blob: a42e9bb587bea6f45a31c7a34bcddc64bbceb055 [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",
Hector Dearmandaca6cd2018-07-11 12:55:34 +010031 ":css_dist",
Hector Dearman81804d12018-07-10 11:38:15 +010032 ":engine_bundle_dist",
33 ":frontend_bundle_dist",
Hector Dearman10641512018-07-04 10:38:53 +010034 ":index_dist",
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# +----------------------------------------------------------------------------+
Hector Dearman262cbe22018-05-31 13:28:21 +0100250# | Copy rules: create the final output directory. |
Primiano Tucci3faad742018-05-16 19:30:48 +0100251# +----------------------------------------------------------------------------+
Hector Dearman10641512018-07-04 10:38:53 +0100252copy("index_dist") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100253 sources = [
254 "index.html",
255 ]
256 outputs = [
Hector Dearman262cbe22018-05-31 13:28:21 +0100257 "$ui_dir/index.html",
Primiano Tucci3faad742018-05-16 19:30:48 +0100258 ]
259}
260
Hector Dearmandaca6cd2018-07-11 12:55:34 +0100261copy("css_dist") {
262 sources = [
263 "perfetto.css",
264 ]
265 outputs = [
266 "$ui_dir/perfetto.css",
267 ]
268}
Michail Schwab20bab202018-08-02 18:17:44 -0400269copy("assets_dist") {
270 sources = [
271 "src/assets",
272 ]
273 outputs = [
274 "$ui_dir/assets/",
275 ]
276}
Hector Dearmandaca6cd2018-07-11 12:55:34 +0100277
Hector Dearman81804d12018-07-10 11:38:15 +0100278sorcery("frontend_bundle_dist") {
Hector Dearman262cbe22018-05-31 13:28:21 +0100279 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100280 ":frontend_bundle",
Hector Dearman262cbe22018-05-31 13:28:21 +0100281 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100282 input = "$target_out_dir/frontend_bundle.js"
283 output = "$ui_dir/frontend_bundle.js"
Hector Dearman5f11e522018-05-31 16:54:28 +0100284}
285
Hector Dearman81804d12018-07-10 11:38:15 +0100286sorcery("controller_bundle_dist") {
Hector Dearman5f11e522018-05-31 16:54:28 +0100287 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100288 ":controller_bundle",
Hector Dearman5f11e522018-05-31 16:54:28 +0100289 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100290 input = "$target_out_dir/controller_bundle.js"
291 output = "$ui_dir/controller_bundle.js"
Hector Dearman262cbe22018-05-31 13:28:21 +0100292}
293
Hector Dearman81804d12018-07-10 11:38:15 +0100294sorcery("engine_bundle_dist") {
Hector Dearman21fa9162018-06-22 14:50:29 +0100295 deps = [
Hector Dearman81804d12018-07-10 11:38:15 +0100296 ":engine_bundle",
Hector Dearman21fa9162018-06-22 14:50:29 +0100297 ]
Hector Dearman81804d12018-07-10 11:38:15 +0100298 input = "$target_out_dir/engine_bundle.js"
299 output = "$ui_dir/engine_bundle.js"
Hector Dearman21fa9162018-06-22 14:50:29 +0100300}
301
Hector Dearman10641512018-07-04 10:38:53 +0100302copy("wasm_dist") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100303 deps = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100304 "//src/trace_processor:trace_processor.wasm($wasm_toolchain)",
305 ]
306 sources = [
307 "$root_build_dir/wasm/trace_processor.wasm",
308 ]
309 outputs = [
310 "$ui_dir/{{source_file_part}}",
311 ]
312}
313
314copy("wasm_gen") {
315 deps = [
316 ":dist_symlink",
317 "//src/trace_processor:trace_processor.d.ts($wasm_toolchain)",
Primiano Tucci3faad742018-05-16 19:30:48 +0100318 "//src/trace_processor:trace_processor.js($wasm_toolchain)",
319 "//src/trace_processor:trace_processor.wasm($wasm_toolchain)",
320 ]
321 sources = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100322 "$root_build_dir/wasm/trace_processor.d.ts",
Primiano Tucci3faad742018-05-16 19:30:48 +0100323 "$root_build_dir/wasm/trace_processor.js",
324 "$root_build_dir/wasm/trace_processor.wasm",
325 ]
326 outputs = [
Hector Dearman21fa9162018-06-22 14:50:29 +0100327 "$ui_gen_dir/{{source_file_part}}",
Primiano Tucci3faad742018-05-16 19:30:48 +0100328 ]
329}
330
331# +----------------------------------------------------------------------------+
Deepanjan Royacf8c072018-07-13 11:37:04 -0400332# | Node JS: Creates a symlink in the out directory to node_modules. |
Primiano Tucci3faad742018-05-16 19:30:48 +0100333# +----------------------------------------------------------------------------+
334
335action("check_node_exists") {
336 script = "../gn/standalone/check_buildtool_exists.py"
Hector Dearman48783b12018-05-22 08:26:06 +0100337 args = [
338 nodejs_bin,
339 "--touch",
340 rebase_path("$target_out_dir/node_exists", ""),
341 ]
Primiano Tucci3faad742018-05-16 19:30:48 +0100342 inputs = []
343 outputs = [
Hector Dearman48783b12018-05-22 08:26:06 +0100344 "$target_out_dir/node_exists",
Primiano Tucci3faad742018-05-16 19:30:48 +0100345 ]
346}
347
348# Creates a symlink from out/xxx/ui/node_modules -> ../../../ui/node_modules.
Hector Dearmanb06d4152018-05-31 16:55:04 +0100349# This allows to run rollup and other node tools from the out/xxx directory.
Primiano Tucci3faad742018-05-16 19:30:48 +0100350action("node_modules_symlink") {
351 deps = [
352 ":check_node_exists",
353 ]
Hector Dearman6186c872018-05-31 13:28:48 +0100354
Primiano Tucci3faad742018-05-16 19:30:48 +0100355 script = "../gn/standalone/build_tool_wrapper.py"
Hector Dearman6186c872018-05-31 13:28:48 +0100356 stamp_file = "$target_out_dir/.$target_name.stamp"
Primiano Tucci3faad742018-05-16 19:30:48 +0100357 args = [
Hector Dearman6186c872018-05-31 13:28:48 +0100358 "--stamp",
359 rebase_path(stamp_file, root_build_dir),
Primiano Tucci3faad742018-05-16 19:30:48 +0100360 "/bin/ln",
361 "-fns",
Hector Dearmana817a062018-06-01 11:01:07 +0100362 rebase_path("node_modules", target_out_dir),
Hector Dearman6186c872018-05-31 13:28:48 +0100363 rebase_path("$target_out_dir/node_modules", root_build_dir),
364 ]
365 outputs = [
366 stamp_file,
Primiano Tucci3faad742018-05-16 19:30:48 +0100367 ]
368}
369
Hector Dearman6186c872018-05-31 13:28:48 +0100370group("node_modules") {
Primiano Tucci3faad742018-05-16 19:30:48 +0100371 deps = [
372 ":node_modules_symlink",
373 ]
374}
375
376# Creates a symlink from //ui/dist -> ../../out/xxx/ui. Used only for
377# autocompletion in IDEs. The problem this is solving is that in tsconfig.json
378# we can't possibly know the path to ../../out/xxx for outDir. Instead, we set
379# outDir to "./dist" and create a symlink on the first build.
380action("dist_symlink") {
381 script = "../gn/standalone/build_tool_wrapper.py"
Hector Dearman262cbe22018-05-31 13:28:21 +0100382 stamp_file = "$target_out_dir/.$target_name.stamp"
Primiano Tucci3faad742018-05-16 19:30:48 +0100383 args = [
384 "--stamp",
385 rebase_path(stamp_file, root_build_dir),
386 "/bin/ln",
387 "-fns",
Hector Dearman262cbe22018-05-31 13:28:21 +0100388 rebase_path(target_out_dir, "."),
Primiano Tucci3faad742018-05-16 19:30:48 +0100389 rebase_path("dist", root_build_dir),
390 ]
391 inputs = [
392 "$root_build_dir",
393 ]
394 outputs = [
395 stamp_file,
396 ]
397}
Hector Dearmanbf384922018-06-25 10:42:01 +0100398
399group("test_scripts") {
400 deps = [
401 ":copy_tests_script",
402 ":copy_unittests_script",
403 ]
404}
405
406copy("copy_unittests_script") {
407 sources = [
408 "config/ui_unittests_template",
409 ]
410 outputs = [
411 "$root_build_dir/ui_unittests",
412 ]
413}
414
415copy("copy_tests_script") {
416 sources = [
417 "config/ui_tests_template",
418 ]
419 outputs = [
420 "$root_build_dir/ui_tests",
421 ]
422}