Handle metadata walk_keys relative to the target directory
Don't process relative labels relative to root, process them relative
to the target directory.
To illustrate this, take the following example:
//x:x
//x:meta
//x/z:z
Where x is a target that depends on z, and meta is a generated_file
target that sets walk_keys to just "z", the collection would fail
because generated_file would try to resolve "z" (which is a relative
path) against the root (i.e. as //z:z). This patches changes the logic
to always resolve the walk_keys against the target current directory,
i.e. in case of //x:meta it'll be resolved against //x which is correct
since "z" is relative to that.
Bug: 117
Change-Id: I4da2a3d5e279a970794cdf163f596d8c9a107f4b
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/6380
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Brett Wilson <brettw@chromium.org>
diff --git a/tools/gn/target.cc b/tools/gn/target.cc
index db7a1be..bc87928 100644
--- a/tools/gn/target.cc
+++ b/tools/gn/target.cc
@@ -918,7 +918,7 @@
// Gather walk keys and find the appropriate target. Targets identified in
// the walk key set must be deps or data_deps of the declaring target.
const DepsIteratorRange& all_deps = GetDeps(Target::DEPS_ALL);
- const SourceDir current_dir("//");
+ const SourceDir& current_dir = label().dir();
for (const auto& next : next_walk_keys) {
DCHECK(next.type() == Value::STRING);
diff --git a/tools/gn/target_unittest.cc b/tools/gn/target_unittest.cc
index 24f4822..93fc6a4 100644
--- a/tools/gn/target_unittest.cc
+++ b/tools/gn/target_unittest.cc
@@ -1189,11 +1189,11 @@
Value walk_expected(nullptr, Value::LIST);
walk_expected.list_value().push_back(
- Value(nullptr, "//foo:two(//toolchain:default)"));
+ Value(nullptr, "two"));
one.metadata().contents().insert(
std::pair<std::string_view, Value>("walk", walk_expected));
- TestTarget two(setup, "//foo:two", Target::SOURCE_SET);
+ TestTarget two(setup, "//foo/two:two", Target::SOURCE_SET);
Value a_2_expected(nullptr, Value::LIST);
a_2_expected.list_value().push_back(Value(nullptr, "bar"));
two.metadata().contents().insert(
@@ -1205,7 +1205,7 @@
three.metadata().contents().insert(
std::pair<std::string_view, Value>("a", a_3_expected));
- one.public_deps().push_back(LabelTargetPair(&two));
+ one.private_deps().push_back(LabelTargetPair(&two));
one.public_deps().push_back(LabelTargetPair(&three));
std::vector<std::string> data_keys;