| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # This file has rules for making Dart packages and Dart-based Mojo applications. | 5 # This file has rules for making Dart packages and Dart-based Mojo applications. |
| 6 # | 6 # The entrypoint is the dart_pkg rule. |
| 7 # Entrypoint rules are: | |
| 8 # - dart_pkg | |
| 9 # - dartzip_package | |
| 10 # - dartzip_packaged_application | |
| 11 | 7 |
| 12 import("../mojo.gni") | 8 import("../mojo.gni") |
| 13 import("//build/module_args/mojo.gni") | 9 import("//build/module_args/mojo.gni") |
| 14 import("//build/module_args/dart.gni") | 10 import("//build/module_args/dart.gni") |
| 15 | 11 |
| 16 template("dartx") { | 12 template("dartx") { |
| 17 bundle_prefix = target_name | 13 bundle_prefix = target_name |
| 18 bundle = "$target_gen_dir/${bundle_prefix}.dartx" | 14 bundle = "$target_gen_dir/${bundle_prefix}.dartx" |
| 19 snapshot = "$target_gen_dir/${bundle_prefix}_snapshot.bin" | 15 snapshot = "$target_gen_dir/${bundle_prefix}_snapshot.bin" |
| 20 | 16 |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 pkg_name = invoker.app_name_override | 400 pkg_name = invoker.app_name_override |
| 405 } | 401 } |
| 406 foreach(entrypoint, invoker.apps) { | 402 foreach(entrypoint, invoker.apps) { |
| 407 entrypoint_name = get_path_info(entrypoint, "name") | 403 entrypoint_name = get_path_info(entrypoint, "name") |
| 408 dartx_target_name = "${pkg_name}_${entrypoint_name}" | 404 dartx_target_name = "${pkg_name}_${entrypoint_name}" |
| 409 deps += [ ":$dartx_target_name" ] | 405 deps += [ ":$dartx_target_name" ] |
| 410 } | 406 } |
| 411 } | 407 } |
| 412 } | 408 } |
| 413 } | 409 } |
| 414 | |
| 415 # Creates a dartzip package. | |
| 416 template("dartzip_package") { | |
| 417 package_target_name = "$target_name" | |
| 418 package_output = "$target_out_dir/$target_name.dartzip" | |
| 419 | |
| 420 if (defined(invoker.uses_pub) && invoker.uses_pub) { | |
| 421 # Repackage all dependencies pulled in via "pub get" in a dartzip file. | |
| 422 action("${package_target_name}_repackage") { | |
| 423 target_dir = get_label_info(":$target_name", "dir") | |
| 424 script = rebase_path("mojo/public/tools/gn/zip.py", ".", mojo_sdk_root) | |
| 425 | |
| 426 package_name = "$package_target_name" | |
| 427 if (defined(invoker.package_name_override)) { | |
| 428 package_name = invoker.package_name_override | |
| 429 } | |
| 430 | |
| 431 # Get a list of the files in packages/ as inputs. | |
| 432 list_packages_contents_script = | |
| 433 rebase_path("mojo/public/tools/dart_list_packages_contents.py", | |
| 434 ".", | |
| 435 mojo_sdk_root) | |
| 436 rebase_target_dir = rebase_path(target_dir, root_build_dir) | |
| 437 inputs = exec_script(list_packages_contents_script, | |
| 438 [ | |
| 439 "--target-directory", | |
| 440 rebase_target_dir, | |
| 441 "--package-name", | |
| 442 package_name, | |
| 443 ], | |
| 444 "list lines", | |
| 445 [ target_dir + "/pubspec.lock" ]) | |
| 446 | |
| 447 # Zip up all the pulled-in files relative to their location in the | |
| 448 # packages dir. | |
| 449 output = "$target_out_dir/$target_name.dartzip" | |
| 450 outputs = [ | |
| 451 output, | |
| 452 ] | |
| 453 rebase_base_dir = rebase_target_dir | |
| 454 rebase_inputs = rebase_path(inputs, root_build_dir) | |
| 455 rebase_output = rebase_path(output, root_build_dir) | |
| 456 args = [ | |
| 457 "--base-dir=$rebase_base_dir", | |
| 458 "--inputs=$rebase_inputs", | |
| 459 "--output=$rebase_output", | |
| 460 ] | |
| 461 } | |
| 462 } | |
| 463 | |
| 464 action("${package_target_name}_package") { | |
| 465 script = | |
| 466 rebase_path("mojo/public/tools/dart_package.py", ".", mojo_sdk_root) | |
| 467 | |
| 468 inputs = invoker.sources | |
| 469 | |
| 470 deps = [] | |
| 471 zip_inputs = [] | |
| 472 | |
| 473 if (defined(invoker.uses_pub) && invoker.uses_pub) { | |
| 474 deps += [ ":${package_target_name}_repackage" ] | |
| 475 } | |
| 476 | |
| 477 if (defined(invoker.deps)) { | |
| 478 deps += invoker.deps | |
| 479 foreach(d, deps) { | |
| 480 dep_name = get_label_info(d, "name") | |
| 481 dep_target_out_dir = get_label_info(d, "target_out_dir") | |
| 482 zip_inputs += [ "$dep_target_out_dir/$dep_name.dartzip" ] | |
| 483 } | |
| 484 } | |
| 485 | |
| 486 if (defined(invoker.datadeps)) { | |
| 487 datadeps = invoker.datadeps | |
| 488 } | |
| 489 | |
| 490 output = package_output | |
| 491 outputs = [ | |
| 492 output, | |
| 493 ] | |
| 494 | |
| 495 rebase_base_dir = | |
| 496 rebase_path(get_label_info(":$package_target_name", "dir"), | |
| 497 root_build_dir) | |
| 498 if (defined(invoker.base_dir)) { | |
| 499 rebase_base_dir = invoker.base_dir | |
| 500 } | |
| 501 rebase_inputs = rebase_path(inputs, root_build_dir) | |
| 502 rebase_zip_inputs = rebase_path(zip_inputs, root_build_dir) | |
| 503 rebase_output = rebase_path(output, root_build_dir) | |
| 504 | |
| 505 args = [ | |
| 506 "--base-dir=$rebase_base_dir", | |
| 507 "--inputs=$rebase_inputs", | |
| 508 "--zip-inputs=$rebase_zip_inputs", | |
| 509 "--output=$rebase_output", | |
| 510 ] | |
| 511 } | |
| 512 | |
| 513 action(target_name) { | |
| 514 script = | |
| 515 rebase_path("mojo/public/tools/dart_analyze.py", ".", mojo_sdk_root) | |
| 516 | |
| 517 sources = [ | |
| 518 package_output, | |
| 519 ] | |
| 520 | |
| 521 args = [ | |
| 522 "--dart-sdk", | |
| 523 rebase_path(dart_sdk_root), | |
| 524 "--dartzip-file", | |
| 525 rebase_path(package_output), | |
| 526 "--stamp-file", | |
| 527 rebase_path("$target_gen_dir/${package_target_name}_analyze.stamp"), | |
| 528 "--no-hints", | |
| 529 ] | |
| 530 | |
| 531 public_deps = [ | |
| 532 ":${package_target_name}_package", | |
| 533 ] | |
| 534 if (defined(invoker.deps)) { | |
| 535 deps = invoker.deps | |
| 536 } | |
| 537 | |
| 538 if (defined(invoker.datadeps)) { | |
| 539 datadeps = invoker.datadeps | |
| 540 } | |
| 541 | |
| 542 outputs = [ | |
| 543 "$target_gen_dir/${package_target_name}_analyze.stamp", | |
| 544 ] | |
| 545 } | |
| 546 } | |
| 547 | |
| 548 # Use this template to generate a .mojo dart application. One of the source | |
| 549 # files should be named main.dart and contain a main function as the | |
| 550 # entry point. Dependencies of dart_packaged_application targets should be | |
| 551 # either mojom targets (and specified using the mojom_deps variable) or | |
| 552 # dartzip_package targets. | |
| 553 template("dartzip_packaged_application") { | |
| 554 package_name = "${target_name}_package" | |
| 555 package_output = "$target_out_dir/$package_name.dartzip" | |
| 556 | |
| 557 if (defined(invoker.output_name)) { | |
| 558 mojo_output = "$root_out_dir/" + invoker.output_name + ".mojo" | |
| 559 } else { | |
| 560 mojo_output = "$root_out_dir/" + target_name + ".mojo" | |
| 561 } | |
| 562 | |
| 563 dartzip_package(package_name) { | |
| 564 sources = invoker.sources | |
| 565 if (defined(invoker.deps)) { | |
| 566 deps = invoker.deps | |
| 567 } | |
| 568 if (defined(invoker.uses_pub)) { | |
| 569 uses_pub = invoker.uses_pub | |
| 570 } | |
| 571 if (defined(invoker.mojom_deps)) { | |
| 572 mojom_deps = invoker.mojom_deps | |
| 573 } | |
| 574 if (defined(invoker.datadeps)) { | |
| 575 datadeps = invoker.datadeps | |
| 576 } | |
| 577 } | |
| 578 | |
| 579 action(target_name) { | |
| 580 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_sdk_root) | |
| 581 | |
| 582 input = package_output | |
| 583 inputs = [ | |
| 584 input, | |
| 585 ] | |
| 586 | |
| 587 output = mojo_output | |
| 588 outputs = [ | |
| 589 output, | |
| 590 ] | |
| 591 | |
| 592 deps = [ | |
| 593 ":$package_name", | |
| 594 ] | |
| 595 if (defined(invoker.deps)) { | |
| 596 deps += invoker.deps | |
| 597 } | |
| 598 if (defined(invoker.mojom_deps)) { | |
| 599 deps += invoker.mojom_deps | |
| 600 } | |
| 601 if (defined(invoker.datadeps)) { | |
| 602 datadeps = invoker.datadeps | |
| 603 } | |
| 604 | |
| 605 line = "#!mojo mojo:dart_content_handler" | |
| 606 if (is_debug || (defined(invoker.strict) && invoker.strict == true)) { | |
| 607 line = "#!mojo mojo:dart_content_handler?strict=true" | |
| 608 } | |
| 609 | |
| 610 rebase_input = rebase_path(input, root_build_dir) | |
| 611 rebase_output = rebase_path(output, root_build_dir) | |
| 612 args = [ | |
| 613 "--input=$rebase_input", | |
| 614 "--output=$rebase_output", | |
| 615 "--line=$line", | |
| 616 ] | |
| 617 } | |
| 618 } | |
| OLD | NEW |