blob: d9bc0422420b2cfd89958bf8219ca05076bc7d2c [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 = [
Michail Schwab20bab202018-08-02 18:17:44 -040029 ":assets_dist",
Primiano Tucci1c752c12018-10-23 09:27:19 +010030 ":catapult_dist",
Hector Dearman81804d12018-07-10 11:38:15 +010031 ":controller_bundle_dist",
32 ":engine_bundle_dist",
33 ":frontend_bundle_dist",
Hector Dearman10641512018-07-04 10:38:53 +010034 ":index_dist",
Primiano Tucci21b91bf2018-08-06 16:42:07 +010035 ":scss",
Hector Dearmanbf384922018-06-25 10:42:01 +010036 ":test_scripts",
Hector Dearman10641512018-07-04 10:38:53 +010037 ":wasm_dist",
Primiano Tucci3faad742018-05-16 19:30:48 +010038 ]
39}
40
Hector Dearman4c919612018-12-06 12:32:40 +000041group("query") {
42 deps = [
43 ":query_bundle_dist",
44 ":query_dist",
45 ":ui",
46 ]
47}
48
Primiano Tucci3faad742018-05-16 19:30:48 +010049# +----------------------------------------------------------------------------+
50# | Template used to run node binaries using the hermetic node toolchain. |
51# +----------------------------------------------------------------------------+
52template("node_bin") {
53 action(target_name) {
54 forward_variables_from(invoker,
55 [
56 "inputs",
57 "outputs",
Hector Dearman4274a382018-07-18 16:14:10 +010058 "depfile",
Primiano Tucci3faad742018-05-16 19:30:48 +010059 ])
60 deps = [
61 ":node_modules",
62 ]
63 if (defined(invoker.deps)) {
64 deps += invoker.deps
65 }
66 script = "../gn/standalone/build_tool_wrapper.py"
67 _node_cmd = invoker.node_cmd
Hector Dearmanb06d4152018-05-31 16:55:04 +010068 args = []
69 if (defined(invoker.suppress_stdout) && invoker.suppress_stdout) {
70 args += [ "--suppress_stdout" ]
71 }
72 if (defined(invoker.suppress_stderr) && invoker.suppress_stderr) {
73 args += [ "--suppress_stderr" ]
74 }
75 args += [
76 "--path=$nodejs_bin",
77 "node",
78 rebase_path("node_modules/.bin/$_node_cmd", root_build_dir),
79 ] + invoker.args
Primiano Tucci3faad742018-05-16 19:30:48 +010080 }
81}
82
83# +----------------------------------------------------------------------------+
Hector Dearman92aec392018-06-19 14:33:38 +010084# | Template for "sorcery" the source map resolver. |
85# +----------------------------------------------------------------------------+
86template("sorcery") {
87 node_bin(target_name) {
88 assert(defined(invoker.input))
89 assert(defined(invoker.output))
90 forward_variables_from(invoker, [ "deps" ])
91 inputs = [
92 invoker.input,
93 ]
94 outputs = [
95 invoker.output,
96 invoker.output + ".map",
97 ]
98 node_cmd = "sorcery"
99 args = [
100 "-i",
101 rebase_path(invoker.input, root_build_dir),
102 "-o",
103 rebase_path(invoker.output, root_build_dir),
104 ]
105 }
106}
107
108# +----------------------------------------------------------------------------+
Hector Dearman6999adc2018-06-20 12:07:14 +0100109# | Template for bundling js |
110# +----------------------------------------------------------------------------+
111template("bundle") {
112 node_bin(target_name) {
113 assert(defined(invoker.input))
114 assert(defined(invoker.output))
115 forward_variables_from(invoker, [ "deps" ])
116 inputs = [
117 invoker.input,
118 "rollup.config.js",
119 ]
120 outputs = [
121 invoker.output,
122 invoker.output + ".map",
123 ]
124 node_cmd = "rollup"
125 args = [
126 "-c",
127 rebase_path("rollup.config.js", root_build_dir),
128 rebase_path(invoker.input, root_build_dir),
129 "-o",
130 rebase_path(invoker.output, root_build_dir),
131 "-f",
132 "iife",
133 "-m",
134 "--silent",
135 ]
136 }
137}
138
139# +----------------------------------------------------------------------------+
Primiano Tucci3faad742018-05-16 19:30:48 +0100140# | Bundles all *.js files together resolving CommonJS require() deps. |
141# +----------------------------------------------------------------------------+
142
143# Bundle together all js sources into a bundle.js file, that will ultimately be
144# included by the .html files.
Hector Dearman5f11e522018-05-31 16:54:28 +0100145
Hector Dearman81804d12018-07-10 11:38:15 +0100146bundle("frontend_bundle") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100147 deps = [
148 ":transpile_all_ts",
149 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100150 input = "$target_out_dir/frontend/index.js"
151 output = "$target_out_dir/frontend_bundle.js"
Hector Dearman5f11e522018-05-31 16:54:28 +0100152}
153
Hector Dearman81804d12018-07-10 11:38:15 +0100154bundle("controller_bundle") {
Hector Dearman5f11e522018-05-31 16:54:28 +0100155 deps = [
156 ":transpile_all_ts",
157 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100158 input = "$target_out_dir/controller/index.js"
159 output = "$target_out_dir/controller_bundle.js"
Primiano Tucci3faad742018-05-16 19:30:48 +0100160}
161
Hector Dearman81804d12018-07-10 11:38:15 +0100162bundle("engine_bundle") {
Hector Dearman21fa9162018-06-22 14:50:29 +0100163 deps = [
164 ":transpile_all_ts",
165 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100166 input = "$target_out_dir/engine/index.js"
167 output = "$target_out_dir/engine_bundle.js"
Hector Dearman21fa9162018-06-22 14:50:29 +0100168}
169
Hector Dearman4c919612018-12-06 12:32:40 +0000170bundle("query_bundle") {
171 deps = [
172 ":transpile_all_ts",
173 ]
174 input = "$target_out_dir/query/index.js"
175 output = "$target_out_dir/query_bundle.js"
176}
177
Primiano Tucci3faad742018-05-16 19:30:48 +0100178# +----------------------------------------------------------------------------+
179# | Protobuf: gen rules to create .js and .d.ts files from protos. |
180# +----------------------------------------------------------------------------+
Primiano Tucci3faad742018-05-16 19:30:48 +0100181node_bin("protos_to_js") {
182 inputs = []
183 foreach(proto, trace_processor_protos) {
184 inputs += [ "../protos/perfetto/trace_processor/$proto.proto" ]
185 }
Hector Dearmanf5fd1e12018-06-12 18:23:49 +0100186 inputs += [ "../protos/perfetto/config/perfetto_config.proto" ]
Primiano Tucci3faad742018-05-16 19:30:48 +0100187 outputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100188 "$ui_gen_dir/protos.js",
Primiano Tucci3faad742018-05-16 19:30:48 +0100189 ]
190 node_cmd = "pbjs"
191 args = [
192 "-t",
193 "static-module",
194 "-w",
195 "commonjs",
196 "-p",
197 rebase_path("../protos", root_build_dir),
198 "-o",
199 rebase_path(outputs[0], root_build_dir),
200 ] + rebase_path(inputs, root_build_dir)
201}
202
203# Protobuf.js requires to first generate .js files from the .proto and then
204# create .ts definitions for them.
205node_bin("protos_to_ts") {
206 deps = [
207 ":protos_to_js",
208 ]
209 inputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100210 "$ui_gen_dir/protos.js",
Primiano Tucci3faad742018-05-16 19:30:48 +0100211 ]
212 outputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100213 "$ui_gen_dir/protos.d.ts",
Primiano Tucci3faad742018-05-16 19:30:48 +0100214 ]
215 node_cmd = "pbts"
216 args = [
217 "-p",
218 rebase_path("../protos", root_build_dir),
219 "-o",
220 rebase_path(outputs[0], root_build_dir),
221 rebase_path(inputs[0], root_build_dir),
222 ]
223}
224
225# +----------------------------------------------------------------------------+
226# | TypeScript: transpiles all *.ts into .js |
227# +----------------------------------------------------------------------------+
228
Hector Dearman4274a382018-07-18 16:14:10 +0100229# Builds all .ts sources in the repo under |src|.
Primiano Tucci3faad742018-05-16 19:30:48 +0100230node_bin("transpile_all_ts") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100231 deps = [
232 ":dist_symlink",
233 ":protos_to_ts",
Hector Dearman21fa9162018-06-22 14:50:29 +0100234 ":wasm_gen",
Primiano Tucci3faad742018-05-16 19:30:48 +0100235 ]
Hector Dearman4274a382018-07-18 16:14:10 +0100236 inputs = [
237 "tsconfig.json",
238 ]
Primiano Tucci3faad742018-05-16 19:30:48 +0100239 outputs = [
Hector Dearman81804d12018-07-10 11:38:15 +0100240 "$target_out_dir/frontend/index.js",
241 "$target_out_dir/engine/index.js",
242 "$target_out_dir/controller/index.js",
Hector Dearman4c919612018-12-06 12:32:40 +0000243 "$target_out_dir/query/index.js",
Primiano Tucci3faad742018-05-16 19:30:48 +0100244 ]
245
Hector Dearman4274a382018-07-18 16:14:10 +0100246 depfile = root_out_dir + "/tsc.d"
247 exec_script("../gn/standalone/glob.py",
248 [
249 "--root=" + rebase_path(".", root_build_dir),
250 "--filter=*.ts",
251 "--exclude=node_modules",
252 "--exclude=dist",
253 "--deps=obj/ui/frontend/index.js",
254 "--output=" + rebase_path(depfile),
255 ],
256 "")
257
Primiano Tucci3faad742018-05-16 19:30:48 +0100258 node_cmd = "tsc"
259 args = [
260 "--project",
261 rebase_path(".", root_build_dir),
262 "--outDir",
Hector Dearman262cbe22018-05-31 13:28:21 +0100263 rebase_path(target_out_dir, root_build_dir),
Primiano Tucci3faad742018-05-16 19:30:48 +0100264 ]
265}
266
267# +----------------------------------------------------------------------------+
Primiano Tucci21b91bf2018-08-06 16:42:07 +0100268# | Build css. |
269# +----------------------------------------------------------------------------+
270
Hector Dearmanfcd63bc2018-10-11 11:40:43 +0100271scss_root = "src/assets/perfetto.scss"
272scss_srcs = [
273 "src/assets/sidebar.scss",
274 "src/assets/topbar.scss",
275 "src/assets/record.scss",
276 "src/assets/common.scss",
277]
278
Primiano Tucci21b91bf2018-08-06 16:42:07 +0100279# Build css.
280node_bin("scss") {
281 deps = [
282 ":dist_symlink",
283 ]
Hector Dearmanfcd63bc2018-10-11 11:40:43 +0100284 inputs = [ scss_root ] + scss_srcs
Primiano Tucci21b91bf2018-08-06 16:42:07 +0100285 outputs = [
286 "$ui_dir/perfetto.css",
287 ]
288
289 node_cmd = "node-sass"
290 args = [
291 "--quiet",
Hector Dearmanfcd63bc2018-10-11 11:40:43 +0100292 rebase_path(scss_root, root_build_dir),
Primiano Tucci21b91bf2018-08-06 16:42:07 +0100293 rebase_path(outputs[0], root_build_dir),
294 ]
295}
296
297# +----------------------------------------------------------------------------+
Hector Dearman262cbe22018-05-31 13:28:21 +0100298# | Copy rules: create the final output directory. |
Primiano Tucci3faad742018-05-16 19:30:48 +0100299# +----------------------------------------------------------------------------+
Hector Dearman10641512018-07-04 10:38:53 +0100300copy("index_dist") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100301 sources = [
302 "index.html",
303 ]
304 outputs = [
Hector Dearman262cbe22018-05-31 13:28:21 +0100305 "$ui_dir/index.html",
Primiano Tucci3faad742018-05-16 19:30:48 +0100306 ]
307}
308
Hector Dearman4c919612018-12-06 12:32:40 +0000309copy("query_dist") {
310 sources = [
311 "query.html",
312 ]
313 outputs = [
314 "$ui_dir/query.html",
315 ]
316}
317
Michail Schwab20bab202018-08-02 18:17:44 -0400318copy("assets_dist") {
319 sources = [
Hector Dearmanfcd63bc2018-10-11 11:40:43 +0100320 "src/assets/logo-3d.png",
321 "src/assets/logo.png",
322 ] + [ scss_root ] + scss_srcs
Michail Schwab20bab202018-08-02 18:17:44 -0400323 outputs = [
Hector Dearman7cf6b102018-08-09 17:30:57 +0100324 "$ui_dir/assets/{{source_file_part}}",
Michail Schwab20bab202018-08-02 18:17:44 -0400325 ]
326}
Hector Dearmandaca6cd2018-07-11 12:55:34 +0100327
Hector Dearman81804d12018-07-10 11:38:15 +0100328sorcery("frontend_bundle_dist") {
Hector Dearman262cbe22018-05-31 13:28:21 +0100329 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100330 ":frontend_bundle",
Hector Dearman262cbe22018-05-31 13:28:21 +0100331 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100332 input = "$target_out_dir/frontend_bundle.js"
333 output = "$ui_dir/frontend_bundle.js"
Hector Dearman5f11e522018-05-31 16:54:28 +0100334}
335
Hector Dearman81804d12018-07-10 11:38:15 +0100336sorcery("controller_bundle_dist") {
Hector Dearman5f11e522018-05-31 16:54:28 +0100337 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100338 ":controller_bundle",
Hector Dearman5f11e522018-05-31 16:54:28 +0100339 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100340 input = "$target_out_dir/controller_bundle.js"
341 output = "$ui_dir/controller_bundle.js"
Hector Dearman262cbe22018-05-31 13:28:21 +0100342}
343
Hector Dearman81804d12018-07-10 11:38:15 +0100344sorcery("engine_bundle_dist") {
Hector Dearman21fa9162018-06-22 14:50:29 +0100345 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100346 ":engine_bundle",
Hector Dearman21fa9162018-06-22 14:50:29 +0100347 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100348 input = "$target_out_dir/engine_bundle.js"
349 output = "$ui_dir/engine_bundle.js"
Hector Dearman21fa9162018-06-22 14:50:29 +0100350}
351
Hector Dearman4c919612018-12-06 12:32:40 +0000352sorcery("query_bundle_dist") {
353 deps = [
354 ":query_bundle",
355 ]
356 input = "$target_out_dir/query_bundle.js"
357 output = "$ui_dir/query_bundle.js"
358}
359
Hector Dearman10641512018-07-04 10:38:53 +0100360copy("wasm_dist") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100361 deps = [
Hector Dearmane8450742018-08-31 14:36:51 +0100362 "//src/trace_processor:trace_processor.wasm($wasm_toolchain)",
Primiano Tucci1c752c12018-10-23 09:27:19 +0100363 "//tools/trace_to_text:trace_to_text.wasm($wasm_toolchain)",
Hector Dearman21fa9162018-06-22 14:50:29 +0100364 ]
365 sources = [
Hector Dearmane8450742018-08-31 14:36:51 +0100366 "$root_build_dir/wasm/trace_processor.wasm",
Primiano Tucci1c752c12018-10-23 09:27:19 +0100367 "$root_build_dir/wasm/trace_to_text.wasm",
Hector Dearman21fa9162018-06-22 14:50:29 +0100368 ]
369 outputs = [
370 "$ui_dir/{{source_file_part}}",
371 ]
372}
373
374copy("wasm_gen") {
375 deps = [
376 ":dist_symlink",
Primiano Tucci1c752c12018-10-23 09:27:19 +0100377
378 # trace_processor
Hector Dearmane8450742018-08-31 14:36:51 +0100379 "//src/trace_processor:trace_processor.d.ts($wasm_toolchain)",
380 "//src/trace_processor:trace_processor.js($wasm_toolchain)",
381 "//src/trace_processor:trace_processor.wasm($wasm_toolchain)",
Primiano Tucci1c752c12018-10-23 09:27:19 +0100382
383 # trace_to_text
384 "//tools/trace_to_text:trace_to_text.d.ts($wasm_toolchain)",
385 "//tools/trace_to_text:trace_to_text.js($wasm_toolchain)",
386 "//tools/trace_to_text:trace_to_text.wasm($wasm_toolchain)",
Primiano Tucci3faad742018-05-16 19:30:48 +0100387 ]
388 sources = [
Primiano Tucci1c752c12018-10-23 09:27:19 +0100389 # trace_processor
Hector Dearmane8450742018-08-31 14:36:51 +0100390 "$root_build_dir/wasm/trace_processor.d.ts",
391 "$root_build_dir/wasm/trace_processor.js",
392 "$root_build_dir/wasm/trace_processor.wasm",
Primiano Tucci1c752c12018-10-23 09:27:19 +0100393
394 # trace_to_text
395 "$root_build_dir/wasm/trace_to_text.d.ts",
396 "$root_build_dir/wasm/trace_to_text.js",
397 "$root_build_dir/wasm/trace_to_text.wasm",
Primiano Tucci3faad742018-05-16 19:30:48 +0100398 ]
Hector Dearmana824ba92018-09-19 17:51:25 +0100399 if (is_debug) {
Primiano Tucci1c752c12018-10-23 09:27:19 +0100400 sources += [
401 "$root_build_dir/wasm/trace_processor.wasm.map",
402 "$root_build_dir/wasm/trace_to_text.wasm.map",
403 ]
Hector Dearmana824ba92018-09-19 17:51:25 +0100404 }
Primiano Tucci3faad742018-05-16 19:30:48 +0100405 outputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100406 "$ui_gen_dir/{{source_file_part}}",
Primiano Tucci3faad742018-05-16 19:30:48 +0100407 ]
408}
409
Primiano Tucci1c752c12018-10-23 09:27:19 +0100410# Copy over the vulcanized legacy trace viewer.
411copy("catapult_dist") {
412 sources = [
413 "../buildtools/catapult_trace_viewer/catapult_trace_viewer.html",
414 "../buildtools/catapult_trace_viewer/catapult_trace_viewer.js",
415 ]
416 outputs = [
417 "$ui_dir/assets/{{source_file_part}}",
418 ]
419}
420
Primiano Tucci3faad742018-05-16 19:30:48 +0100421# +----------------------------------------------------------------------------+
Deepanjan Royacf8c072018-07-13 11:37:04 -0400422# | Node JS: Creates a symlink in the out directory to node_modules. |
Primiano Tucci3faad742018-05-16 19:30:48 +0100423# +----------------------------------------------------------------------------+
424
425action("check_node_exists") {
426 script = "../gn/standalone/check_buildtool_exists.py"
Hector Dearman48783b12018-05-22 08:26:06 +0100427 args = [
428 nodejs_bin,
429 "--touch",
430 rebase_path("$target_out_dir/node_exists", ""),
431 ]
Primiano Tucci3faad742018-05-16 19:30:48 +0100432 inputs = []
433 outputs = [
Hector Dearman48783b12018-05-22 08:26:06 +0100434 "$target_out_dir/node_exists",
Primiano Tucci3faad742018-05-16 19:30:48 +0100435 ]
436}
437
438# Creates a symlink from out/xxx/ui/node_modules -> ../../../ui/node_modules.
Hector Dearmanb06d4152018-05-31 16:55:04 +0100439# This allows to run rollup and other node tools from the out/xxx directory.
Primiano Tucci3faad742018-05-16 19:30:48 +0100440action("node_modules_symlink") {
441 deps = [
442 ":check_node_exists",
443 ]
Hector Dearman6186c872018-05-31 13:28:48 +0100444
Primiano Tucci3faad742018-05-16 19:30:48 +0100445 script = "../gn/standalone/build_tool_wrapper.py"
Hector Dearman6186c872018-05-31 13:28:48 +0100446 stamp_file = "$target_out_dir/.$target_name.stamp"
Primiano Tucci3faad742018-05-16 19:30:48 +0100447 args = [
Hector Dearman6186c872018-05-31 13:28:48 +0100448 "--stamp",
449 rebase_path(stamp_file, root_build_dir),
Primiano Tucci3faad742018-05-16 19:30:48 +0100450 "/bin/ln",
451 "-fns",
Hector Dearmana817a062018-06-01 11:01:07 +0100452 rebase_path("node_modules", target_out_dir),
Hector Dearman6186c872018-05-31 13:28:48 +0100453 rebase_path("$target_out_dir/node_modules", root_build_dir),
454 ]
455 outputs = [
456 stamp_file,
Primiano Tucci3faad742018-05-16 19:30:48 +0100457 ]
458}
459
Hector Dearman6186c872018-05-31 13:28:48 +0100460group("node_modules") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100461 deps = [
462 ":node_modules_symlink",
463 ]
464}
465
466# Creates a symlink from //ui/dist -> ../../out/xxx/ui. Used only for
467# autocompletion in IDEs. The problem this is solving is that in tsconfig.json
468# we can't possibly know the path to ../../out/xxx for outDir. Instead, we set
469# outDir to "./dist" and create a symlink on the first build.
470action("dist_symlink") {
471 script = "../gn/standalone/build_tool_wrapper.py"
Hector Dearman262cbe22018-05-31 13:28:21 +0100472 stamp_file = "$target_out_dir/.$target_name.stamp"
Primiano Tucci3faad742018-05-16 19:30:48 +0100473 args = [
474 "--stamp",
475 rebase_path(stamp_file, root_build_dir),
476 "/bin/ln",
477 "-fns",
Hector Dearman262cbe22018-05-31 13:28:21 +0100478 rebase_path(target_out_dir, "."),
Primiano Tucci3faad742018-05-16 19:30:48 +0100479 rebase_path("dist", root_build_dir),
480 ]
481 inputs = [
482 "$root_build_dir",
483 ]
484 outputs = [
485 stamp_file,
486 ]
487}
Hector Dearmanbf384922018-06-25 10:42:01 +0100488
489group("test_scripts") {
490 deps = [
491 ":copy_tests_script",
492 ":copy_unittests_script",
493 ]
494}
495
496copy("copy_unittests_script") {
497 sources = [
498 "config/ui_unittests_template",
499 ]
500 outputs = [
501 "$root_build_dir/ui_unittests",
502 ]
503}
504
505copy("copy_tests_script") {
506 sources = [
507 "config/ui_tests_template",
508 ]
509 outputs = [
510 "$root_build_dir/ui_tests",
511 ]
512}