diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java | 12 | ||||
-rwxr-xr-x | src/test/shell/bazel/location_test.sh | 20 |
2 files changed, 26 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java b/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java index 882b93bae5..225b3e14b6 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java @@ -48,7 +48,7 @@ import java.util.TreeSet; * Note that //mypackage:myhelper should have just one output. */ public class LocationExpander { - + /** * List of options to tweak the LocationExpander. */ @@ -58,7 +58,7 @@ public class LocationExpander { /** Allow to take label from the data attribute */ ALLOW_DATA, } - + private static final int MAX_PATHS_SHOWN = 5; private static final String LOCATION = "$(location"; private final RuleContext ruleContext; @@ -105,7 +105,7 @@ public class LocationExpander { /** * Creates location expander helper bound to specific target. - * + * * @param ruleContext the BUILD rule's context * @param options the list of options, see {@link Options}. */ @@ -181,7 +181,7 @@ public class LocationExpander { message = String.format(" in %s expression", message); // (2) parse label - String labelText = value.substring(start + scannedLength, end); + String labelText = value.substring(start + scannedLength, end).trim(); Label label = parseLabel(labelText, message, reporter); if (label == null) { @@ -206,7 +206,7 @@ public class LocationExpander { restart = end + 1; } - + return result.toString(); } @@ -357,7 +357,7 @@ public class LocationExpander { } return values; } - + private static interface ErrorReporter { void report(RuleContext ctx, String error); } diff --git a/src/test/shell/bazel/location_test.sh b/src/test/shell/bazel/location_test.sh index 2435dcc4a1..801aa198eb 100755 --- a/src/test/shell/bazel/location_test.sh +++ b/src/test/shell/bazel/location_test.sh @@ -75,4 +75,24 @@ EOF assert_contains "hello" bazel-genfiles/bar/loc } +function test_location_trim() { + mkdir bar + cat > bar/BUILD <<EOF +genrule( + name = "baz-rule", + outs = ["baz"], + cmd = "echo helloworld > \"\$@\"", +) + +genrule( + name = "loc-rule", + srcs = [":baz-rule"], + outs = ["loc"], + cmd = "echo \$(location :baz-rule ) > \"\$@\"", +) +EOF + + bazel build //bar:loc || fail "Label was not trimmed before lookup" +} + run_suite "location tests" |