blob: 7ebca4ce5c9f51da497408f5232438a6ef22ad6f [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 = [
290 "src/assets",
291 ]
292 outputs = [
293 "$ui_dir/assets/",
294 ]
295}
Hector Dearmandaca6cd2018-07-11 12:55:34 +0100296
Hector Dearman81804d12018-07-10 11:38:15 +0100297sorcery("frontend_bundle_dist") {
Hector Dearman262cbe22018-05-31 13:28:21 +0100298 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100299 ":frontend_bundle",
Hector Dearman262cbe22018-05-31 13:28:21 +0100300 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100301 input = "$target_out_dir/frontend_bundle.js"
302 output = "$ui_dir/frontend_bundle.js"
Hector Dearman5f11e522018-05-31 16:54:28 +0100303}
304
Hector Dearman81804d12018-07-10 11:38:15 +0100305sorcery("controller_bundle_dist") {
Hector Dearman5f11e522018-05-31 16:54:28 +0100306 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100307 ":controller_bundle",
Hector Dearman5f11e522018-05-31 16:54:28 +0100308 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100309 input = "$target_out_dir/controller_bundle.js"
310 output = "$ui_dir/controller_bundle.js"
Hector Dearman262cbe22018-05-31 13:28:21 +0100311}
312
Hector Dearman81804d12018-07-10 11:38:15 +0100313sorcery("engine_bundle_dist") {
Hector Dearman21fa9162018-06-22 14:50:29 +0100314 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100315 ":engine_bundle",
Hector Dearman21fa9162018-06-22 14:50:29 +0100316 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100317 input = "$target_out_dir/engine_bundle.js"
318 output = "$ui_dir/engine_bundle.js"
Hector Dearman21fa9162018-06-22 14:50:29 +0100319}
320
Hector Dearman10641512018-07-04 10:38:53 +0100321copy("wasm_dist") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100322 deps = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100323 "//src/trace_processor:trace_processor.wasm($wasm_toolchain)",
324 ]
325 sources = [
326 "$root_build_dir/wasm/trace_processor.wasm",
327 ]
328 outputs = [
329 "$ui_dir/{{source_file_part}}",
330 ]
331}
332
333copy("wasm_gen") {
334 deps = [
335 ":dist_symlink",
336 "//src/trace_processor:trace_processor.d.ts($wasm_toolchain)",
Primiano Tucci3faad742018-05-16 19:30:48 +0100337 "//src/trace_processor:trace_processor.js($wasm_toolchain)",
338 "//src/trace_processor:trace_processor.wasm($wasm_toolchain)",
339 ]
340 sources = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100341 "$root_build_dir/wasm/trace_processor.d.ts",
Primiano Tucci3faad742018-05-16 19:30:48 +0100342 "$root_build_dir/wasm/trace_processor.js",
343 "$root_build_dir/wasm/trace_processor.wasm",
344 ]
345 outputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100346 "$ui_gen_dir/{{source_file_part}}",
Primiano Tucci3faad742018-05-16 19:30:48 +0100347 ]
348}
349
350# +----------------------------------------------------------------------------+
Deepanjan Royacf8c072018-07-13 11:37:04 -0400351# | Node JS: Creates a symlink in the out directory to node_modules. |
Primiano Tucci3faad742018-05-16 19:30:48 +0100352# +----------------------------------------------------------------------------+
353
354action("check_node_exists") {
355 script = "../gn/standalone/check_buildtool_exists.py"
Hector Dearman48783b12018-05-22 08:26:06 +0100356 args = [
357 nodejs_bin,
358 "--touch",
359 rebase_path("$target_out_dir/node_exists", ""),
360 ]
Primiano Tucci3faad742018-05-16 19:30:48 +0100361 inputs = []
362 outputs = [
Hector Dearman48783b12018-05-22 08:26:06 +0100363 "$target_out_dir/node_exists",
Primiano Tucci3faad742018-05-16 19:30:48 +0100364 ]
365}
366
367# Creates a symlink from out/xxx/ui/node_modules -> ../../../ui/node_modules.
Hector Dearmanb06d4152018-05-31 16:55:04 +0100368# This allows to run rollup and other node tools from the out/xxx directory.
Primiano Tucci3faad742018-05-16 19:30:48 +0100369action("node_modules_symlink") {
370 deps = [
371 ":check_node_exists",
372 ]
Hector Dearman6186c872018-05-31 13:28:48 +0100373
Primiano Tucci3faad742018-05-16 19:30:48 +0100374 script = "../gn/standalone/build_tool_wrapper.py"
Hector Dearman6186c872018-05-31 13:28:48 +0100375 stamp_file = "$target_out_dir/.$target_name.stamp"
Primiano Tucci3faad742018-05-16 19:30:48 +0100376 args = [
Hector Dearman6186c872018-05-31 13:28:48 +0100377 "--stamp",
378 rebase_path(stamp_file, root_build_dir),
Primiano Tucci3faad742018-05-16 19:30:48 +0100379 "/bin/ln",
380 "-fns",
Hector Dearmana817a062018-06-01 11:01:07 +0100381 rebase_path("node_modules", target_out_dir),
Hector Dearman6186c872018-05-31 13:28:48 +0100382 rebase_path("$target_out_dir/node_modules", root_build_dir),
383 ]
384 outputs = [
385 stamp_file,
Primiano Tucci3faad742018-05-16 19:30:48 +0100386 ]
387}
388
Hector Dearman6186c872018-05-31 13:28:48 +0100389group("node_modules") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100390 deps = [
391 ":node_modules_symlink",
392 ]
393}
394
395# Creates a symlink from //ui/dist -> ../../out/xxx/ui. Used only for
396# autocompletion in IDEs. The problem this is solving is that in tsconfig.json
397# we can't possibly know the path to ../../out/xxx for outDir. Instead, we set
398# outDir to "./dist" and create a symlink on the first build.
399action("dist_symlink") {
400 script = "../gn/standalone/build_tool_wrapper.py"
Hector Dearman262cbe22018-05-31 13:28:21 +0100401 stamp_file = "$target_out_dir/.$target_name.stamp"
Primiano Tucci3faad742018-05-16 19:30:48 +0100402 args = [
403 "--stamp",
404 rebase_path(stamp_file, root_build_dir),
405 "/bin/ln",
406 "-fns",
Hector Dearman262cbe22018-05-31 13:28:21 +0100407 rebase_path(target_out_dir, "."),
Primiano Tucci3faad742018-05-16 19:30:48 +0100408 rebase_path("dist", root_build_dir),
409 ]
410 inputs = [
411 "$root_build_dir",
412 ]
413 outputs = [
414 stamp_file,
415 ]
416}
Hector Dearmanbf384922018-06-25 10:42:01 +0100417
418group("test_scripts") {
419 deps = [
420 ":copy_tests_script",
421 ":copy_unittests_script",
422 ]
423}
424
425copy("copy_unittests_script") {
426 sources = [
427 "config/ui_unittests_template",
428 ]
429 outputs = [
430 "$root_build_dir/ui_unittests",
431 ]
432}
433
434copy("copy_tests_script") {
435 sources = [
436 "config/ui_tests_template",
437 ]
438 outputs = [
439 "$root_build_dir/ui_tests",
440 ]
441}