diff options
author | 2018-06-21 17:46:06 -0700 | |
---|---|---|
committer | 2018-06-21 17:48:01 -0700 | |
commit | a8d7357b7dc66e0531c298e4d369e6342fcf94b7 (patch) | |
tree | a2ed8c5ee313d2113ac562a1ed57b5580683b108 /src/main/java | |
parent | db461d0e8a15aff0c4af219fd4a7a5b668ab1289 (diff) |
Audit usages of Label.getRelative and update to Label.getRelativeWithRemapping
RELNOTES: None
PiperOrigin-RevId: 201617188
Diffstat (limited to 'src/main/java')
7 files changed, 31 insertions, 14 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LabelExpander.java b/src/main/java/com/google/devtools/build/lib/analysis/LabelExpander.java index bac4c0a52b..c741275dc3 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/LabelExpander.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/LabelExpander.java @@ -17,6 +17,7 @@ package com.google.devtools.build.lib.analysis; import com.google.common.base.CharMatcher; import com.google.common.base.Preconditions; import com.google.common.base.Strings; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.cmdline.Label; @@ -153,7 +154,7 @@ public final class LabelExpander { */ private static Label resolveLabelText(String labelText, Label labelResolver) { try { - return labelResolver.getRelative(labelText); + return labelResolver.getRelativeWithRemapping(labelText, ImmutableMap.of()); } catch (LabelSyntaxException e) { // It's a heuristic, so quietly ignore "errors". Because Label.getRelative never // returns null, we can use null to indicate an error. diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java index 249c6b6ab2..ddc6ab5689 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java @@ -670,7 +670,11 @@ public class SkylarkRuleClassFunctions implements SkylarkRuleFunctionsApi<Artifa try { if (parentLabel != null) { LabelValidator.parseAbsoluteLabel(labelString); - labelString = parentLabel.getRelative(labelString).getUnambiguousCanonicalForm(); + // TODO(dannark): pass the environment here + labelString = + parentLabel + .getRelativeWithRemapping(labelString, ImmutableMap.of()) + .getUnambiguousCanonicalForm(); } return labelCache.get(labelString); } catch (LabelValidator.BadLabelException | LabelSyntaxException | ExecutionException e) { diff --git a/src/main/java/com/google/devtools/build/lib/packages/BuildType.java b/src/main/java/com/google/devtools/build/lib/packages/BuildType.java index d7811acc32..ecc397bd98 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/BuildType.java +++ b/src/main/java/com/google/devtools/build/lib/packages/BuildType.java @@ -268,9 +268,10 @@ public final class BuildType { // TODO(b/110101445): check if context is ever actually null if (context == null) { return Label.parseAbsolute((String) x, false); - // TODO(b/110308446): remove instances of context being a Label + // TODO(b/110308446): remove instances of context being a Label } else if (context instanceof Label) { - return ((Label) context).getRelative(STRING.convert(x, what, context)); + return ((Label) context) + .getRelativeWithRemapping(STRING.convert(x, what, context), ImmutableMap.of()); } else if (context instanceof LabelConversionContext) { LabelConversionContext labelConversionContext = (LabelConversionContext) context; return labelConversionContext diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java index 8ff93ddec6..c1191850f8 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java @@ -299,7 +299,11 @@ public class CppHelper { private static boolean expandLabel( RuleContext ruleContext, List<String> linkopts, String labelName) { try { - Label label = ruleContext.getLabel().getRelative(labelName); + Label label = + ruleContext + .getLabel() + .getRelativeWithRemapping( + labelName, ruleContext.getRule().getPackage().getRepositoryMapping()); for (String prereqKind : LINKOPTS_PREREQUISITE_LABEL_KINDS) { for (TransitiveInfoCollection target : ruleContext .getPrerequisitesIf(prereqKind, Mode.TARGET, FileProvider.class)) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java index ac7a1f6e31..33a3112b84 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java @@ -104,7 +104,8 @@ public class CppOptions extends FragmentOptions { throw new OptionsParsingException("Not a label"); } try { - return Label.parseAbsolute(input).getRelative(LIBC_RELATIVE_LABEL); + return Label.parseAbsolute(input) + .getRelativeWithRemapping(LIBC_RELATIVE_LABEL, ImmutableMap.of()); } catch (LabelSyntaxException e) { throw new OptionsParsingException(e.getMessage()); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java index 7849ea52a6..1396779f83 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java @@ -199,14 +199,16 @@ public final class CppToolchainInfo { crosstoolInfo.getLdEmbedFlags(), crosstoolInfo.getObjcopyEmbedFlags(), toolchainLabel, - toolchainLabel.getRelative( + toolchainLabel.getRelativeWithRemapping( !crosstoolInfo.getStaticRuntimesFilegroup().isEmpty() ? crosstoolInfo.getStaticRuntimesFilegroup() - : "static-runtime-libs-" + crosstoolInfo.getTargetCpu()), - toolchainLabel.getRelative( + : "static-runtime-libs-" + crosstoolInfo.getTargetCpu(), + ImmutableMap.of()), + toolchainLabel.getRelativeWithRemapping( !crosstoolInfo.getDynamicRuntimesFilegroup().isEmpty() ? crosstoolInfo.getDynamicRuntimesFilegroup() - : "dynamic-runtime-libs-" + crosstoolInfo.getTargetCpu()), + : "dynamic-runtime-libs-" + crosstoolInfo.getTargetCpu(), + ImmutableMap.of()), "_solib_" + crosstoolInfo.getTargetCpu(), crosstoolInfo.getAbiVersion(), crosstoolInfo.getTargetSystemName(), @@ -224,8 +226,8 @@ public final class CppToolchainInfo { crosstoolInfo.supportsGoldLinker(), crosstoolInfo.needsPic()); } catch (LabelSyntaxException e) { - // All of the above label.getRelative() calls are valid labels, and the crosstool_top - // was already checked earlier in the process. + // All of the above label.getRelativeWithRemapping() calls are valid labels, and the + // crosstool_top was already checked earlier in the process. throw new AssertionError(e); } } diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkImports.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkImports.java index 6cedeed40a..36c5ae4166 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkImports.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkImports.java @@ -142,7 +142,9 @@ public class SkylarkImports { PathFragment.create(containingFileLabel.getName()).getParentDirectory(); String targetNameForImport = containingDirInPkg.getRelative(importFile).toString(); try { - return containingFileLabel.getRelative(targetNameForImport); + // This is for imports relative to the current repository, so repositoryMapping can be + // empty + return containingFileLabel.getRelativeWithRemapping(targetNameForImport, ImmutableMap.of()); } catch (LabelSyntaxException e) { // Shouldn't happen because the parent label is assumed to be valid and the target string is // validated on construction. @@ -198,7 +200,9 @@ public class SkylarkImports { // Unlike a relative path import, the import target is relative to the containing package, // not the containing directory within the package. try { - return containingFileLabel.getRelative(importTarget); + // This is for imports relative to the current repository, so repositoryMapping can be + // empty + return containingFileLabel.getRelativeWithRemapping(importTarget, ImmutableMap.of()); } catch (LabelSyntaxException e) { // shouldn't happen because the parent label is assumed validated and the target string is // validated on construction |