Search in sources :

Example 6 with RawAttributeMapper

use of com.google.devtools.build.lib.packages.RawAttributeMapper in project bazel by bazelbuild.

the class RawAttributeMapperTest method testGetAttributeType.

@Override
@Test
public void testGetAttributeType() throws Exception {
    RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
    // not configurable
    assertEquals(BuildType.LABEL_LIST, rawMapper.getAttributeType("data"));
    // configurable
    assertEquals(BuildType.LABEL_LIST, rawMapper.getAttributeType("srcs"));
}
Also used : RawAttributeMapper(com.google.devtools.build.lib.packages.RawAttributeMapper) Test(org.junit.Test)

Example 7 with RawAttributeMapper

use of com.google.devtools.build.lib.packages.RawAttributeMapper in project bazel by bazelbuild.

the class RawAttributeMapperTest method testConfigurabilityCheck.

@Test
public void testConfigurabilityCheck() throws Exception {
    RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
    assertFalse(rawMapper.isConfigurable("data"));
    assertTrue(rawMapper.isConfigurable("srcs"));
}
Also used : RawAttributeMapper(com.google.devtools.build.lib.packages.RawAttributeMapper) Test(org.junit.Test)

Example 8 with RawAttributeMapper

use of com.google.devtools.build.lib.packages.RawAttributeMapper in project bazel by bazelbuild.

the class BuildView method getConfigurableAttributeKeysForTesting.

/**
   * Returns ConfigMatchingProvider instances corresponding to the configurable attribute keys
   * present in this rule's attributes.
   */
private ImmutableMap<Label, ConfigMatchingProvider> getConfigurableAttributeKeysForTesting(ExtendedEventHandler eventHandler, TargetAndConfiguration ctg) {
    if (!(ctg.getTarget() instanceof Rule)) {
        return ImmutableMap.of();
    }
    Rule rule = (Rule) ctg.getTarget();
    Map<Label, ConfigMatchingProvider> keys = new LinkedHashMap<>();
    RawAttributeMapper mapper = RawAttributeMapper.of(rule);
    for (Attribute attribute : rule.getAttributes()) {
        for (Label label : mapper.getConfigurabilityKeys(attribute.getName(), attribute.getType())) {
            if (BuildType.Selector.isReservedLabel(label)) {
                continue;
            }
            ConfiguredTarget ct = getConfiguredTargetForTesting(eventHandler, label, ctg.getConfiguration());
            keys.put(label, Preconditions.checkNotNull(ct.getProvider(ConfigMatchingProvider.class)));
        }
    }
    return ImmutableMap.copyOf(keys);
}
Also used : RawAttributeMapper(com.google.devtools.build.lib.packages.RawAttributeMapper) Attribute(com.google.devtools.build.lib.packages.Attribute) Label(com.google.devtools.build.lib.cmdline.Label) ConfigMatchingProvider(com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider) Rule(com.google.devtools.build.lib.packages.Rule) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with RawAttributeMapper

use of com.google.devtools.build.lib.packages.RawAttributeMapper in project bazel by bazelbuild.

the class CompileOneDependencyTransformer method transformCompileOneDependency.

private Target transformCompileOneDependency(ExtendedEventHandler eventHandler, Target target) throws TargetParsingException, InterruptedException {
    if (!(target instanceof FileTarget)) {
        throw new TargetParsingException("--compile_one_dependency target '" + target.getLabel() + "' must be a file");
    }
    Rule result = null;
    Iterable<Rule> orderedRuleList = getOrderedRuleList(target.getPackage());
    for (Rule rule : orderedRuleList) {
        Set<Label> labels = getInputLabels(rule);
        if (listContainsFile(eventHandler, labels, target.getLabel(), Sets.<Label>newHashSet())) {
            if (rule.getRuleClassObject().isPreferredDependency(target.getName())) {
                result = rule;
                break;
            }
            if (result == null) {
                result = rule;
            }
        }
    }
    if (result == null) {
        throw new TargetParsingException("Couldn't find dependency on target '" + target.getLabel() + "'");
    }
    // If the rule has source targets, return it.
    if (!RawAttributeMapper.of(result).getMergedValues("srcs", BuildType.LABEL_LIST).isEmpty()) {
        return result;
    }
    // Try to find a rule in the same package that has 'result' as a dependency.
    for (Rule rule : orderedRuleList) {
        RawAttributeMapper attributes = RawAttributeMapper.of(rule);
        // We don't know which path to follow for configurable attributes, so skip them.
        if (attributes.isConfigurable("deps") || attributes.isConfigurable("srcs")) {
            continue;
        }
        RuleClass ruleClass = rule.getRuleClassObject();
        if (ruleClass.hasAttr("deps", BuildType.LABEL_LIST) && ruleClass.hasAttr("srcs", BuildType.LABEL_LIST)) {
            for (Label dep : attributes.get("deps", BuildType.LABEL_LIST)) {
                if (dep.equals(result.getLabel())) {
                    if (!attributes.get("srcs", BuildType.LABEL_LIST).isEmpty()) {
                        return rule;
                    }
                }
            }
        }
    }
    return result;
}
Also used : RawAttributeMapper(com.google.devtools.build.lib.packages.RawAttributeMapper) FileTarget(com.google.devtools.build.lib.packages.FileTarget) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) Label(com.google.devtools.build.lib.cmdline.Label) Rule(com.google.devtools.build.lib.packages.Rule) RuleClass(com.google.devtools.build.lib.packages.RuleClass)

Example 10 with RawAttributeMapper

use of com.google.devtools.build.lib.packages.RawAttributeMapper in project bazel by bazelbuild.

the class JvmConfigurationLoader method selectRuntime.

private static Label selectRuntime(Rule javaRuntimeSuite, String cpu) throws InvalidConfigurationException {
    RawAttributeMapper suiteAttributes = RawAttributeMapper.of(javaRuntimeSuite);
    Map<String, Label> runtimes = suiteAttributes.get("runtimes", BuildType.LABEL_DICT_UNARY);
    if (runtimes.containsKey(cpu)) {
        return runtimes.get(cpu);
    }
    if (suiteAttributes.isAttributeValueExplicitlySpecified("default")) {
        return suiteAttributes.get("default", BuildType.LABEL);
    }
    throw new InvalidConfigurationException("No JVM target found under " + javaRuntimeSuite + " that would work for " + cpu);
}
Also used : RawAttributeMapper(com.google.devtools.build.lib.packages.RawAttributeMapper) Label(com.google.devtools.build.lib.cmdline.Label) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)

Aggregations

RawAttributeMapper (com.google.devtools.build.lib.packages.RawAttributeMapper)16 Label (com.google.devtools.build.lib.cmdline.Label)10 Rule (com.google.devtools.build.lib.packages.Rule)9 Test (org.junit.Test)7 Attribute (com.google.devtools.build.lib.packages.Attribute)4 ConfigMatchingProvider (com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider)3 LinkedHashMap (java.util.LinkedHashMap)3 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)2 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)2 InvalidConfigurationException (com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)2 FileTarget (com.google.devtools.build.lib.packages.FileTarget)2 Target (com.google.devtools.build.lib.packages.Target)2 SkyKey (com.google.devtools.build.skyframe.SkyKey)2 Nullable (javax.annotation.Nullable)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArtifactOwner (com.google.devtools.build.lib.actions.ArtifactOwner)1 Root (com.google.devtools.build.lib.actions.Root)1 Dependency (com.google.devtools.build.lib.analysis.Dependency)1 InconsistentAspectOrderException (com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException)1