| # Copyright 2016 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # This defines a fuchsia_component template that builds a component from a |
| # manifest and an executable rule. It will package up any resources that are |
| # declared in the component manifest too. |
| # It should be used with a corresponding "component" entry in packages/gn/* |
| # It takes: |
| # manifest: the name of the JSON manifest that defines the component |
| # program: the target that produces the program executable |
| template("fuchsia_component") { |
| # TODO(ianloic) remove Chromium's concept of components from our build system |
| # and rename this to "component" |
| |
| assert(defined(invoker.manifest), "manifest must be defined for $target_name") |
| |
| # TODO(ianloic): support non-program components |
| assert(defined(invoker.program) || defined(invoker.flutter_program), |
| "program or flutter_program must be defined for $target_name") |
| |
| if (defined(invoker.program)) { |
| program = invoker.program |
| |
| # TODO(ianloic): handle output_name being set in program |
| program_name = get_label_info(program, "name") |
| program_out_path = "${root_out_dir}/${program_name}" |
| } else { |
| assert(defined(invoker.flutter_program)) |
| program = invoker.flutter_program |
| program_name = get_label_info(program, "name") |
| program_gen_dir = get_label_info(program, "target_gen_dir") |
| program_out_path = "${program_gen_dir}/${program_name}.flx" |
| } |
| |
| manifest_scope = exec_script("//build/component/component_rules.py", |
| [ rebase_path(invoker.manifest) ], |
| "scope", |
| [ invoker.manifest ]) |
| copy_labels = [] |
| |
| program_scope = manifest_scope.program |
| i = 1 |
| foreach(file, manifest_scope.files) { |
| copy_label = "${target_name}__copy__$i" |
| i = i + 1 |
| copy(copy_label) { |
| if (file.url == program_scope.url) { |
| sources = [ |
| program_out_path, |
| ] |
| deps = [ |
| program, |
| ] |
| } else { |
| sources = [ |
| file.src_path, |
| ] |
| } |
| outputs = [ |
| "${root_out_dir}/components/${file.url_as_path}", |
| ] |
| } |
| copy_labels += [ ":${copy_label}" ] |
| } |
| |
| group(target_name) { |
| deps = copy_labels |
| } |
| } |