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"));
}
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"));
}
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);
}
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;
}
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);
}
Aggregations