aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
diff options
context:
space:
mode:
authorGravatar dannark <dannark@google.com>2018-06-21 11:55:44 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-21 11:57:27 -0700
commitf24479d495df540bae634b5ff2dde3177585c2a3 (patch)
treeab16e9bf0c46f1f2b1ad70d6502003de553abd81 /src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
parent9594d5e8dc465bb4526a2f15a4b547de7e1324a7 (diff)
Take into account repository mapping when processing labels inside BUILD files within external repositories.
For example: a/BUILD genrule( name = "a", srcs = ["@x//:x.txt"], outs = ["result.txt"], cmd = "echo hello > \$(location result.txt)" ) If the main workspace file references that repository with a rule: local_repository( name = "other_repo", path = "../a", repo_mapping = {"@x" : "@y"} ) Then when a/BUILD is evaluated, the string "@x//:x.txt" will be turned into a Label "@y//:x.txt" RELNOTES: None PiperOrigin-RevId: 201562148
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages/RuleClass.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/RuleClass.java37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
index fba4c92a65..15349b10a3 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
@@ -36,11 +36,13 @@ import com.google.devtools.build.lib.analysis.config.transitions.SplitTransition
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
+import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.events.NullEventHandler;
import com.google.devtools.build.lib.packages.Attribute.SkylarkComputedDefaultTemplate;
import com.google.devtools.build.lib.packages.Attribute.SkylarkComputedDefaultTemplate.CannotPrecomputeDefaultsException;
+import com.google.devtools.build.lib.packages.BuildType.LabelConversionContext;
import com.google.devtools.build.lib.packages.BuildType.SelectorList;
import com.google.devtools.build.lib.packages.ConfigurationFragmentPolicy.MissingFragmentPolicy;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
@@ -1766,7 +1768,8 @@ public class RuleClass {
EventHandler eventHandler)
throws InterruptedException, CannotPrecomputeDefaultsException {
BitSet definedAttrIndices =
- populateDefinedRuleAttributeValues(rule, attributeValues, eventHandler);
+ populateDefinedRuleAttributeValues(
+ rule, pkgBuilder.getRepositoryMapping(), attributeValues, eventHandler);
populateDefaultRuleAttributeValues(rule, pkgBuilder, definedAttrIndices, eventHandler);
// Now that all attributes are bound to values, collect and store configurable attribute keys.
populateConfigDependenciesAttribute(rule);
@@ -1779,12 +1782,15 @@ public class RuleClass {
* <p>Handles the special cases of the attribute named {@code "name"} and attributes with value
* {@link Runtime#NONE}.
*
- * <p>Returns a bitset {@code b} where {@code b.get(i)} is {@code true} if this method set a
- * value for the attribute with index {@code i} in this {@link RuleClass}. Errors are reported
- * on {@code eventHandler}.
+ * <p>Returns a bitset {@code b} where {@code b.get(i)} is {@code true} if this method set a value
+ * for the attribute with index {@code i} in this {@link RuleClass}. Errors are reported on {@code
+ * eventHandler}.
*/
private <T> BitSet populateDefinedRuleAttributeValues(
- Rule rule, AttributeValues<T> attributeValues, EventHandler eventHandler) {
+ Rule rule,
+ ImmutableMap<RepositoryName, RepositoryName> repositoryMapping,
+ AttributeValues<T> attributeValues,
+ EventHandler eventHandler) {
BitSet definedAttrIndices = new BitSet();
for (T attributeAccessor : attributeValues.getAttributeAccessors()) {
String attributeName = attributeValues.getName(attributeAccessor);
@@ -1809,7 +1815,8 @@ public class RuleClass {
Object nativeAttributeValue;
if (attributeValues.valuesAreBuildLanguageTyped()) {
try {
- nativeAttributeValue = convertFromBuildLangType(rule, attr, attributeValue);
+ nativeAttributeValue =
+ convertFromBuildLangType(rule, attr, attributeValue, repositoryMapping);
} catch (ConversionException e) {
rule.reportError(String.format("%s: %s", rule.getLabel(), e.getMessage()), eventHandler);
continue;
@@ -2105,13 +2112,19 @@ public class RuleClass {
* <p>Throws {@link ConversionException} if the conversion fails, or if {@code buildLangValue} is
* a selector expression but {@code attr.isConfigurable()} is {@code false}.
*/
- private static Object convertFromBuildLangType(Rule rule, Attribute attr, Object buildLangValue)
+ private static Object convertFromBuildLangType(
+ Rule rule,
+ Attribute attr,
+ Object buildLangValue,
+ ImmutableMap<RepositoryName, RepositoryName> repositoryMapping)
throws ConversionException {
- Object converted = BuildType.selectableConvert(
- attr.getType(),
- buildLangValue,
- new AttributeConversionContext(attr.getName(), rule.getRuleClass()),
- rule.getLabel());
+ LabelConversionContext context = new LabelConversionContext(rule.getLabel(), repositoryMapping);
+ Object converted =
+ BuildType.selectableConvert(
+ attr.getType(),
+ buildLangValue,
+ new AttributeConversionContext(attr.getName(), rule.getRuleClass()),
+ context);
if ((converted instanceof SelectorList<?>) && !attr.isConfigurable()) {
throw new ConversionException(