blob: 104b6e8454433b3ab4f085dd15ffdd15caa43f59 [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",
Hector Dearman81804d12018-07-10 11:38:15 +010030 ":controller_bundle_dist",
31 ":engine_bundle_dist",
32 ":frontend_bundle_dist",
Hector Dearman10641512018-07-04 10:38:53 +010033 ":index_dist",
Primiano Tucci21b91bf2018-08-06 16:42:07 +010034 ":scss",
Hector Dearmanbf384922018-06-25 10:42:01 +010035 ":test_scripts",
Hector Dearman10641512018-07-04 10:38:53 +010036 ":wasm_dist",
Primiano Tucci3faad742018-05-16 19:30:48 +010037 ]
38}
39
40# +----------------------------------------------------------------------------+
41# | Template used to run node binaries using the hermetic node toolchain. |
42# +----------------------------------------------------------------------------+
43template("node_bin") {
44 action(target_name) {
45 forward_variables_from(invoker,
46 [
47 "inputs",
48 "outputs",
Hector Dearman4274a382018-07-18 16:14:10 +010049 "depfile",
Primiano Tucci3faad742018-05-16 19:30:48 +010050 ])
51 deps = [
52 ":node_modules",
53 ]
54 if (defined(invoker.deps)) {
55 deps += invoker.deps
56 }
57 script = "../gn/standalone/build_tool_wrapper.py"
58 _node_cmd = invoker.node_cmd
Hector Dearmanb06d4152018-05-31 16:55:04 +010059 args = []
60 if (defined(invoker.suppress_stdout) && invoker.suppress_stdout) {
61 args += [ "--suppress_stdout" ]
62 }
63 if (defined(invoker.suppress_stderr) && invoker.suppress_stderr) {
64 args += [ "--suppress_stderr" ]
65 }
66 args += [
67 "--path=$nodejs_bin",
68 "node",
69 rebase_path("node_modules/.bin/$_node_cmd", root_build_dir),
70 ] + invoker.args
Primiano Tucci3faad742018-05-16 19:30:48 +010071 }
72}
73
74# +----------------------------------------------------------------------------+
Hector Dearman92aec392018-06-19 14:33:38 +010075# | Template for "sorcery" the source map resolver. |
76# +----------------------------------------------------------------------------+
77template("sorcery") {
78 node_bin(target_name) {
79 assert(defined(invoker.input))
80 assert(defined(invoker.output))
81 forward_variables_from(invoker, [ "deps" ])
82 inputs = [
83 invoker.input,
84 ]
85 outputs = [
86 invoker.output,
87 invoker.output + ".map",
88 ]
89 node_cmd = "sorcery"
90 args = [
91 "-i",
92 rebase_path(invoker.input, root_build_dir),
93 "-o",
94 rebase_path(invoker.output, root_build_dir),
95 ]
96 }
97}
98
99# +----------------------------------------------------------------------------+
Hector Dearman6999adc2018-06-20 12:07:14 +0100100# | Template for bundling js |
101# +----------------------------------------------------------------------------+
102template("bundle") {
103 node_bin(target_name) {
104 assert(defined(invoker.input))
105 assert(defined(invoker.output))
106 forward_variables_from(invoker, [ "deps" ])
107 inputs = [
108 invoker.input,
109 "rollup.config.js",
110 ]
111 outputs = [
112 invoker.output,
113 invoker.output + ".map",
114 ]
115 node_cmd = "rollup"
116 args = [
117 "-c",
118 rebase_path("rollup.config.js", root_build_dir),
119 rebase_path(invoker.input, root_build_dir),
120 "-o",
121 rebase_path(invoker.output, root_build_dir),
122 "-f",
123 "iife",
124 "-m",
125 "--silent",
126 ]
127 }
128}
129
130# +----------------------------------------------------------------------------+
Primiano Tucci3faad742018-05-16 19:30:48 +0100131# | Bundles all *.js files together resolving CommonJS require() deps. |
132# +----------------------------------------------------------------------------+
133
134# Bundle together all js sources into a bundle.js file, that will ultimately be
135# included by the .html files.
Hector Dearman5f11e522018-05-31 16:54:28 +0100136
Hector Dearman81804d12018-07-10 11:38:15 +0100137bundle("frontend_bundle") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100138 deps = [
139 ":transpile_all_ts",
140 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100141 input = "$target_out_dir/frontend/index.js"
142 output = "$target_out_dir/frontend_bundle.js"
Hector Dearman5f11e522018-05-31 16:54:28 +0100143}
144
Hector Dearman81804d12018-07-10 11:38:15 +0100145bundle("controller_bundle") {
Hector Dearman5f11e522018-05-31 16:54:28 +0100146 deps = [
147 ":transpile_all_ts",
148 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100149 input = "$target_out_dir/controller/index.js"
150 output = "$target_out_dir/controller_bundle.js"
Primiano Tucci3faad742018-05-16 19:30:48 +0100151}
152
Hector Dearman81804d12018-07-10 11:38:15 +0100153bundle("engine_bundle") {
Hector Dearman21fa9162018-06-22 14:50:29 +0100154 deps = [
155 ":transpile_all_ts",
156 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100157 input = "$target_out_dir/engine/index.js"
158 output = "$target_out_dir/engine_bundle.js"
Hector Dearman21fa9162018-06-22 14:50:29 +0100159}
160
Primiano Tucci3faad742018-05-16 19:30:48 +0100161# +----------------------------------------------------------------------------+
162# | Protobuf: gen rules to create .js and .d.ts files from protos. |
163# +----------------------------------------------------------------------------+
Primiano Tucci3faad742018-05-16 19:30:48 +0100164node_bin("protos_to_js") {
165 inputs = []
166 foreach(proto, trace_processor_protos) {
167 inputs += [ "../protos/perfetto/trace_processor/$proto.proto" ]
168 }
Hector Dearmanf5fd1e12018-06-12 18:23:49 +0100169 inputs += [ "../protos/perfetto/config/perfetto_config.proto" ]
Primiano Tucci3faad742018-05-16 19:30:48 +0100170 outputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100171 "$ui_gen_dir/protos.js",
Primiano Tucci3faad742018-05-16 19:30:48 +0100172 ]
173 node_cmd = "pbjs"
174 args = [
175 "-t",
176 "static-module",
177 "-w",
178 "commonjs",
179 "-p",
180 rebase_path("../protos", root_build_dir),
181 "-o",
182 rebase_path(outputs[0], root_build_dir),
183 ] + rebase_path(inputs, root_build_dir)
184}
185
186# Protobuf.js requires to first generate .js files from the .proto and then
187# create .ts definitions for them.
188node_bin("protos_to_ts") {
189 deps = [
190 ":protos_to_js",
191 ]
192 inputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100193 "$ui_gen_dir/protos.js",
Primiano Tucci3faad742018-05-16 19:30:48 +0100194 ]
195 outputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100196 "$ui_gen_dir/protos.d.ts",
Primiano Tucci3faad742018-05-16 19:30:48 +0100197 ]
198 node_cmd = "pbts"
199 args = [
200 "-p",
201 rebase_path("../protos", root_build_dir),
202 "-o",
203 rebase_path(outputs[0], root_build_dir),
204 rebase_path(inputs[0], root_build_dir),
205 ]
206}
207
208# +----------------------------------------------------------------------------+
209# | TypeScript: transpiles all *.ts into .js |
210# +----------------------------------------------------------------------------+
211
Hector Dearman4274a382018-07-18 16:14:10 +0100212# Builds all .ts sources in the repo under |src|.
Primiano Tucci3faad742018-05-16 19:30:48 +0100213node_bin("transpile_all_ts") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100214 deps = [
215 ":dist_symlink",
216 ":protos_to_ts",
Hector Dearman21fa9162018-06-22 14:50:29 +0100217 ":wasm_gen",
Primiano Tucci3faad742018-05-16 19:30:48 +0100218 ]
Hector Dearman4274a382018-07-18 16:14:10 +0100219 inputs = [
220 "tsconfig.json",
221 ]
Primiano Tucci3faad742018-05-16 19:30:48 +0100222 outputs = [
Hector Dearman81804d12018-07-10 11:38:15 +0100223 "$target_out_dir/frontend/index.js",
224 "$target_out_dir/engine/index.js",
225 "$target_out_dir/controller/index.js",
Primiano Tucci3faad742018-05-16 19:30:48 +0100226 ]
227
Hector Dearman4274a382018-07-18 16:14:10 +0100228 depfile = root_out_dir + "/tsc.d"
229 exec_script("../gn/standalone/glob.py",
230 [
231 "--root=" + rebase_path(".", root_build_dir),
232 "--filter=*.ts",
233 "--exclude=node_modules",
234 "--exclude=dist",
235 "--deps=obj/ui/frontend/index.js",
236 "--output=" + rebase_path(depfile),
237 ],
238 "")
239
Primiano Tucci3faad742018-05-16 19:30:48 +0100240 node_cmd = "tsc"
241 args = [
242 "--project",
243 rebase_path(".", root_build_dir),
244 "--outDir",
Hector Dearman262cbe22018-05-31 13:28:21 +0100245 rebase_path(target_out_dir, root_build_dir),
Primiano Tucci3faad742018-05-16 19:30:48 +0100246 ]
247}
248
249# +----------------------------------------------------------------------------+
Primiano Tucci21b91bf2018-08-06 16:42:07 +0100250# | Build css. |
251# +----------------------------------------------------------------------------+
252
253# Build css.
254node_bin("scss") {
255 deps = [
256 ":dist_symlink",
257 ]
258 main_css = "src/assets/perfetto.scss"
259 inputs = [
260 main_css,
261 "src/assets/sidebar.scss",
262 "src/assets/topbar.scss",
263 ]
264 outputs = [
265 "$ui_dir/perfetto.css",
266 ]
267
268 node_cmd = "node-sass"
269 args = [
270 "--quiet",
271 rebase_path(main_css, root_build_dir),
272 rebase_path(outputs[0], root_build_dir),
273 ]
274}
275
276# +----------------------------------------------------------------------------+
Hector Dearman262cbe22018-05-31 13:28:21 +0100277# | Copy rules: create the final output directory. |
Primiano Tucci3faad742018-05-16 19:30:48 +0100278# +----------------------------------------------------------------------------+
Hector Dearman10641512018-07-04 10:38:53 +0100279copy("index_dist") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100280 sources = [
281 "index.html",
282 ]
283 outputs = [
Hector Dearman262cbe22018-05-31 13:28:21 +0100284 "$ui_dir/index.html",
Primiano Tucci3faad742018-05-16 19:30:48 +0100285 ]
286}
287
Michail Schwab20bab202018-08-02 18:17:44 -0400288copy("assets_dist") {
289 sources = [
Hector Dearman7cf6b102018-08-09 17:30:57 +0100290 "src/assets/flamegraph.svg",
291 "src/assets/logo-3d.png",
292 "src/assets/logo.png",
293 "src/assets/perfetto.scss",
294 "src/assets/sidebar.scss",
295 "src/assets/topbar.scss",
Michail Schwab20bab202018-08-02 18:17:44 -0400296 ]
297 outputs = [
Hector Dearman7cf6b102018-08-09 17:30:57 +0100298 "$ui_dir/assets/{{source_file_part}}",
Michail Schwab20bab202018-08-02 18:17:44 -0400299 ]
300}
Hector Dearmandaca6cd2018-07-11 12:55:34 +0100301
Hector Dearman81804d12018-07-10 11:38:15 +0100302sorcery("frontend_bundle_dist") {
Hector Dearman262cbe22018-05-31 13:28:21 +0100303 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100304 ":frontend_bundle",
Hector Dearman262cbe22018-05-31 13:28:21 +0100305 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100306 input = "$target_out_dir/frontend_bundle.js"
307 output = "$ui_dir/frontend_bundle.js"
Hector Dearman5f11e522018-05-31 16:54:28 +0100308}
309
Hector Dearman81804d12018-07-10 11:38:15 +0100310sorcery("controller_bundle_dist") {
Hector Dearman5f11e522018-05-31 16:54:28 +0100311 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100312 ":controller_bundle",
Hector Dearman5f11e522018-05-31 16:54:28 +0100313 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100314 input = "$target_out_dir/controller_bundle.js"
315 output = "$ui_dir/controller_bundle.js"
Hector Dearman262cbe22018-05-31 13:28:21 +0100316}
317
Hector Dearman81804d12018-07-10 11:38:15 +0100318sorcery("engine_bundle_dist") {
Hector Dearman21fa9162018-06-22 14:50:29 +0100319 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100320 ":engine_bundle",
Hector Dearman21fa9162018-06-22 14:50:29 +0100321 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100322 input = "$target_out_dir/engine_bundle.js"
323 output = "$ui_dir/engine_bundle.js"
Hector Dearman21fa9162018-06-22 14:50:29 +0100324}
325
Hector Dearman10641512018-07-04 10:38:53 +0100326copy("wasm_dist") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100327 deps = [
Hector Dearmane8450742018-08-31 14:36:51 +0100328 "//src/trace_processor:trace_processor.wasm($wasm_toolchain)",
Hector Dearman21fa9162018-06-22 14:50:29 +0100329 ]
330 sources = [
Hector Dearmane8450742018-08-31 14:36:51 +0100331 "$root_build_dir/wasm/trace_processor.wasm",
Hector Dearman21fa9162018-06-22 14:50:29 +0100332 ]
333 outputs = [
334 "$ui_dir/{{source_file_part}}",
335 ]
336}
337
338copy("wasm_gen") {
339 deps = [
340 ":dist_symlink",
Hector Dearmane8450742018-08-31 14:36:51 +0100341 "//src/trace_processor:trace_processor.d.ts($wasm_toolchain)",
342 "//src/trace_processor:trace_processor.js($wasm_toolchain)",
343 "//src/trace_processor:trace_processor.wasm($wasm_toolchain)",
Primiano Tucci3faad742018-05-16 19:30:48 +0100344 ]
345 sources = [
Hector Dearmane8450742018-08-31 14:36:51 +0100346 "$root_build_dir/wasm/trace_processor.d.ts",
347 "$root_build_dir/wasm/trace_processor.js",
348 "$root_build_dir/wasm/trace_processor.wasm",
Primiano Tucci3faad742018-05-16 19:30:48 +0100349 ]
350 outputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100351 "$ui_gen_dir/{{source_file_part}}",
Primiano Tucci3faad742018-05-16 19:30:48 +0100352 ]
353}
354
355# +----------------------------------------------------------------------------+
Deepanjan Royacf8c072018-07-13 11:37:04 -0400356# | Node JS: Creates a symlink in the out directory to node_modules. |
Primiano Tucci3faad742018-05-16 19:30:48 +0100357# +----------------------------------------------------------------------------+
358
359action("check_node_exists") {
360 script = "../gn/standalone/check_buildtool_exists.py"
Hector Dearman48783b12018-05-22 08:26:06 +0100361 args = [
362 nodejs_bin,
363 "--touch",
364 rebase_path("$target_out_dir/node_exists", ""),
365 ]
Primiano Tucci3faad742018-05-16 19:30:48 +0100366 inputs = []
367 outputs = [
Hector Dearman48783b12018-05-22 08:26:06 +0100368 "$target_out_dir/node_exists",
Primiano Tucci3faad742018-05-16 19:30:48 +0100369 ]
370}
371
372# Creates a symlink from out/xxx/ui/node_modules -> ../../../ui/node_modules.
Hector Dearmanb06d4152018-05-31 16:55:04 +0100373# This allows to run rollup and other node tools from the out/xxx directory.
Primiano Tucci3faad742018-05-16 19:30:48 +0100374action("node_modules_symlink") {
375 deps = [
376 ":check_node_exists",
377 ]
Hector Dearman6186c872018-05-31 13:28:48 +0100378
Primiano Tucci3faad742018-05-16 19:30:48 +0100379 script = "../gn/standalone/build_tool_wrapper.py"
Hector Dearman6186c872018-05-31 13:28:48 +0100380 stamp_file = "$target_out_dir/.$target_name.stamp"
Primiano Tucci3faad742018-05-16 19:30:48 +0100381 args = [
Hector Dearman6186c872018-05-31 13:28:48 +0100382 "--stamp",
383 rebase_path(stamp_file, root_build_dir),
Primiano Tucci3faad742018-05-16 19:30:48 +0100384 "/bin/ln",
385 "-fns",
Hector Dearmana817a062018-06-01 11:01:07 +0100386 rebase_path("node_modules", target_out_dir),
Hector Dearman6186c872018-05-31 13:28:48 +0100387 rebase_path("$target_out_dir/node_modules", root_build_dir),
388 ]
389 outputs = [
390 stamp_file,
Primiano Tucci3faad742018-05-16 19:30:48 +0100391 ]
392}
393
Hector Dearman6186c872018-05-31 13:28:48 +0100394group("node_modules") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100395 deps = [
396 ":node_modules_symlink",
397 ]
398}
399
400# Creates a symlink from //ui/dist -> ../../out/xxx/ui. Used only for
401# autocompletion in IDEs. The problem this is solving is that in tsconfig.json
402# we can't possibly know the path to ../../out/xxx for outDir. Instead, we set
403# outDir to "./dist" and create a symlink on the first build.
404action("dist_symlink") {
405 script = "../gn/standalone/build_tool_wrapper.py"
Hector Dearman262cbe22018-05-31 13:28:21 +0100406 stamp_file = "$target_out_dir/.$target_name.stamp"
Primiano Tucci3faad742018-05-16 19:30:48 +0100407 args = [
408 "--stamp",
409 rebase_path(stamp_file, root_build_dir),
410 "/bin/ln",
411 "-fns",
Hector Dearman262cbe22018-05-31 13:28:21 +0100412 rebase_path(target_out_dir, "."),
Primiano Tucci3faad742018-05-16 19:30:48 +0100413 rebase_path("dist", root_build_dir),
414 ]
415 inputs = [
416 "$root_build_dir",
417 ]
418 outputs = [
419 stamp_file,
420 ]
421}
Hector Dearmanbf384922018-06-25 10:42:01 +0100422
423group("test_scripts") {
424 deps = [
425 ":copy_tests_script",
426 ":copy_unittests_script",
427 ]
428}
429
430copy("copy_unittests_script") {
431 sources = [
432 "config/ui_unittests_template",
433 ]
434 outputs = [
435 "$root_build_dir/ui_unittests",
436 ]
437}
438
439copy("copy_tests_script") {
440 sources = [
441 "config/ui_tests_template",
442 ]
443 outputs = [
444 "$root_build_dir/ui_tests",
445 ]
446}