Search in sources :

Example 46 with BuildConfiguration

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)
    }
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) Test(org.junit.Test)

Example 47 with BuildConfiguration

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());
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) RuleConfiguredTarget(com.google.devtools.build.lib.analysis.RuleConfiguredTarget) FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget)

Example 48 with BuildConfiguration

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");
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) TestAspects(com.google.devtools.build.lib.analysis.util.TestAspects) Test(org.junit.Test)

Example 49 with BuildConfiguration

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");
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) TestAspects(com.google.devtools.build.lib.analysis.util.TestAspects) Test(org.junit.Test)

Example 50 with BuildConfiguration

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);
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) RawAttributeMapper(com.google.devtools.build.lib.packages.RawAttributeMapper) ArtifactOwner(com.google.devtools.build.lib.actions.ArtifactOwner) Root(com.google.devtools.build.lib.actions.Root) RepositoryName(com.google.devtools.build.lib.cmdline.RepositoryName) Rule(com.google.devtools.build.lib.packages.Rule) ConfiguredTargetKey(com.google.devtools.build.lib.skyframe.ConfiguredTargetKey)

Aggregations

BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)51 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)13 Label (com.google.devtools.build.lib.cmdline.Label)12 Artifact (com.google.devtools.build.lib.actions.Artifact)11 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 Test (org.junit.Test)8 Attribute (com.google.devtools.build.lib.packages.Attribute)7 BuildOptions (com.google.devtools.build.lib.analysis.config.BuildOptions)6 InvalidConfigurationException (com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)6 Rule (com.google.devtools.build.lib.packages.Rule)6 Target (com.google.devtools.build.lib.packages.Target)6 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)6 SkyKey (com.google.devtools.build.skyframe.SkyKey)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Nullable (javax.annotation.Nullable)6 Root (com.google.devtools.build.lib.actions.Root)5 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)5 HashMap (java.util.HashMap)5