OLD | NEW |
1 # Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 _dart_root = rebase_path("..") | 5 _dart_root = rebase_path("..") |
6 | 6 |
7 # copy_tree() copies a directory tree rooted at `source` to `dest`, which should | 7 # copy_tree() copies a directory tree rooted at `source` to `dest`, which should |
8 # be somewhere under $root_out_dir. | 8 # be somewhere under $root_out_dir. |
9 # | 9 # |
10 # Optional parameters: | 10 # Optional parameters: |
11 # exclude - A comma separated list that is passed to shutil.ignore_patterns() | 11 # exclude - A comma separated list that is passed to shutil.ignore_patterns() |
12 # in tools/copy_tree.py. | 12 # in tools/copy_tree.py. |
13 template("copy_tree") { | 13 template("_copy_tree") { |
14 assert(defined(invoker.source), "copy_tree must define 'source'") | 14 assert(defined(invoker.source), "copy_tree must define 'source'") |
15 assert(defined(invoker.dest), "copy_tree must define 'dest'") | 15 assert(defined(invoker.dest), "copy_tree must define 'dest'") |
| 16 assert(defined(invoker.inputs), "copy_tree must define 'inputs'") |
16 source = invoker.source | 17 source = invoker.source |
17 dest = invoker.dest | 18 dest = invoker.dest |
| 19 inputs = invoker.inputs |
18 action(target_name) { | 20 action(target_name) { |
19 if (defined(invoker.visibility)) { | 21 if (defined(invoker.visibility)) { |
20 visibility = invoker.visibility | 22 visibility = invoker.visibility |
21 } | 23 } |
22 | 24 |
23 deps = [] | 25 deps = [] |
24 if (defined(invoker.deps)) { | 26 if (defined(invoker.deps)) { |
25 deps += invoker.deps | 27 deps += invoker.deps |
26 } | 28 } |
27 | 29 |
28 common_args = [ | 30 common_args = [ |
29 "--from", | 31 "--from", |
30 rebase_path(source), | 32 rebase_path(source), |
31 "--to", | 33 "--to", |
32 rebase_path(dest), | 34 rebase_path(dest), |
33 ] | 35 ] |
34 if (defined(invoker.exclude)) { | 36 if (defined(invoker.exclude)) { |
35 common_args += [ | 37 common_args += [ |
36 "--exclude", | 38 "--exclude", |
37 invoker.exclude, | 39 invoker.exclude, |
38 ] | 40 ] |
39 } | 41 } |
40 | 42 |
41 dry_run_args = common_args + [ "--dry-run" ] | 43 relative_files = rebase_path(inputs, rebase_path(source)) |
42 input_files = exec_script("$_dart_root/tools/copy_tree.py", | |
43 dry_run_args, | |
44 "list lines") | |
45 inputs = input_files | |
46 relative_files = rebase_path(input_files, rebase_path(source)) | |
47 | 44 |
48 output_files = [] | 45 output_files = [] |
49 foreach(input, relative_files) { | 46 foreach(input, relative_files) { |
50 output_files += [ "$dest/$input" ] | 47 output_files += [ "$dest/$input" ] |
51 } | 48 } |
52 | 49 |
53 outputs = output_files | 50 outputs = output_files |
54 script = "$_dart_root/tools/copy_tree.py" | 51 script = "$_dart_root/tools/copy_tree.py" |
55 args = common_args | 52 args = common_args |
56 } | 53 } |
57 } | 54 } |
| 55 |
| 56 # copy_trees() arranges to invoke copy_tree.py only once to gather the list of |
| 57 # input source files for every _copy_tree() target. It takes a list of scopes as |
| 58 # a parameter. The scopes should contain the following mappings. |
| 59 # |
| 60 # target: The target name for the _copy_tree() target. |
| 61 # visibility: The visibility for the _copy_tree() target. |
| 62 # source: The source directory relative to this directory. |
| 63 # dest: The destination directory for the _copy_tree() target. |
| 64 # deps: Any deps needed for the _copy_tree() target. |
| 65 # ignore_patterns: Patterns to ignore when walking the directory tree. |
| 66 # This should be '{}' if nothing should be ignored. |
| 67 # |
| 68 # copy_trees() will then make sure each invocation of _copy_tree() has the |
| 69 # correct 'inputs' parameter |
| 70 template("copy_trees") { |
| 71 assert(defined(invoker.sources), "$target_name must define 'source'") |
| 72 sources = invoker.sources |
| 73 copy_tree_source_paths = [] |
| 74 foreach(copy_tree_spec, sources) { |
| 75 copy_tree_source_paths += [ |
| 76 rebase_path(copy_tree_spec.source), |
| 77 copy_tree_spec.ignore_patterns |
| 78 ] |
| 79 } |
| 80 |
| 81 # Evaluate script output as GN, producing a scope containing a single value |
| 82 # "sources" |
| 83 copy_tree_inputs_scope = exec_script("$_dart_root/tools/copy_tree.py", |
| 84 ["--gn"] + copy_tree_source_paths, |
| 85 "scope") |
| 86 |
| 87 # A list of lists of input source files for copy_tree. |
| 88 copy_tree_inputs = copy_tree_inputs_scope.sources |
| 89 copy_tree_inputs_index = 0 |
| 90 foreach(copy_tree_spec, sources) { |
| 91 _copy_tree(copy_tree_spec.target) { |
| 92 visibility = copy_tree_spec.visibility |
| 93 source = copy_tree_spec.source |
| 94 dest = copy_tree_spec.dest |
| 95 inputs = copy_tree_inputs[copy_tree_inputs_index] |
| 96 if (defined(copy_tree_spec.deps)) { |
| 97 deps = copy_tree_spec.deps |
| 98 } |
| 99 if (copy_tree_spec.ignore_patterns != "{}") { |
| 100 exclude = copy_tree_spec.ignore_patterns |
| 101 } |
| 102 } |
| 103 copy_tree_inputs_index = copy_tree_inputs_index + 1 |
| 104 } |
| 105 } |
OLD | NEW |