1
0
mirror of https://github.com/dart-lang/sdk synced 2024-07-03 08:19:13 +00:00
dart-sdk/build/dart/copy_tree.gni
Zach Anderson 03101837d9 [gn] Deprecate copy_trees()
Part of https://github.com/flutter/flutter/issues/144430

This is a reland of https://dart-review.googlesource.com/c/sdk/+/356481 with the addition of dependencies to prevent races on directory creation.

Previously, this code did backflips to accomplish two goals
1. Collect the paths of all files that would be copied from one place to another after applying regex filters so that they could be listed as the "inputs" to a GN action.
2. Arrange so that the python script doing the above would only be invoked once during GN to reduce the cost of calling out to python.

However, this is exactly the use-case for the "depfile" parameter to a GN action. Instead of running the script during GN to populate the "inputs" list, when we run the copy_tree.py script, we can instead ask it to generate a depfile to collect all the input files that were actually copied after applying the regex filter. Using that, we don't have to run the python script at all during GN.

TEST=it builds

Change-Id: I593e2500544a9fff5dd9852d0d3370f97aafc464
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356620
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Zach Anderson <zra@google.com>
2024-03-09 04:14:39 +00:00

88 lines
2.6 KiB
Plaintext

# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
_dart_root = rebase_path("../..")
# copy_tree() copies a directory tree rooted at `source` to `dest`, which should
# be somewhere under $root_out_dir.
#
# When dest is a subdirectory of the dest of a different copy_tree() target,
# the target whose dest is the subdirectory should include the target whose
# dest is the parent directory in its "deps" list. This prevents races on
# directory creation that could happen if the two targets were executed
# concurrently.
#
# Optional parameters:
# exclude - A comma separated list that is passed to shutil.ignore_patterns()
# in tools/copy_tree.py.
template("copy_tree") {
assert(defined(invoker.source), "copy_tree must define 'source'")
assert(defined(invoker.dest), "copy_tree must define 'dest'")
source = invoker.source
dest = invoker.dest
action(target_name) {
if (defined(invoker.visibility)) {
visibility = invoker.visibility
}
deps = []
if (defined(invoker.deps)) {
deps += invoker.deps
}
depfile = "$target_gen_dir/$target_name.d"
stampfile = "$target_gen_dir/$target_name.stamp"
common_args = [
"--from",
rebase_path(source),
"--to",
rebase_path(dest),
"--depfile",
rebase_path(depfile),
"--stamp",
rebase_path(stampfile),
]
if (defined(invoker.exclude)) {
common_args += [
"--exclude",
invoker.exclude,
]
}
outputs = [ stampfile ]
script = "$_dart_root/tools/copy_tree.py"
args = common_args
}
}
# DEPRECATED: This can be removed after the uses in the flutter/engine tree
# are migrated to use copy_tree().
template("copy_trees") {
assert(defined(invoker.sources), "$target_name must define 'source'")
sources = invoker.sources
copy_tree_source_paths = []
foreach(copy_tree_spec, sources) {
copy_tree_source_paths += [
rebase_path(copy_tree_spec.source),
copy_tree_spec.ignore_patterns,
]
}
# A list of lists of input source files for copy_tree.
foreach(copy_tree_spec, sources) {
copy_tree(copy_tree_spec.target) {
visibility = copy_tree_spec.visibility
source = copy_tree_spec.source
dest = copy_tree_spec.dest
if (defined(copy_tree_spec.deps)) {
deps = copy_tree_spec.deps
}
if (copy_tree_spec.ignore_patterns != "{}") {
exclude = copy_tree_spec.ignore_patterns
}
}
}
}