use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class DependencyTest method withConfiguredAspects_BasicAccessors.
@Test
public void withConfiguredAspects_BasicAccessors() throws Exception {
update();
AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT);
AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT);
AspectCollection aspects = AspectCollection.createForTests(ImmutableSet.of(simpleAspect, attributeAspect));
ImmutableMap<AspectDescriptor, BuildConfiguration> twoAspectMap = ImmutableMap.of(simpleAspect, getTargetConfiguration(), attributeAspect, getHostConfiguration());
Dependency targetDep = Dependency.withConfiguredAspects(Label.parseAbsolute("//a"), getTargetConfiguration(), aspects, twoAspectMap);
assertThat(targetDep.getLabel()).isEqualTo(Label.parseAbsolute("//a"));
assertThat(targetDep.hasStaticConfiguration()).isTrue();
assertThat(targetDep.getConfiguration()).isEqualTo(getTargetConfiguration());
assertThat(targetDep.getAspects().getAllAspects()).containsExactlyElementsIn(ImmutableSet.of(simpleAspect, attributeAspect));
assertThat(targetDep.getAspectConfiguration(simpleAspect)).isEqualTo(getTargetConfiguration());
assertThat(targetDep.getAspectConfiguration(attributeAspect)).isEqualTo(getHostConfiguration());
try {
targetDep.getTransition();
fail("withConfiguredAspects-created Dependencies should throw ISE on getTransition()");
} catch (IllegalStateException ex) {
// good. all according to keikaku. (TL note: keikaku means plan)
}
}
use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class BuildViewTestCase method assertDirectPrerequisitesContain.
/**
* Asserts that a target's prerequisites contain the given dependency.
*/
// TODO(bazel-team): replace this method with assertThat(iterable).contains(target).
// That doesn't work now because dynamic configurations aren't yet applied to top-level targets.
// This means that getConfiguredTarget("//go:two") returns a different configuration than
// requesting "//go:two" as a dependency. So the configured targets aren't considered "equal".
// Once we apply dynamic configs to top-level targets this discrepancy will go away.
protected void assertDirectPrerequisitesContain(ConfiguredTarget target, ConfiguredTarget dep) throws Exception {
Iterable<ConfiguredTarget> prereqs = getDirectPrerequisites(target);
BuildConfiguration depConfig = dep.getConfiguration();
for (ConfiguredTarget contained : prereqs) {
if (contained.getLabel().equals(dep.getLabel())) {
BuildConfiguration containedConfig = contained.getConfiguration();
if (containedConfig == null && depConfig == null) {
return;
} else if (containedConfig != null && depConfig != null && containedConfig.cloneOptions().equals(depConfig.cloneOptions())) {
return;
}
}
}
fail("Cannot find " + target.toString() + " in " + prereqs.toString());
}
use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class ConfigurationsForTargetsWithDynamicConfigurationsTest method testConflictingAttributeAndRuleClassTransitions.
@Test
public void testConflictingAttributeAndRuleClassTransitions() throws Exception {
setRulesAvailableInTests(new TestAspects.BaseRule(), new TestAspects.AttributeTransitionRule(), new TestAspects.RuleClassTransitionRule());
scratch.file("a/BUILD", "attribute_transition(", " name='attribute',", " with_cpu_transition = ':rule_class',", ")", "rule_class_transition(name='rule_class')");
List<ConfiguredTarget> deps = getConfiguredDeps("//a:attribute", "with_cpu_transition");
BuildConfiguration ruleclass = Iterables.getOnlyElement(deps).getConfiguration();
assertThat(ruleclass.getCpu()).isEqualTo("SET BY SPLIT");
}
use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class ConfigurationsForTargetsWithDynamicConfigurationsTest method testRuleClassTransition.
@Test
public void testRuleClassTransition() throws Exception {
setRulesAvailableInTests(new TestAspects.BaseRule(), new TestAspects.AttributeTransitionRule(), new TestAspects.RuleClassTransitionRule());
scratch.file("a/BUILD", "attribute_transition(", " name='attribute',", " without_transition = ':rule_class',", ")", "rule_class_transition(name='rule_class')");
List<ConfiguredTarget> deps = getConfiguredDeps("//a:attribute", "without_transition");
BuildConfiguration ruleclass = Iterables.getOnlyElement(deps).getConfiguration();
assertThat(ruleclass.getCpu()).isEqualTo("SET BY PATCH");
}
use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class BuildViewTestCase method getImplicitOutputArtifact.
protected Artifact getImplicitOutputArtifact(ConfiguredTarget target, SafeImplicitOutputsFunction outputFunction) {
Rule associatedRule = target.getTarget().getAssociatedRule();
RepositoryName repository = associatedRule.getRepository();
BuildConfiguration configuration = target.getConfiguration();
Root root;
if (associatedRule.hasBinaryOutput()) {
root = configuration.getBinDirectory(repository);
} else {
root = configuration.getGenfilesDirectory(repository);
}
ArtifactOwner owner = new ConfiguredTargetKey(target.getTarget().getLabel(), target.getConfiguration());
RawAttributeMapper attr = RawAttributeMapper.of(associatedRule);
String path = Iterables.getOnlyElement(outputFunction.getImplicitOutputs(attr));
return view.getArtifactFactory().getDerivedArtifact(target.getTarget().getLabel().getPackageFragment().getRelative(path), root, owner);
}
Aggregations