blob: 297464d8de07c7c27e6d0def442e950e467eb47e [file] [log] [blame]
Primiano Tucci3faad742018-05-16 19:30:48 +01001# Copyright (C) 2018 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import("../gn/perfetto.gni")
16import("../gn/wasm.gni")
17import("../protos/perfetto/trace_processor/proto_files.gni")
18
Hector Dearman262cbe22018-05-31 13:28:21 +010019ui_dir = "$root_build_dir/ui"
Hector Dearman21fa9162018-06-22 14:50:29 +010020ui_gen_dir = "$target_out_dir/gen"
Primiano Tucci3faad742018-05-16 19:30:48 +010021nodejs_root = "../buildtools/nodejs"
22nodejs_bin = rebase_path("$nodejs_root/bin", root_build_dir)
23
24# +----------------------------------------------------------------------------+
25# | The outer "ui" target to just ninja -C out/xxx ui |
26# +----------------------------------------------------------------------------+
27group("ui") {
28 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +010029 ":controller_bundle_dist",
Hector Dearmandaca6cd2018-07-11 12:55:34 +010030 ":css_dist",
Hector Dearman81804d12018-07-10 11:38:15 +010031 ":engine_bundle_dist",
32 ":frontend_bundle_dist",
Hector Dearman10641512018-07-04 10:38:53 +010033 ":index_dist",
Hector Dearmanbf384922018-06-25 10:42:01 +010034 ":test_scripts",
Hector Dearman10641512018-07-04 10:38:53 +010035 ":wasm_dist",
Primiano Tucci3faad742018-05-16 19:30:48 +010036 ]
37}
38
39# +----------------------------------------------------------------------------+
40# | Template used to run node binaries using the hermetic node toolchain. |
41# +----------------------------------------------------------------------------+
42template("node_bin") {
43 action(target_name) {
44 forward_variables_from(invoker,
45 [
46 "inputs",
47 "outputs",
48 ])
49 deps = [
50 ":node_modules",
51 ]
52 if (defined(invoker.deps)) {
53 deps += invoker.deps
54 }
55 script = "../gn/standalone/build_tool_wrapper.py"
56 _node_cmd = invoker.node_cmd
Hector Dearmanb06d4152018-05-31 16:55:04 +010057 args = []
58 if (defined(invoker.suppress_stdout) && invoker.suppress_stdout) {
59 args += [ "--suppress_stdout" ]
60 }
61 if (defined(invoker.suppress_stderr) && invoker.suppress_stderr) {
62 args += [ "--suppress_stderr" ]
63 }
64 args += [
65 "--path=$nodejs_bin",
66 "node",
67 rebase_path("node_modules/.bin/$_node_cmd", root_build_dir),
68 ] + invoker.args
Primiano Tucci3faad742018-05-16 19:30:48 +010069 }
70}
71
72# +----------------------------------------------------------------------------+
Hector Dearman92aec392018-06-19 14:33:38 +010073# | Template for "sorcery" the source map resolver. |
74# +----------------------------------------------------------------------------+
75template("sorcery") {
76 node_bin(target_name) {
77 assert(defined(invoker.input))
78 assert(defined(invoker.output))
79 forward_variables_from(invoker, [ "deps" ])
80 inputs = [
81 invoker.input,
82 ]
83 outputs = [
84 invoker.output,
85 invoker.output + ".map",
86 ]
87 node_cmd = "sorcery"
88 args = [
89 "-i",
90 rebase_path(invoker.input, root_build_dir),
91 "-o",
92 rebase_path(invoker.output, root_build_dir),
93 ]
94 }
95}
96
97# +----------------------------------------------------------------------------+
Hector Dearman6999adc2018-06-20 12:07:14 +010098# | Template for bundling js |
99# +----------------------------------------------------------------------------+
100template("bundle") {
101 node_bin(target_name) {
102 assert(defined(invoker.input))
103 assert(defined(invoker.output))
104 forward_variables_from(invoker, [ "deps" ])
105 inputs = [
106 invoker.input,
107 "rollup.config.js",
108 ]
109 outputs = [
110 invoker.output,
111 invoker.output + ".map",
112 ]
113 node_cmd = "rollup"
114 args = [
115 "-c",
116 rebase_path("rollup.config.js", root_build_dir),
117 rebase_path(invoker.input, root_build_dir),
118 "-o",
119 rebase_path(invoker.output, root_build_dir),
120 "-f",
121 "iife",
122 "-m",
123 "--silent",
124 ]
125 }
126}
127
128# +----------------------------------------------------------------------------+
Primiano Tucci3faad742018-05-16 19:30:48 +0100129# | Bundles all *.js files together resolving CommonJS require() deps. |
130# +----------------------------------------------------------------------------+
131
132# Bundle together all js sources into a bundle.js file, that will ultimately be
133# included by the .html files.
Hector Dearman5f11e522018-05-31 16:54:28 +0100134
Hector Dearman81804d12018-07-10 11:38:15 +0100135bundle("frontend_bundle") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100136 deps = [
137 ":transpile_all_ts",
138 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100139 input = "$target_out_dir/frontend/index.js"
140 output = "$target_out_dir/frontend_bundle.js"
Hector Dearman5f11e522018-05-31 16:54:28 +0100141}
142
Hector Dearman81804d12018-07-10 11:38:15 +0100143bundle("controller_bundle") {
Hector Dearman5f11e522018-05-31 16:54:28 +0100144 deps = [
145 ":transpile_all_ts",
146 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100147 input = "$target_out_dir/controller/index.js"
148 output = "$target_out_dir/controller_bundle.js"
Primiano Tucci3faad742018-05-16 19:30:48 +0100149}
150
Hector Dearman81804d12018-07-10 11:38:15 +0100151bundle("engine_bundle") {
Hector Dearman21fa9162018-06-22 14:50:29 +0100152 deps = [
153 ":transpile_all_ts",
154 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100155 input = "$target_out_dir/engine/index.js"
156 output = "$target_out_dir/engine_bundle.js"
Hector Dearman21fa9162018-06-22 14:50:29 +0100157}
158
Primiano Tucci3faad742018-05-16 19:30:48 +0100159# +----------------------------------------------------------------------------+
160# | Protobuf: gen rules to create .js and .d.ts files from protos. |
161# +----------------------------------------------------------------------------+
Primiano Tucci3faad742018-05-16 19:30:48 +0100162node_bin("protos_to_js") {
163 inputs = []
164 foreach(proto, trace_processor_protos) {
165 inputs += [ "../protos/perfetto/trace_processor/$proto.proto" ]
166 }
Hector Dearmanf5fd1e12018-06-12 18:23:49 +0100167 inputs += [ "../protos/perfetto/config/perfetto_config.proto" ]
Primiano Tucci3faad742018-05-16 19:30:48 +0100168 outputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100169 "$ui_gen_dir/protos.js",
Primiano Tucci3faad742018-05-16 19:30:48 +0100170 ]
171 node_cmd = "pbjs"
172 args = [
173 "-t",
174 "static-module",
175 "-w",
176 "commonjs",
177 "-p",
178 rebase_path("../protos", root_build_dir),
179 "-o",
180 rebase_path(outputs[0], root_build_dir),
181 ] + rebase_path(inputs, root_build_dir)
182}
183
184# Protobuf.js requires to first generate .js files from the .proto and then
185# create .ts definitions for them.
186node_bin("protos_to_ts") {
187 deps = [
188 ":protos_to_js",
189 ]
190 inputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100191 "$ui_gen_dir/protos.js",
Primiano Tucci3faad742018-05-16 19:30:48 +0100192 ]
193 outputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100194 "$ui_gen_dir/protos.d.ts",
Primiano Tucci3faad742018-05-16 19:30:48 +0100195 ]
196 node_cmd = "pbts"
197 args = [
198 "-p",
199 rebase_path("../protos", root_build_dir),
200 "-o",
201 rebase_path(outputs[0], root_build_dir),
202 rebase_path(inputs[0], root_build_dir),
203 ]
204}
205
206# +----------------------------------------------------------------------------+
207# | TypeScript: transpiles all *.ts into .js |
208# +----------------------------------------------------------------------------+
209
210# Builds all .ts sources in the repo that are reachable from |sources|.
211node_bin("transpile_all_ts") {
212 sources = [
Hector Dearman81804d12018-07-10 11:38:15 +0100213 "src/controller/index.ts",
214 "src/engine/index.ts",
215 "src/frontend/index.ts",
Primiano Tucci3faad742018-05-16 19:30:48 +0100216 ]
217 deps = [
218 ":dist_symlink",
219 ":protos_to_ts",
Hector Dearman21fa9162018-06-22 14:50:29 +0100220 ":wasm_gen",
Primiano Tucci3faad742018-05-16 19:30:48 +0100221 ]
222 inputs = sources + [ "tsconfig.json" ]
223 outputs = [
Hector Dearman81804d12018-07-10 11:38:15 +0100224 "$target_out_dir/frontend/index.js",
225 "$target_out_dir/engine/index.js",
226 "$target_out_dir/controller/index.js",
Primiano Tucci3faad742018-05-16 19:30:48 +0100227 ]
228
229 # Find all *.ts files and pass them as input triggers. This does NOT affect
230 # which files will get built. This defines only the set of files that, when
231 # changes, will re-trigger this rule in ninja. The files that get transpiled
232 # are the transitive dependencies of |sources|.
233 all_ts_files = exec_script("../gn/standalone/glob.py",
234 [
235 "--root=" + rebase_path(".", root_build_dir),
236 "--filter=*.ts",
237 "--exclude=node_modules",
238 "--exclude=dist",
239 ],
240 "list lines",
241 [ "." ])
242 inputs += all_ts_files
Primiano Tucci3faad742018-05-16 19:30:48 +0100243 node_cmd = "tsc"
244 args = [
245 "--project",
246 rebase_path(".", root_build_dir),
247 "--outDir",
Hector Dearman262cbe22018-05-31 13:28:21 +0100248 rebase_path(target_out_dir, root_build_dir),
Primiano Tucci3faad742018-05-16 19:30:48 +0100249 ]
250}
251
252# +----------------------------------------------------------------------------+
Hector Dearman262cbe22018-05-31 13:28:21 +0100253# | Copy rules: create the final output directory. |
Primiano Tucci3faad742018-05-16 19:30:48 +0100254# +----------------------------------------------------------------------------+
Hector Dearman10641512018-07-04 10:38:53 +0100255copy("index_dist") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100256 sources = [
257 "index.html",
258 ]
259 outputs = [
Hector Dearman262cbe22018-05-31 13:28:21 +0100260 "$ui_dir/index.html",
Primiano Tucci3faad742018-05-16 19:30:48 +0100261 ]
262}
263
Hector Dearmandaca6cd2018-07-11 12:55:34 +0100264copy("css_dist") {
265 sources = [
266 "perfetto.css",
267 ]
268 outputs = [
269 "$ui_dir/perfetto.css",
270 ]
271}
272
Hector Dearman81804d12018-07-10 11:38:15 +0100273sorcery("frontend_bundle_dist") {
Hector Dearman262cbe22018-05-31 13:28:21 +0100274 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100275 ":frontend_bundle",
Hector Dearman262cbe22018-05-31 13:28:21 +0100276 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100277 input = "$target_out_dir/frontend_bundle.js"
278 output = "$ui_dir/frontend_bundle.js"
Hector Dearman5f11e522018-05-31 16:54:28 +0100279}
280
Hector Dearman81804d12018-07-10 11:38:15 +0100281sorcery("controller_bundle_dist") {
Hector Dearman5f11e522018-05-31 16:54:28 +0100282 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100283 ":controller_bundle",
Hector Dearman5f11e522018-05-31 16:54:28 +0100284 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100285 input = "$target_out_dir/controller_bundle.js"
286 output = "$ui_dir/controller_bundle.js"
Hector Dearman262cbe22018-05-31 13:28:21 +0100287}
288
Hector Dearman81804d12018-07-10 11:38:15 +0100289sorcery("engine_bundle_dist") {
Hector Dearman21fa9162018-06-22 14:50:29 +0100290 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100291 ":engine_bundle",
Hector Dearman21fa9162018-06-22 14:50:29 +0100292 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100293 input = "$target_out_dir/engine_bundle.js"
294 output = "$ui_dir/engine_bundle.js"
Hector Dearman21fa9162018-06-22 14:50:29 +0100295}
296
Hector Dearman10641512018-07-04 10:38:53 +0100297copy("wasm_dist") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100298 deps = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100299 "//src/trace_processor:trace_processor.wasm($wasm_toolchain)",
300 ]
301 sources = [
302 "$root_build_dir/wasm/trace_processor.wasm",
303 ]
304 outputs = [
305 "$ui_dir/{{source_file_part}}",
306 ]
307}
308
309copy("wasm_gen") {
310 deps = [
311 ":dist_symlink",
312 "//src/trace_processor:trace_processor.d.ts($wasm_toolchain)",
Primiano Tucci3faad742018-05-16 19:30:48 +0100313 "//src/trace_processor:trace_processor.js($wasm_toolchain)",
314 "//src/trace_processor:trace_processor.wasm($wasm_toolchain)",
315 ]
316 sources = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100317 "$root_build_dir/wasm/trace_processor.d.ts",
Primiano Tucci3faad742018-05-16 19:30:48 +0100318 "$root_build_dir/wasm/trace_processor.js",
319 "$root_build_dir/wasm/trace_processor.wasm",
320 ]
321 outputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100322 "$ui_gen_dir/{{source_file_part}}",
Primiano Tucci3faad742018-05-16 19:30:48 +0100323 ]
324}
325
326# +----------------------------------------------------------------------------+
Deepanjan Royacf8c072018-07-13 11:37:04 -0400327# | Node JS: Creates a symlink in the out directory to node_modules. |
Primiano Tucci3faad742018-05-16 19:30:48 +0100328# +----------------------------------------------------------------------------+
329
330action("check_node_exists") {
331 script = "../gn/standalone/check_buildtool_exists.py"
Hector Dearman48783b12018-05-22 08:26:06 +0100332 args = [
333 nodejs_bin,
334 "--touch",
335 rebase_path("$target_out_dir/node_exists", ""),
336 ]
Primiano Tucci3faad742018-05-16 19:30:48 +0100337 inputs = []
338 outputs = [
Hector Dearman48783b12018-05-22 08:26:06 +0100339 "$target_out_dir/node_exists",
Primiano Tucci3faad742018-05-16 19:30:48 +0100340 ]
341}
342
343# Creates a symlink from out/xxx/ui/node_modules -> ../../../ui/node_modules.
Hector Dearmanb06d4152018-05-31 16:55:04 +0100344# This allows to run rollup and other node tools from the out/xxx directory.
Primiano Tucci3faad742018-05-16 19:30:48 +0100345action("node_modules_symlink") {
346 deps = [
347 ":check_node_exists",
348 ]
Hector Dearman6186c872018-05-31 13:28:48 +0100349
Primiano Tucci3faad742018-05-16 19:30:48 +0100350 script = "../gn/standalone/build_tool_wrapper.py"
Hector Dearman6186c872018-05-31 13:28:48 +0100351 stamp_file = "$target_out_dir/.$target_name.stamp"
Primiano Tucci3faad742018-05-16 19:30:48 +0100352 args = [
Hector Dearman6186c872018-05-31 13:28:48 +0100353 "--stamp",
354 rebase_path(stamp_file, root_build_dir),
Primiano Tucci3faad742018-05-16 19:30:48 +0100355 "/bin/ln",
356 "-fns",
Hector Dearmana817a062018-06-01 11:01:07 +0100357 rebase_path("node_modules", target_out_dir),
Hector Dearman6186c872018-05-31 13:28:48 +0100358 rebase_path("$target_out_dir/node_modules", root_build_dir),
359 ]
360 outputs = [
361 stamp_file,
Primiano Tucci3faad742018-05-16 19:30:48 +0100362 ]
363}
364
Hector Dearman6186c872018-05-31 13:28:48 +0100365group("node_modules") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100366 deps = [
367 ":node_modules_symlink",
368 ]
369}
370
371# Creates a symlink from //ui/dist -> ../../out/xxx/ui. Used only for
372# autocompletion in IDEs. The problem this is solving is that in tsconfig.json
373# we can't possibly know the path to ../../out/xxx for outDir. Instead, we set
374# outDir to "./dist" and create a symlink on the first build.
375action("dist_symlink") {
376 script = "../gn/standalone/build_tool_wrapper.py"
Hector Dearman262cbe22018-05-31 13:28:21 +0100377 stamp_file = "$target_out_dir/.$target_name.stamp"
Primiano Tucci3faad742018-05-16 19:30:48 +0100378 args = [
379 "--stamp",
380 rebase_path(stamp_file, root_build_dir),
381 "/bin/ln",
382 "-fns",
Hector Dearman262cbe22018-05-31 13:28:21 +0100383 rebase_path(target_out_dir, "."),
Primiano Tucci3faad742018-05-16 19:30:48 +0100384 rebase_path("dist", root_build_dir),
385 ]
386 inputs = [
387 "$root_build_dir",
388 ]
389 outputs = [
390 stamp_file,
391 ]
392}
Hector Dearmanbf384922018-06-25 10:42:01 +0100393
394group("test_scripts") {
395 deps = [
396 ":copy_tests_script",
397 ":copy_unittests_script",
398 ]
399}
400
401copy("copy_unittests_script") {
402 sources = [
403 "config/ui_unittests_template",
404 ]
405 outputs = [
406 "$root_build_dir/ui_unittests",
407 ]
408}
409
410copy("copy_tests_script") {
411 sources = [
412 "config/ui_tests_template",
413 ]
414 outputs = [
415 "$root_build_dir/ui_tests",
416 ]
417}