Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: mojo/public/dart/rules.gni

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/dart/.gitignore ('k') | mojo/public/dart/tools/fetch_dart_packages.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 # This file has rules for making Dart packages and Dart-based Mojo applications.
6 # The entrypoint is the dart_pkg rule.
7
8 import("../mojo.gni")
9 import("//build/module_args/mojo.gni")
10 import("//build/module_args/dart.gni")
11
12 template("dartx") {
13 bundle_prefix = target_name
14 bundle = "$target_gen_dir/${bundle_prefix}.dartx"
15 snapshot = "$target_gen_dir/${bundle_prefix}_snapshot.bin"
16 depfile_path = "${snapshot}.d"
17
18 if (mojo_use_prebuilt_dart_snapshotter) {
19 dart_snapshotter_path =
20 rebase_path("mojo/public/tools:copy_dart_snapshotter", ".", mojo_root)
21 dart_snapshotter_rule = "$dart_snapshotter_path($host_toolchain)"
22 } else {
23 dart_snapshotter_rule = dart_snapshotter_bin
24 }
25 dart_snapshotter_dir =
26 get_label_info("$dart_snapshotter_rule", "root_out_dir")
27 dart_snapshotter = "$dart_snapshotter_dir/dart_snapshotter"
28
29 action("gen_${bundle_prefix}_snapshot") {
30 main_dart = invoker.main_dart
31
32 depfile = depfile_path
33
34 inputs = [
35 dart_snapshotter,
36 ]
37 outputs = [
38 snapshot,
39 ]
40
41 if (defined(invoker.sources)) {
42 sources = invoker.sources
43 }
44
45 script =
46 rebase_path("mojo/public/tools/dart_snapshotter.py", ".", mojo_sdk_root)
47
48 args = [
49 rebase_path(dart_snapshotter),
50 rebase_path(main_dart),
51 "--package-root",
52 rebase_path("$root_gen_dir/dart-pkg/packages"),
53 "--snapshot",
54 rebase_path(snapshot),
55 "--depfile",
56 rebase_path(depfile_path),
57 "--build-output",
58 rebase_path(snapshot, root_build_dir), # Relative to build directory
59 ]
60
61 deps = [
62 dart_snapshotter_rule,
63 ]
64 if (defined(invoker.deps)) {
65 deps += invoker.deps
66 }
67 }
68
69 action("gen_${bundle_prefix}_bundle") {
70 sources = [
71 rebase_path("mojo/public/tools/dartx.py", ".", mojo_sdk_root),
72 snapshot,
73 ]
74
75 outputs = [
76 bundle,
77 ]
78
79 script = rebase_path("mojo/public/tools/dartx.py", ".", mojo_sdk_root)
80 args = [
81 "--snapshot",
82 rebase_path(snapshot),
83 "--output",
84 rebase_path(bundle),
85 ]
86
87 deps = [
88 ":gen_${bundle_prefix}_snapshot",
89 ]
90 }
91
92 group(target_name) {
93 public_deps = [
94 ":gen_${bundle_prefix}_bundle",
95 ]
96 }
97 }
98
99 template("dartx_application") {
100 dartx_name = "${target_name}_dartx"
101
102 dartx(dartx_name) {
103 main_dart = invoker.main_dart
104 if (defined(invoker.sources)) {
105 sources = invoker.sources
106 }
107 if (defined(invoker.deps)) {
108 deps = invoker.deps
109 }
110 }
111
112 if (defined(invoker.output_name)) {
113 mojo_output = "$root_out_dir/" + invoker.output_name + ".mojo"
114 } else {
115 mojo_output = "$root_out_dir/" + target_name + ".mojo"
116 }
117
118 action(target_name) {
119 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_sdk_root)
120
121 input = "$target_gen_dir/${dartx_name}.dartx"
122 inputs = [
123 input,
124 ]
125
126 output = mojo_output
127 outputs = [
128 output,
129 ]
130
131 deps = [
132 ":$dartx_name",
133 ]
134 if (defined(invoker.deps)) {
135 deps += invoker.deps
136 }
137
138 line = "#!mojo mojo:dart_content_handler"
139 if (is_debug || (defined(invoker.strict) && invoker.strict == true)) {
140 line = "#!mojo mojo:dart_content_handler?strict=true"
141 }
142
143 rebase_input = rebase_path(input, root_build_dir)
144 rebase_output = rebase_path(output, root_build_dir)
145 args = [
146 "--input=$rebase_input",
147 "--output=$rebase_output",
148 "--line=$line",
149 ]
150 }
151 }
152
153 template("dart_pkg_helper") {
154 assert(defined(invoker.package_name))
155 package_name = invoker.package_name
156 pkg_directory = rebase_path("$root_gen_dir/dart-pkg")
157 package_root = rebase_path("$root_gen_dir/dart-pkg/packages")
158 stamp_file = "$root_gen_dir/dart-pkg/${package_name}.stamp"
159 entries_file = "$root_gen_dir/dart-pkg/${package_name}.entries"
160
161 assert(defined(invoker.sources) || defined(invoker.apps) ||
162 defined(invoker.libs) || defined(invoker.pkg_dir))
163
164 action(target_name) {
165 deps = []
166 if (defined(invoker.deps)) {
167 deps += invoker.deps
168 }
169
170 datadeps = []
171 if (defined(invoker.datadeps)) {
172 datadeps += invoker.datadeps
173 }
174
175 sdk_ext_directory = []
176 if (defined(invoker.sdk_ext_directory)) {
177 sdk_ext_directory += [ invoker.sdk_ext_directory ]
178 }
179
180 sdk_ext_files = []
181 if (defined(invoker.sdk_ext_files)) {
182 sdk_ext_files += invoker.sdk_ext_files
183 }
184
185 sdk_ext_mappings = []
186 if (defined(invoker.sdk_ext_mappings)) {
187 sdk_ext_mappings += invoker.sdk_ext_mappings
188 }
189
190 script = rebase_path("mojo/public/tools/dart_pkg.py", ".", mojo_sdk_root)
191
192 entrypoints = []
193 if (defined(invoker.apps)) {
194 foreach(app, invoker.apps) {
195 entrypoints += [ app[1] ]
196 }
197 }
198 if (defined(invoker.libs)) {
199 entrypoints += invoker.libs
200 }
201
202 sources = entrypoints
203 extra_flags = []
204 if (defined(invoker.sources)) {
205 sources += invoker.sources
206 } else if (defined(invoker.pkg_dir)) {
207 list_script = rebase_path("mojo/public/tools/ls.py", ".", mojo_sdk_root)
208 extra_flags += [ "--read_only" ]
209 ls_sources = exec_script(list_script,
210 [
211 "--target-directory",
212 rebase_path(invoker.pkg_dir),
213 ],
214 "list lines")
215 sources += ls_sources
216 }
217
218 # We have to use foreach to set up outputs instead of rebase_path because
219 # GN doesn't like assignments to outputs that aren't obviously under
220 # $root_gen_dir somewhere.
221 outputs = [
222 "$root_gen_dir/dart-pkg/${package_name}",
223 "$root_gen_dir/dart-pkg/packages/${package_name}",
224 stamp_file,
225 ]
226
227 inputs = [ script ] + rebase_path(sources)
228
229 args = [
230 "--package-name",
231 package_name,
232 "--dart-sdk",
233 rebase_path(dart_sdk_root),
234 "--pkg-directory",
235 pkg_directory,
236 "--package-root",
237 package_root,
238 "--stamp-file",
239 rebase_path(stamp_file),
240 "--entries-file",
241 rebase_path(entries_file),
242 "--package-sources",
243 ] + rebase_path(sources) + [ "--package-entrypoints" ] +
244 rebase_path(entrypoints) + [ "--sdk-ext-directories" ] +
245 rebase_path(sdk_ext_directory) + [ "--sdk-ext-files" ] +
246 rebase_path(sdk_ext_files) + [ "--sdk-ext-mappings" ] +
247 sdk_ext_mappings + extra_flags
248 }
249 }
250
251 # This is the entrypoint for organizing Dart code for Mojo.
252 #
253 # There should be a one to one mapping between dart_pkg rules and pubspec.yamls.
254 #
255 # This build rule will result in a package under $root_gen_dir/dart-pkg/
256 #
257 # The name of the package is taken from the 'pubspec.yaml' file.
258 #
259 # For each app in |apps|, it makes a .mojo Mojo application using the dartx
260 # format as well as an assemblage of the app under $root_gen_dir/dart-pkg for
261 # use in local development.
262 #
263 # For each library in |libs|, it invokes the Dart analyzer on that library. The
264 # build will fail if the library is not analyzer clean.
265 #
266 # All other sources go in |sources|. This should at least contain the
267 # 'pubspec.yaml' file.
268 #
269 # Even if a package will not be uploaded to pub, an attempt should be made not
270 # to conflict with the names of existing pub packages, for example by using the
271 # prefix 'mojo_dart_'.
272 #
273 # sources
274 # List of sources to include in the package. This should at least contain
275 # the pubspec.yaml for the package.
276 #
277 # apps (optional)
278 # List of pairs. [mojo_app_name, entrypoint.dart]. Each entrypoint
279 # script must contain a main() function. A .mojo Mojo application will be
280 # generated for each application.
281 #
282 # libs (optional)
283 # List of library entrypoints to pass to the analyzer. If none are
284 # defined, the analyzer is not run.
285 #
286 # strict (optional)
287 # If |apps| are specified, |strict| can be set to true to
288 # instruct the content handler to run the apps in Dart VM's strict
289 # compilation mode (with assertions and type-checks, etc.).
290 #
291 # deps (optional)
292 # List of other dart_pkg targets for Dart packages imported by this
293 # dart_pkg, as well as the mojom targets needed by this dart_pkg.
294 #
295 # pkg_dir (optional)
296 # Directory containing the package sources. This overrides sources and
297 # entrypoints. The analyzer will not be run.
298 #
299 # datadeps (optional)
300 #
301 # sdk_ext_directory (optional)
302 # Directory containing sdk-ext .dart sources.
303 #
304 # sdk_ext_files (optional)
305 # List of sources to include in sdk-ext.
306 #
307 # sdk_ext_mappings (optional)
308 # Mappings for dart libraries that are part of of sdk_ext.
309 template("dart_pkg") {
310 if (defined(invoker.pkg_dir)) {
311 pubspec_yaml_path = rebase_path("pubspec.yaml", "", invoker.pkg_dir)
312 } else {
313 pubspec_yaml_path = rebase_path("pubspec.yaml")
314 }
315 dart_package_name_script =
316 rebase_path("mojo/public/tools/dart_package_name.py", ".", mojo_sdk_root)
317 dart_package_name = exec_script(dart_package_name_script,
318 [
319 "--pubspec",
320 pubspec_yaml_path,
321 ],
322 "trim string",
323 [ pubspec_yaml_path ])
324
325 dart_pkg_target_name = "${target_name}_pkg_helper"
326 dart_pkg_helper(dart_pkg_target_name) {
327 package_name = dart_package_name
328 if (defined(invoker.sources)) {
329 sources = invoker.sources
330 }
331 if (defined(invoker.apps)) {
332 apps = invoker.apps
333 }
334 if (defined(invoker.libs)) {
335 libs = invoker.libs
336 }
337 if (defined(invoker.pkg_dir)) {
338 pkg_dir = invoker.pkg_dir
339 }
340 if (defined(invoker.deps)) {
341 deps = invoker.deps
342 }
343 if (defined(invoker.datadeps)) {
344 datadeps = invoker.datadeps
345 }
346 if (defined(invoker.sdk_ext_directory)) {
347 sdk_ext_directory = invoker.sdk_ext_directory
348 }
349 if (defined(invoker.sdk_ext_files)) {
350 sdk_ext_files = invoker.sdk_ext_files
351 }
352 if (defined(invoker.sdk_ext_mappings)) {
353 sdk_ext_mappings = invoker.sdk_ext_mappings
354 }
355 }
356
357 if (defined(invoker.apps)) {
358 pkg_helper_output_dir = "$root_gen_dir/dart-pkg/${dart_package_name}"
359 foreach(app, invoker.apps) {
360 app_name = app[0]
361 app_entrypoint = app[1]
362 dartx_output_name = app_name
363 dartx_application("${app_name}_dart_app") {
364 output_name = dartx_output_name
365 main_dart = rebase_path(app_entrypoint, "", pkg_helper_output_dir)
366 sources = [
367 "$root_gen_dir/dart-pkg/${dart_package_name}.stamp",
368 ]
369 deps = [
370 ":$dart_pkg_target_name",
371 ]
372 deps += invoker.deps
373 if (defined(invoker.strict)) {
374 strict = invoker.strict
375 }
376 }
377 }
378 }
379
380 group(target_name) {
381 deps = [
382 ":$dart_pkg_target_name",
383 ]
384 if (defined(invoker.apps)) {
385 foreach(app, invoker.apps) {
386 app_name = app[0]
387 dartx_target_name = "${app_name}_dart_app"
388 deps += [ ":$dartx_target_name" ]
389 }
390 }
391 }
392 }
393
394 # Used to create dart_pkgs from a directory populated by fetch_dart_packages.py
395 #
396 # This build rule will result in a many packages under $root_gen_dir/dart-pkg/.
397 #
398 # base_dir (optional)
399 # Directory populated by fetch_dart_packages.py. Defaults to BUILD.gn
400 # directory.
401 template("dart_packages") {
402 base_dir = "."
403 if (defined(invoker.base_dir)) {
404 base_dir = invoker.base_dir
405 }
406
407 # Determine list of packages.
408 list_script = rebase_path("mojo/public/dart/tools/fetch_dart_packages.py",
409 ".",
410 mojo_sdk_root)
411 packages = exec_script(list_script,
412 [
413 "--directory",
414 rebase_path(base_dir),
415 "--list",
416 ],
417 "list lines",
418 [
419 rebase_path("pubspec.yaml"),
420 rebase_path("pubspec.lock"),
421 ])
422
423 # Generate dart_pkg for each package.
424 foreach(package_dir, packages) {
425 dart_pkg("$package_dir") {
426 pkg_dir = rebase_path("$package_dir")
427 }
428 }
429
430 # Generate target group.
431 group(target_name) {
432 deps = []
433 foreach(package_dir, packages) {
434 deps += [ ":$package_dir" ]
435 }
436 if (defined(invoker.deps)) {
437 deps += invoker.deps
438 }
439 }
440 }
OLDNEW
« no previous file with comments | « mojo/public/dart/.gitignore ('k') | mojo/public/dart/tools/fetch_dart_packages.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698