diff options
author | 2015-09-18 11:40:12 +0000 | |
---|---|---|
committer | 2015-09-21 08:56:51 +0000 | |
commit | ffa73addaf80ab7a9cf9f98e5d4414b152ae6cb6 (patch) | |
tree | f498621bb8634d934815dbaddf90400eda0ce28d /src/test/java/com/google/devtools | |
parent | 29ad862a5bd45d2fdbb921f36bbb95816cf47acc (diff) |
Separate build-specific types and types inherent to Skylark.
--
MOS_MIGRATED_REVID=103374106
Diffstat (limited to 'src/test/java/com/google/devtools')
17 files changed, 473 insertions, 410 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AspectDefinitionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AspectDefinitionTest.java index 461738eb7f..da5614c671 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/AspectDefinitionTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/AspectDefinitionTest.java @@ -18,7 +18,7 @@ import static org.junit.Assert.fail; import com.google.devtools.build.lib.packages.AspectDefinition; import com.google.devtools.build.lib.packages.AspectParameters; -import com.google.devtools.build.lib.packages.Type; +import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.syntax.Label; import org.junit.Test; @@ -60,7 +60,7 @@ public class AspectDefinitionTest { @Test public void testSimpleAspect() throws Exception { new AspectDefinition.Builder("simple") - .add(attr("$runtime", Type.LABEL).value(Label.parseAbsoluteUnchecked("//run:time"))) + .add(attr("$runtime", BuildType.LABEL).value(Label.parseAbsoluteUnchecked("//run:time"))) .attributeAspect("deps", TestAspectFactory.class) .build(); } @@ -69,7 +69,7 @@ public class AspectDefinitionTest { public void testAspectWithUserVisibleAttribute() throws Exception { try { new AspectDefinition.Builder("user_visible_attribute") - .add(attr("invalid", Type.LABEL).value(Label.parseAbsoluteUnchecked("//run:time"))) + .add(attr("invalid", BuildType.LABEL).value(Label.parseAbsoluteUnchecked("//run:time"))) .attributeAspect("deps", TestAspectFactory.class) .build(); fail(); // expected IllegalStateException diff --git a/src/test/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapperTest.java index 3a854c5f42..984a4b5bb3 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapperTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapperTest.java @@ -20,8 +20,9 @@ import com.google.devtools.build.lib.analysis.config.CompilationMode; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; import com.google.devtools.build.lib.packages.Attribute; import com.google.devtools.build.lib.packages.AttributeMap; -import com.google.devtools.build.lib.packages.Type; +import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.syntax.Label; +import com.google.devtools.build.lib.syntax.Type; import java.util.ArrayList; import java.util.List; @@ -69,7 +70,7 @@ public class ConfiguredAttributeMapperTest extends BuildViewTestCase { " cmd = select({", " '//conditions:a': 'a command',", " '//conditions:b': 'b command',", - " '" + Type.Selector.DEFAULT_CONDITION_KEY + "': 'default command',", + " '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': 'default command',", " }))"); useConfiguration("-c", "opt"); @@ -94,7 +95,7 @@ public class ConfiguredAttributeMapperTest extends BuildViewTestCase { " deps = select({", " '//conditions:a': [':adep'],", " '//conditions:b': [':bdep'],", - " '" + Type.Selector.DEFAULT_CONDITION_KEY + "': [':defaultdep'],", + " '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': [':defaultdep'],", " }))", "sh_library(", " name = 'adep',", @@ -150,7 +151,7 @@ public class ConfiguredAttributeMapperTest extends BuildViewTestCase { " tools = select({", " '//conditions:a': [':adep'],", " '//conditions:b': [':bdep'],", - " '" + Type.Selector.DEFAULT_CONDITION_KEY + "': [':defaultdep'],", + " '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': [':defaultdep'],", " }))", "sh_binary(", " name = 'adep',", @@ -166,7 +167,7 @@ public class ConfiguredAttributeMapperTest extends BuildViewTestCase { // Target configuration is in dbg mode, so we should match //conditions:b: assertSameContents( ImmutableList.of(Label.parseAbsolute("//a:bdep")), - getMapper("//a:gen").get("tools", Type.LABEL_LIST)); + getMapper("//a:gen").get("tools", BuildType.LABEL_LIST)); // Verify the "tools" dep uses a different configuration that's not also in "dbg": assertEquals(Attribute.ConfigurationTransition.HOST, @@ -191,6 +192,6 @@ public class ConfiguredAttributeMapperTest extends BuildViewTestCase { useConfiguration("--define", "foo=a", "--define", "bar=d"); assertSameContents( ImmutableList.of(Label.parseAbsolute("//hello:a.in"), Label.parseAbsolute("//hello:d.in")), - getMapper("//hello:gen").get("srcs", Type.LABEL_LIST)); + getMapper("//hello:gen").get("srcs", BuildType.LABEL_LIST)); } } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/config/StampTest.java b/src/test/java/com/google/devtools/build/lib/analysis/config/StampTest.java index 8407ec938a..bc04d55eb6 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/config/StampTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/config/StampTest.java @@ -14,11 +14,11 @@ package com.google.devtools.build.lib.analysis.config; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; +import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleFactory; import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.packages.TriState; -import com.google.devtools.build.lib.packages.Type; import com.google.devtools.build.lib.testutil.TestRuleClassProvider; /** @@ -32,7 +32,7 @@ public class StampTest extends BuildViewTestCase { RuleFactory ruleFactory = new RuleFactory(TestRuleClassProvider.getRuleClassProvider()); for (String name : ruleFactory.getRuleClassNames()) { RuleClass ruleClass = ruleFactory.getRuleClass(name); - if (TargetUtils.isTestRuleName(name) && ruleClass.hasAttr("stamp", Type.TRISTATE)) { + if (TargetUtils.isTestRuleName(name) && ruleClass.hasAttr("stamp", BuildType.TRISTATE)) { assertEquals(TriState.NO, ruleClass.getAttributeByName("stamp").getDefaultValue(null)); } } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/constraints/ConstraintsTest.java b/src/test/java/com/google/devtools/build/lib/analysis/constraints/ConstraintsTest.java index 9ccd2a22ed..e2159efc17 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/constraints/ConstraintsTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/constraints/ConstraintsTest.java @@ -21,10 +21,10 @@ import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.packages.Attribute; +import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleClass.Builder; -import com.google.devtools.build.lib.packages.Type; import com.google.devtools.build.lib.syntax.Label; import com.google.devtools.build.lib.testutil.TestRuleClassProvider; import com.google.devtools.build.lib.testutil.UnknownRuleConfiguredTarget; @@ -102,9 +102,9 @@ public class ConstraintsTest extends AbstractConstraintsTest { public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { return builder .setUndocumented() - .add(Attribute.attr("$implicit", Type.LABEL) + .add(Attribute.attr("$implicit", BuildType.LABEL) .value(Label.parseAbsoluteUnchecked("//helpers:implicit"))) - .add(Attribute.attr(":latebound", Type.LABEL) + .add(Attribute.attr(":latebound", BuildType.LABEL) .value( new Attribute.LateBoundLabel<BuildConfiguration>() { @Override @@ -112,7 +112,7 @@ public class ConstraintsTest extends AbstractConstraintsTest { return Label.parseAbsoluteUnchecked("//helpers:latebound"); } })) - .add(Attribute.attr("normal", Type.LABEL) + .add(Attribute.attr("normal", BuildType.LABEL) .allowedFileTypes(FileTypeSet.NO_FILE) .value(Label.parseAbsoluteUnchecked("//helpers:default"))) .build(); diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/AbstractAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/AbstractAttributeMapperTest.java index f15d1a6a6c..c32eb16614 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/select/AbstractAttributeMapperTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/select/AbstractAttributeMapperTest.java @@ -22,12 +22,13 @@ import com.google.devtools.build.lib.packages.AbstractAttributeMapper; import com.google.devtools.build.lib.packages.Attribute; import com.google.devtools.build.lib.packages.AttributeContainer; import com.google.devtools.build.lib.packages.AttributeMap; +import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.Package; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.RuleClass; -import com.google.devtools.build.lib.packages.Type; import com.google.devtools.build.lib.packages.util.PackageFactoryApparatus; import com.google.devtools.build.lib.syntax.Label; +import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.testutil.FoundationTestCase; import com.google.devtools.build.lib.testutil.MoreAsserts; import com.google.devtools.build.lib.testutil.Scratch; @@ -84,7 +85,7 @@ public class AbstractAttributeMapperTest extends FoundationTestCase { public void testAttributeTypeChecking() throws Exception { // Good typing: - mapper.get("srcs", Type.LABEL_LIST); + mapper.get("srcs", BuildType.LABEL_LIST); // Bad typing: try { @@ -104,7 +105,7 @@ public class AbstractAttributeMapperTest extends FoundationTestCase { } public void testGetAttributeType() throws Exception { - assertEquals(Type.LABEL_LIST, mapper.getAttributeType("srcs")); + assertEquals(BuildType.LABEL_LIST, mapper.getAttributeType("srcs")); assertNull(mapper.getAttributeType("nonsense")); } @@ -138,9 +139,9 @@ public class AbstractAttributeMapperTest extends FoundationTestCase { public void testComputedDefault() throws Exception { // Should return a valid ComputedDefault instance since this is a computed default: - assertThat(mapper.getComputedDefault("$stl", Type.LABEL)) + assertThat(mapper.getComputedDefault("$stl", BuildType.LABEL)) .isInstanceOf(Attribute.ComputedDefault.class); // Should return null since this *isn't* a computed default: - assertNull(mapper.getComputedDefault("srcs", Type.LABEL_LIST)); + assertNull(mapper.getComputedDefault("srcs", BuildType.LABEL_LIST)); } } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java index 230e55e216..1ab8484a0c 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java @@ -19,9 +19,10 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.packages.AggregatingAttributeMapper; import com.google.devtools.build.lib.packages.Attribute; +import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.Rule; -import com.google.devtools.build.lib.packages.Type; import com.google.devtools.build.lib.syntax.Label; +import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.testutil.TestConstants; /** @@ -46,7 +47,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest " srcs = ['a.sh'])"); assertSameContents( ImmutableList.of(ImmutableList.of(Label.create("a", "a.sh"))), - AggregatingAttributeMapper.of(rule).visitAttribute("srcs", Type.LABEL_LIST)); + AggregatingAttributeMapper.of(rule).visitAttribute("srcs", BuildType.LABEL_LIST)); } /** @@ -59,14 +60,14 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest " srcs = select({", " '//conditions:a': ['a.sh'],", " '//conditions:b': ['b.sh'],", - " '" + Type.Selector.DEFAULT_CONDITION_KEY + "': ['default.sh'],", + " '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': ['default.sh'],", " }))"); assertSameContents( ImmutableList.of( ImmutableList.of(Label.create("a", "a.sh")), ImmutableList.of(Label.create("a", "b.sh")), ImmutableList.of(Label.create("a", "default.sh"))), - AggregatingAttributeMapper.of(rule).visitAttribute("srcs", Type.LABEL_LIST)); + AggregatingAttributeMapper.of(rule).visitAttribute("srcs", BuildType.LABEL_LIST)); } public void testGetPossibleValuesWithConcatenatedSelects() throws Exception { @@ -85,7 +86,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest ImmutableList.of(Label.create("a", "a1.sh"), Label.create("a", "b2.sh")), ImmutableList.of(Label.create("a", "b1.sh"), Label.create("a", "a2.sh")), ImmutableList.of(Label.create("a", "b1.sh"), Label.create("a", "b2.sh"))), - AggregatingAttributeMapper.of(rule).visitAttribute("srcs", Type.LABEL_LIST)); + AggregatingAttributeMapper.of(rule).visitAttribute("srcs", BuildType.LABEL_LIST)); } /** @@ -117,7 +118,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest " srcs = select({", " '//conditions:a': ['a.sh'],", " '//conditions:b': ['b.sh'],", - " '" + Type.Selector.DEFAULT_CONDITION_KEY + "': ['default.sh'],", + " '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': ['default.sh'],", " }))"); VisitationRecorder recorder = new VisitationRecorder(); @@ -141,7 +142,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest " select({", " '//conditions:c': ['c.cc'],", " '//conditions:d': ['d.cc'],", - " '" + Type.Selector.DEFAULT_CONDITION_KEY + "': ['default.cc'],", + " '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': ['default.cc'],", " }))"); ImmutableList<Label> valueLabels = ImmutableList.of( diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/NonconfigurableAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/NonconfigurableAttributeMapperTest.java index 01ef88d58e..4b35a396fc 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/select/NonconfigurableAttributeMapperTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/select/NonconfigurableAttributeMapperTest.java @@ -16,7 +16,7 @@ package com.google.devtools.build.lib.analysis.select; import static com.google.common.truth.Truth.assertThat; import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper; -import com.google.devtools.build.lib.packages.Type; +import com.google.devtools.build.lib.syntax.Type; /** * Unit tests for {@link NonconfigurableAttributeMapper}. diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java index b1c02d4281..9e5efb7e00 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java @@ -19,9 +19,9 @@ import static com.google.devtools.build.lib.testutil.MoreAsserts.assertSameConte import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.packages.Attribute; import com.google.devtools.build.lib.packages.AttributeMap; +import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.RawAttributeMapper; import com.google.devtools.build.lib.packages.Rule; -import com.google.devtools.build.lib.packages.Type; import com.google.devtools.build.lib.syntax.Label; import java.util.List; @@ -45,21 +45,21 @@ public class RawAttributeMapperTest extends AbstractAttributeMapperTest { " srcs = select({", " '//conditions:a': ['a.sh'],", " '//conditions:b': ['b.sh'],", - " '" + Type.Selector.DEFAULT_CONDITION_KEY + "': ['default.sh'],", + " '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': ['default.sh'],", " }),", " data = [ ':data_a', ':data_b' ])"); } public void testGetAttribute() throws Exception { RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule()); - List<Label> value = rawMapper.get("data", Type.LABEL_LIST); + List<Label> value = rawMapper.get("data", BuildType.LABEL_LIST); assertNotNull(value); assertThat(value).containsExactly(Label.create("x", "data_a"), Label.create("x", "data_b")); // Configurable attribute: trying to directly access from a RawAttributeMapper throws a // type mismatch exception. try { - rawMapper.get("srcs", Type.LABEL_LIST); + rawMapper.get("srcs", BuildType.LABEL_LIST); fail("Expected srcs lookup to fail since the returned type is a SelectorList and not a list"); } catch (IllegalArgumentException e) { assertThat(e.getCause().getMessage()) @@ -70,14 +70,14 @@ public class RawAttributeMapperTest extends AbstractAttributeMapperTest { @Override public void testGetAttributeType() throws Exception { RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule()); - assertEquals(Type.LABEL_LIST, rawMapper.getAttributeType("data")); // not configurable - assertEquals(Type.LABEL_LIST, rawMapper.getAttributeType("srcs")); // configurable + assertEquals(BuildType.LABEL_LIST, rawMapper.getAttributeType("data")); // not configurable + assertEquals(BuildType.LABEL_LIST, rawMapper.getAttributeType("srcs")); // configurable } public void testConfigurabilityCheck() throws Exception { RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule()); - assertFalse(rawMapper.isConfigurable("data", Type.LABEL_LIST)); - assertTrue(rawMapper.isConfigurable("srcs", Type.LABEL_LIST)); + assertFalse(rawMapper.isConfigurable("data", BuildType.LABEL_LIST)); + assertTrue(rawMapper.isConfigurable("srcs", BuildType.LABEL_LIST)); } /** @@ -106,8 +106,8 @@ public class RawAttributeMapperTest extends AbstractAttributeMapperTest { Label.parseAbsolute("//conditions:a"), Label.parseAbsolute("//conditions:b"), Label.parseAbsolute("//conditions:default")), - rawMapper.getConfigurabilityKeys("srcs", Type.LABEL_LIST)); - assertThat(rawMapper.getConfigurabilityKeys("data", Type.LABEL_LIST)).isEmpty(); + rawMapper.getConfigurabilityKeys("srcs", BuildType.LABEL_LIST)); + assertThat(rawMapper.getConfigurabilityKeys("data", BuildType.LABEL_LIST)).isEmpty(); } public void testGetMergedValues() throws Exception { @@ -119,7 +119,7 @@ public class RawAttributeMapperTest extends AbstractAttributeMapperTest { " '//conditions:b': ['b.sh', 'c.sh'],", " }))"); RawAttributeMapper rawMapper = RawAttributeMapper.of(rule); - assertThat(rawMapper.getMergedValues("srcs", Type.LABEL_LIST)).containsExactly( + assertThat(rawMapper.getMergedValues("srcs", BuildType.LABEL_LIST)).containsExactly( Label.parseAbsolute("//x:a.sh"), Label.parseAbsolute("//x:b.sh"), Label.parseAbsolute("//x:c.sh")) @@ -138,7 +138,7 @@ public class RawAttributeMapperTest extends AbstractAttributeMapperTest { " '//conditions:b2': ['b2.sh']})", " )"); RawAttributeMapper rawMapper = RawAttributeMapper.of(rule); - assertThat(rawMapper.getMergedValues("srcs", Type.LABEL_LIST)).containsExactly( + assertThat(rawMapper.getMergedValues("srcs", BuildType.LABEL_LIST)).containsExactly( Label.parseAbsolute("//x:a1.sh"), Label.parseAbsolute("//x:b1.sh"), Label.parseAbsolute("//x:another_b1.sh"), diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/TestAspects.java b/src/test/java/com/google/devtools/build/lib/analysis/util/TestAspects.java index c0ee9111a0..91140b4222 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/TestAspects.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/TestAspects.java @@ -15,12 +15,12 @@ package com.google.devtools.build.lib.analysis.util; import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition.HOST; import static com.google.devtools.build.lib.packages.Attribute.attr; -import static com.google.devtools.build.lib.packages.Type.BOOLEAN; -import static com.google.devtools.build.lib.packages.Type.LABEL; -import static com.google.devtools.build.lib.packages.Type.LABEL_LIST; -import static com.google.devtools.build.lib.packages.Type.NODEP_LABEL_LIST; -import static com.google.devtools.build.lib.packages.Type.STRING; -import static com.google.devtools.build.lib.packages.Type.STRING_LIST; +import static com.google.devtools.build.lib.packages.BuildType.LABEL; +import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; +import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL_LIST; +import static com.google.devtools.build.lib.syntax.Type.BOOLEAN; +import static com.google.devtools.build.lib.syntax.Type.STRING; +import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; import com.google.common.base.Function; import com.google.common.collect.Iterables; diff --git a/src/test/java/com/google/devtools/build/lib/packages/AttributeTest.java b/src/test/java/com/google/devtools/build/lib/packages/AttributeTest.java index c15e9ac5fe..5682bc6e3b 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/AttributeTest.java +++ b/src/test/java/com/google/devtools/build/lib/packages/AttributeTest.java @@ -16,11 +16,11 @@ package com.google.devtools.build.lib.packages; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition.HOST; import static com.google.devtools.build.lib.packages.Attribute.attr; -import static com.google.devtools.build.lib.packages.Type.INTEGER; -import static com.google.devtools.build.lib.packages.Type.LABEL; -import static com.google.devtools.build.lib.packages.Type.LABEL_LIST; -import static com.google.devtools.build.lib.packages.Type.STRING; -import static com.google.devtools.build.lib.packages.Type.STRING_LIST; +import static com.google.devtools.build.lib.packages.BuildType.LABEL; +import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; +import static com.google.devtools.build.lib.syntax.Type.INTEGER; +import static com.google.devtools.build.lib.syntax.Type.STRING; +import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -28,6 +28,7 @@ import static org.junit.Assert.fail; import com.google.common.base.Predicates; import com.google.devtools.build.lib.syntax.Label; +import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.util.FileType; import com.google.devtools.build.lib.util.FileTypeSet; @@ -77,9 +78,9 @@ public class AttributeTest { @Test public void testNonEmpty() throws Exception { - Attribute attr = attr("foo", Type.LABEL_LIST).nonEmpty().legacyAllowAnyFileType().build(); + Attribute attr = attr("foo", BuildType.LABEL_LIST).nonEmpty().legacyAllowAnyFileType().build(); assertEquals("foo", attr.getName()); - assertEquals(Type.LABEL_LIST, attr.getType()); + assertEquals(BuildType.LABEL_LIST, attr.getType()); assertTrue(attr.isNonEmpty()); } @@ -240,9 +241,9 @@ public class AttributeTest { */ @Test public void testConfigurability() { - assertTrue(attr("foo_configurable", Type.LABEL_LIST).legacyAllowAnyFileType().build() + assertTrue(attr("foo_configurable", BuildType.LABEL_LIST).legacyAllowAnyFileType().build() .isConfigurable()); - assertFalse(attr("foo_nonconfigurable", Type.LABEL_LIST).legacyAllowAnyFileType() + assertFalse(attr("foo_nonconfigurable", BuildType.LABEL_LIST).legacyAllowAnyFileType() .nonconfigurable("test").build().isConfigurable()); } } diff --git a/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java b/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java new file mode 100644 index 0000000000..e46c2586d1 --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java @@ -0,0 +1,351 @@ +// Copyright 2006-2015 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.packages; + +import static com.google.common.truth.Truth.assertThat; +import static com.google.devtools.build.lib.testutil.MoreAsserts.assertSameContents; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.devtools.build.lib.cmdline.LabelSyntaxException; +import com.google.devtools.build.lib.packages.BuildType.Selector; +import com.google.devtools.build.lib.syntax.EvalUtils; +import com.google.devtools.build.lib.syntax.Label; +import com.google.devtools.build.lib.syntax.Printer; +import com.google.devtools.build.lib.syntax.SelectorList; +import com.google.devtools.build.lib.syntax.SelectorValue; +import com.google.devtools.build.lib.syntax.Type.ConversionException; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * Test of type-conversions for build-specific types. + */ +@RunWith(JUnit4.class) +public class BuildTypeTest { + private Label currentRule; + + @Before + public void setUp() throws Exception { + this.currentRule = Label.parseAbsolute("//quux:baz"); + } + + @Test + public void testFilesetEntry() throws Exception { + Label srcDir = Label.create("foo", "src"); + Label entryLabel = Label.create("foo", "entry"); + FilesetEntry input = + new FilesetEntry(srcDir, ImmutableList.of(entryLabel), null, null, null, null); + assertEquals(input, BuildType.FILESET_ENTRY.convert(input, null, currentRule)); + assertThat(BuildType.FILESET_ENTRY.flatten(input)).containsExactly(entryLabel); + } + + @Test + public void testFilesetEntryList() throws Exception { + Label srcDir = Label.create("foo", "src"); + Label entry1Label = Label.create("foo", "entry1"); + Label entry2Label = Label.create("foo", "entry"); + List<FilesetEntry> input = ImmutableList.of( + new FilesetEntry(srcDir, ImmutableList.of(entry1Label), null, null, null, null), + new FilesetEntry(srcDir, ImmutableList.of(entry2Label), null, null, null, null)); + assertEquals(input, BuildType.FILESET_ENTRY_LIST.convert(input, null, currentRule)); + assertThat(BuildType.FILESET_ENTRY_LIST.flatten(input)).containsExactly(entry1Label, entry2Label); + } + + /** + * Tests basic {@link Selector} functionality. + */ + @Test + public void testSelector() throws Exception { + Object input = ImmutableMap.of( + "//conditions:a", "//a:a", + "//conditions:b", "//b:b", + BuildType.Selector.DEFAULT_CONDITION_KEY, "//d:d"); + Selector<Label> selector = new Selector<>(input, null, currentRule, BuildType.LABEL); + assertEquals(BuildType.LABEL, selector.getOriginalType()); + + Map<Label, Label> expectedMap = ImmutableMap.of( + Label.parseAbsolute("//conditions:a"), Label.create("a", "a"), + Label.parseAbsolute("//conditions:b"), Label.create("b", "b"), + Label.parseAbsolute(BuildType.Selector.DEFAULT_CONDITION_KEY), Label.create("d", "d")); + assertSameContents(expectedMap.entrySet(), selector.getEntries().entrySet()); + } + + /** + * Tests that creating a {@link Selector} over a mismatching native type triggers an + * exception. + */ + @Test + public void testSelectorWrongType() throws Exception { + Object input = ImmutableMap.of( + "//conditions:a", "not a label", + "//conditions:b", "also not a label", + BuildType.Selector.DEFAULT_CONDITION_KEY, "whatever"); + try { + new Selector<Label>(input, null, currentRule, BuildType.LABEL); + fail("Expected Selector instantiation to fail since the input isn't a selection of labels"); + } catch (ConversionException e) { + assertThat(e.getMessage()).contains("invalid label 'not a label'"); + } + } + + /** + * Tests that non-label selector keys trigger an exception. + */ + @Test + public void testSelectorKeyIsNotALabel() throws Exception { + Object input = ImmutableMap.of( + "not a label", "//a:a", + BuildType.Selector.DEFAULT_CONDITION_KEY, "whatever"); + try { + new Selector<Label>(input, null, currentRule, BuildType.LABEL); + fail("Expected Selector instantiation to fail since the key isn't a label"); + } catch (ConversionException e) { + assertThat(e.getMessage()).contains("invalid label 'not a label'"); + } + } + + /** + * Tests that {@link Selector} correctly references its default value. + */ + @Test + public void testSelectorDefault() throws Exception { + Object input = ImmutableMap.of( + "//conditions:a", "//a:a", + "//conditions:b", "//b:b", + BuildType.Selector.DEFAULT_CONDITION_KEY, "//d:d"); + assertEquals( + Label.create("d", "d"), + new Selector<Label>(input, null, currentRule, BuildType.LABEL).getDefault()); + } + + @Test + public void testSelectorList() throws Exception { + Object selector1 = new SelectorValue(ImmutableMap.of("//conditions:a", + ImmutableList.of("//a:a"), "//conditions:b", ImmutableList.of("//b:b"))); + Object selector2 = new SelectorValue(ImmutableMap.of("//conditions:c", + ImmutableList.of("//c:c"), "//conditions:d", ImmutableList.of("//d:d"))); + BuildType.SelectorList<List<Label>> selectorList = new BuildType.SelectorList<>( + ImmutableList.of(selector1, selector2), null, currentRule, BuildType.LABEL_LIST); + + assertEquals(BuildType.LABEL_LIST, selectorList.getOriginalType()); + assertSameContents( + ImmutableSet.of( + Label.parseAbsolute("//conditions:a"), Label.parseAbsolute("//conditions:b"), + Label.parseAbsolute("//conditions:c"), Label.parseAbsolute("//conditions:d")), + selectorList.getKeyLabels()); + + List<Selector<List<Label>>> selectors = selectorList.getSelectors(); + assertSameContents( + ImmutableMap.of( + Label.parseAbsolute("//conditions:a"), ImmutableList.of(Label.create("a", "a")), + Label.parseAbsolute("//conditions:b"), ImmutableList.of(Label.create("b", "b"))) + .entrySet(), + selectors.get(0).getEntries().entrySet()); + assertSameContents( + ImmutableMap.of( + Label.parseAbsolute("//conditions:c"), ImmutableList.of(Label.create("c", "c")), + Label.parseAbsolute("//conditions:d"), ImmutableList.of(Label.create("d", "d"))) + .entrySet(), + selectors.get(1).getEntries().entrySet()); + } + + @Test + public void testSelectorListMixedTypes() throws Exception { + Object selector1 = + new SelectorValue(ImmutableMap.of("//conditions:a", ImmutableList.of("//a:a"))); + Object selector2 = + new SelectorValue(ImmutableMap.of("//conditions:b", "//b:b")); + try { + new BuildType.SelectorList<>(ImmutableList.of(selector1, selector2), null, currentRule, + BuildType.LABEL_LIST); + fail("Expected SelectorList initialization to fail on mixed element types"); + } catch (ConversionException e) { + assertThat(e.getMessage()).contains("expected value of type 'list(label)'"); + } + } + + /** + * Tests that {@link BuildType#selectableConvert} returns either the native type or a selector + * on that type, in accordance with the provided input. + */ + @SuppressWarnings("unchecked") + @Test + public void testSelectableConvert() throws Exception { + Object nativeInput = Arrays.asList("//a:a1", "//a:a2"); + Object selectableInput = + SelectorList.of(new SelectorValue(ImmutableMap.of( + "//conditions:a", nativeInput, + BuildType.Selector.DEFAULT_CONDITION_KEY, nativeInput))); + List<Label> expectedLabels = ImmutableList.of(Label.create("a", "a1"), Label.create("a", "a2")); + + // Conversion to direct type: + Object converted = BuildType + .selectableConvert(BuildType.LABEL_LIST, nativeInput, null, currentRule); + assertTrue(converted instanceof List<?>); + assertSameContents(expectedLabels, (List<Label>) converted); + + // Conversion to selectable type: + converted = BuildType + .selectableConvert(BuildType.LABEL_LIST, selectableInput, null, currentRule); + BuildType.SelectorList<?> selectorList = (BuildType.SelectorList<?>) converted; + assertSameContents( + ImmutableMap.of( + Label.parseAbsolute("//conditions:a"), expectedLabels, + Label.parseAbsolute(BuildType.Selector.DEFAULT_CONDITION_KEY), + expectedLabels).entrySet(), + ((Selector<Label>) selectorList.getSelectors().get(0)).getEntries().entrySet()); + } + + /** + * Tests that {@link com.google.devtools.build.lib.syntax.Type#convert} fails on selector inputs. + */ + @Test + public void testConvertDoesNotAcceptSelectables() throws Exception { + Object selectableInput = SelectorList.of( + new SelectorValue(ImmutableMap.of("//conditions:a", Arrays.asList("//a:a1", "//a:a2")))); + try { + BuildType.LABEL_LIST.convert(selectableInput, null, currentRule); + fail("Expected conversion to fail on a selectable input"); + } catch (ConversionException e) { + assertThat(e.getMessage()).contains("expected value of type 'list(label)'"); + } + } + + /** + * Tests for "reserved" key labels (i.e. not intended to map to actual targets). + */ + @Test + public void testReservedKeyLabels() throws Exception { + assertFalse(BuildType.Selector.isReservedLabel(Label.parseAbsolute("//condition:a"))); + assertTrue(BuildType.Selector.isReservedLabel( + Label.parseAbsolute(BuildType.Selector.DEFAULT_CONDITION_KEY))); + } + + private static FilesetEntry makeFilesetEntry() { + try { + return new FilesetEntry(Label.parseAbsolute("//foo:bar"), + Lists.<Label>newArrayList(), Lists.newArrayList("xyz"), "", + FilesetEntry.SymlinkBehavior.COPY, "."); + } catch (LabelSyntaxException e) { + throw new RuntimeException("Bad label: ", e); + } + } + + private String createExpectedFilesetEntryString( + FilesetEntry.SymlinkBehavior symlinkBehavior, char quotationMark) { + return String.format( + "FilesetEntry(srcdir = %1$c//x:x%1$c," + + " files = [%1$c//x:x%1$c]," + + " excludes = []," + + " destdir = %1$c%1$c," + + " strip_prefix = %1$c.%1$c," + + " symlinks = %1$c%2$s%1$c)", + quotationMark, symlinkBehavior.toString().toLowerCase()); + } + + private String createExpectedFilesetEntryString(char quotationMark) { + return createExpectedFilesetEntryString(FilesetEntry.SymlinkBehavior.COPY, quotationMark); + } + + private FilesetEntry createTestFilesetEntry( + FilesetEntry.SymlinkBehavior symlinkBehavior) + throws LabelSyntaxException { + Label label = Label.parseAbsolute("//x"); + return new FilesetEntry( + label, Arrays.asList(label), Arrays.<String>asList(), "", symlinkBehavior, "."); + } + + private FilesetEntry createTestFilesetEntry() throws LabelSyntaxException { + return createTestFilesetEntry(FilesetEntry.SymlinkBehavior.COPY); + } + + @Test + public void testRegressionCrashInPrettyPrintValue() throws Exception { + // Would cause crash in code such as this: + // Fileset(name='x', entries=[], out=[FilesetEntry(files=['a'])]) + // While formatting the "expected x, got y" message for the 'out' + // attribute, prettyPrintValue(FilesetEntry) would be recursively called + // with a List<Label> even though this isn't a valid datatype in the + // interpreter. + // Fileset isn't part of bazel, even though FilesetEntry is. + assertEquals(createExpectedFilesetEntryString('"'), Printer.repr(createTestFilesetEntry())); + } + + @Test + public void testSingleQuotes() throws Exception { + assertThat(Printer.repr(createTestFilesetEntry(), '\'')) + .isEqualTo(createExpectedFilesetEntryString('\'')); + } + + @Test + public void testFilesetEntrySymlinkAttr() throws Exception { + FilesetEntry entryDereference = + createTestFilesetEntry(FilesetEntry.SymlinkBehavior.DEREFERENCE); + + assertEquals( + createExpectedFilesetEntryString(FilesetEntry.SymlinkBehavior.DEREFERENCE, '"'), + Printer.repr(entryDereference)); + } + + private FilesetEntry createStripPrefixFilesetEntry(String stripPrefix) throws Exception { + Label label = Label.parseAbsolute("//x"); + return new FilesetEntry( + label, + Arrays.asList(label), + Arrays.<String>asList(), + "", + FilesetEntry.SymlinkBehavior.DEREFERENCE, + stripPrefix); + } + + @Test + public void testFilesetEntryStripPrefixAttr() throws Exception { + FilesetEntry withoutStripPrefix = createStripPrefixFilesetEntry("."); + FilesetEntry withStripPrefix = createStripPrefixFilesetEntry("orange"); + + String prettyWithout = Printer.repr(withoutStripPrefix); + String prettyWith = Printer.repr(withStripPrefix); + + assertThat(prettyWithout).contains("strip_prefix = \".\""); + assertThat(prettyWith).contains("strip_prefix = \"orange\""); + } + + @Test + public void testPrintFilesetEntry() throws Exception { + assertEquals("FilesetEntry(srcdir = \"//foo:bar\", files = [], " + + "excludes = [\"xyz\"], destdir = \"\", " + + "strip_prefix = \".\", symlinks = \"copy\")", + Printer.repr(makeFilesetEntry())); + } + + @Test + public void testFilesetTypeDefinition() throws Exception { + assertEquals("FilesetEntry", EvalUtils.getDataTypeName(makeFilesetEntry())); + assertFalse(EvalUtils.isImmutable(makeFilesetEntry())); + } +} diff --git a/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java b/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java index 9666b029cb..ee1d915c3b 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java +++ b/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java @@ -16,15 +16,15 @@ package com.google.devtools.build.lib.packages; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import static com.google.devtools.build.lib.packages.Attribute.attr; +import static com.google.devtools.build.lib.packages.BuildType.LABEL; +import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; +import static com.google.devtools.build.lib.packages.BuildType.OUTPUT_LIST; import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.substitutePlaceholderIntoTemplate; import static com.google.devtools.build.lib.packages.RuleClass.NO_EXTERNAL_BINDINGS; -import static com.google.devtools.build.lib.packages.Type.BOOLEAN; -import static com.google.devtools.build.lib.packages.Type.INTEGER; -import static com.google.devtools.build.lib.packages.Type.LABEL; -import static com.google.devtools.build.lib.packages.Type.LABEL_LIST; -import static com.google.devtools.build.lib.packages.Type.OUTPUT_LIST; -import static com.google.devtools.build.lib.packages.Type.STRING; -import static com.google.devtools.build.lib.packages.Type.STRING_LIST; +import static com.google.devtools.build.lib.syntax.Type.BOOLEAN; +import static com.google.devtools.build.lib.syntax.Type.INTEGER; +import static com.google.devtools.build.lib.syntax.Type.STRING; +import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; import com.google.common.base.Predicate; import com.google.common.base.Predicates; @@ -47,6 +47,7 @@ import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType; import com.google.devtools.build.lib.packages.RuleClass.MissingFragmentPolicy; import com.google.devtools.build.lib.packages.util.PackageLoadingTestCase; import com.google.devtools.build.lib.syntax.Label; +import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.vfs.Path; import java.util.ArrayList; @@ -306,12 +307,12 @@ public class RuleClassTest extends PackageLoadingTestCase { // Test attribute access: AttributeMap attributes = RawAttributeMapper.of(rule); assertEquals("//default:label", - attributes.get("my-label-attr", Type.LABEL).toString()); + attributes.get("my-label-attr", BuildType.LABEL).toString()); assertEquals(42, attributes.get("my-integer-attr", Type.INTEGER).intValue()); assertEquals("", // missing attribute -> default chosen based on type attributes.get("my-string-attr", Type.STRING)); - assertThat(attributes.get("my-labellist-attr", Type.LABEL_LIST)).isEmpty(); + assertThat(attributes.get("my-labellist-attr", BuildType.LABEL_LIST)).isEmpty(); assertEquals(Arrays.asList("foo", "bar"), attributes.get("my-stringlist-attr", Type.STRING_LIST)); try { diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java index bcad177f47..4969d6cb7b 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java @@ -19,9 +19,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import com.google.common.collect.Lists; -import com.google.devtools.build.lib.cmdline.LabelSyntaxException; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -51,16 +48,6 @@ public class EvalUtilsTest { return new LinkedHashMap<>(); } - private static FilesetEntry makeFilesetEntry() { - try { - return new FilesetEntry(Label.parseAbsolute("//foo:bar"), - Lists.<Label>newArrayList(), Lists.newArrayList("xyz"), "", - FilesetEntry.SymlinkBehavior.COPY, "."); - } catch (LabelSyntaxException e) { - throw new RuntimeException("Bad label: ", e); - } - } - @Test public void testDataTypeNames() throws Exception { assertEquals("string", EvalUtils.getDataTypeName("foo")); @@ -68,7 +55,6 @@ public class EvalUtilsTest { assertEquals("Tuple", EvalUtils.getDataTypeName(makeTuple(1, 2, 3))); assertEquals("List", EvalUtils.getDataTypeName(makeList(1, 2, 3))); assertEquals("dict", EvalUtils.getDataTypeName(makeDict())); - assertEquals("FilesetEntry", EvalUtils.getDataTypeName(makeFilesetEntry())); assertEquals("NoneType", EvalUtils.getDataTypeName(Runtime.NONE)); } @@ -79,7 +65,6 @@ public class EvalUtilsTest { assertTrue(EvalUtils.isImmutable(makeTuple(1, 2, 3))); assertFalse(EvalUtils.isImmutable(makeList(1, 2, 3))); assertFalse(EvalUtils.isImmutable(makeDict())); - assertFalse(EvalUtils.isImmutable(makeFilesetEntry())); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java b/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java index 63d52368a6..f1576ddfb2 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java @@ -19,8 +19,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import org.junit.Test; import org.junit.runner.RunWith; @@ -47,16 +45,6 @@ public class PrinterTest { return EvalUtils.makeSequence(Arrays.<Object>asList(args), true); } - private static FilesetEntry makeFilesetEntry() { - try { - return new FilesetEntry(Label.parseAbsolute("//foo:bar"), - Lists.<Label>newArrayList(), Lists.newArrayList("xyz"), "", - FilesetEntry.SymlinkBehavior.COPY, "."); - } catch (LabelSyntaxException e) { - throw new RuntimeException("Bad label: ", e); - } - } - @Test public void testPrinter() throws Exception { // Note that prettyPrintValue and printValue only differ on behaviour of @@ -94,10 +82,6 @@ public class PrinterTest { Printer.str(dict)); assertEquals("{1: (\"foo\", \"bar\"), 2: [\"foo\", \"bar\"], \"foo\": []}", Printer.repr(dict)); - assertEquals("FilesetEntry(srcdir = \"//foo:bar\", files = [], " - + "excludes = [\"xyz\"], destdir = \"\", " - + "strip_prefix = \".\", symlinks = \"copy\")", - Printer.repr(makeFilesetEntry())); } private void checkFormatPositionalFails(String errorMessage, String format, Object... arguments) { @@ -155,51 +139,6 @@ public class PrinterTest { } @Test - public void testFilesetEntrySymlinkAttr() throws Exception { - FilesetEntry entryDereference = - createTestFilesetEntry(FilesetEntry.SymlinkBehavior.DEREFERENCE); - - assertEquals( - createExpectedFilesetEntryString(FilesetEntry.SymlinkBehavior.DEREFERENCE, '"'), - Printer.repr(entryDereference)); - } - - private FilesetEntry createStripPrefixFilesetEntry(String stripPrefix) throws Exception { - Label label = Label.parseAbsolute("//x"); - return new FilesetEntry( - label, - Arrays.asList(label), - Arrays.<String>asList(), - "", - FilesetEntry.SymlinkBehavior.DEREFERENCE, - stripPrefix); - } - - @Test - public void testFilesetEntryStripPrefixAttr() throws Exception { - FilesetEntry withoutStripPrefix = createStripPrefixFilesetEntry("."); - FilesetEntry withStripPrefix = createStripPrefixFilesetEntry("orange"); - - String prettyWithout = Printer.repr(withoutStripPrefix); - String prettyWith = Printer.repr(withStripPrefix); - - assertThat(prettyWithout).contains("strip_prefix = \".\""); - assertThat(prettyWith).contains("strip_prefix = \"orange\""); - } - - @Test - public void testRegressionCrashInPrettyPrintValue() throws Exception { - // Would cause crash in code such as this: - // Fileset(name='x', entries=[], out=[FilesetEntry(files=['a'])]) - // While formatting the "expected x, got y" message for the 'out' - // attribute, prettyPrintValue(FilesetEntry) would be recursively called - // with a List<Label> even though this isn't a valid datatype in the - // interpreter. - // Fileset isn't part of bazel, even though FilesetEntry is. - assertEquals(createExpectedFilesetEntryString('"'), Printer.repr(createTestFilesetEntry())); - } - - @Test public void testSingleQuotes() throws Exception { assertThat(Printer.str("test", '\'')).isEqualTo("test"); assertThat(Printer.repr("test", '\'')).isEqualTo("'test'"); @@ -223,35 +162,5 @@ public class PrinterTest { .isEqualTo("{1: ('foo', 'bar'), 2: ['foo', 'bar'], 'foo': []}"); assertThat(Printer.repr(dict, '\'')) .isEqualTo("{1: ('foo', 'bar'), 2: ['foo', 'bar'], 'foo': []}"); - - assertThat(Printer.repr(createTestFilesetEntry(), '\'')) - .isEqualTo(createExpectedFilesetEntryString('\'')); - } - - private String createExpectedFilesetEntryString( - FilesetEntry.SymlinkBehavior symlinkBehavior, char quotationMark) { - return String.format( - "FilesetEntry(srcdir = %1$c//x:x%1$c," - + " files = [%1$c//x:x%1$c]," - + " excludes = []," - + " destdir = %1$c%1$c," - + " strip_prefix = %1$c.%1$c," - + " symlinks = %1$c%2$s%1$c)", - quotationMark, symlinkBehavior.toString().toLowerCase()); - } - - private String createExpectedFilesetEntryString(char quotationMark) { - return createExpectedFilesetEntryString(FilesetEntry.SymlinkBehavior.COPY, quotationMark); - } - - private FilesetEntry createTestFilesetEntry(FilesetEntry.SymlinkBehavior symlinkBehavior) - throws LabelSyntaxException { - Label label = Label.parseAbsolute("//x"); - return new FilesetEntry( - label, Arrays.asList(label), Arrays.<String>asList(), "", symlinkBehavior, "."); - } - - private FilesetEntry createTestFilesetEntry() throws LabelSyntaxException { - return createTestFilesetEntry(FilesetEntry.SymlinkBehavior.COPY); } } diff --git a/src/test/java/com/google/devtools/build/lib/packages/TypeTest.java b/src/test/java/com/google/devtools/build/lib/syntax/TypeTest.java index baf0d0feea..712001d65b 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/TypeTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/TypeTest.java @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -package com.google.devtools.build.lib.packages; +package com.google.devtools.build.lib.syntax; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.testutil.MoreAsserts.assertSameContents; @@ -21,18 +21,16 @@ import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import com.google.devtools.build.lib.packages.Type.ConversionException; -import com.google.devtools.build.lib.syntax.FilesetEntry; -import com.google.devtools.build.lib.syntax.Label; -import com.google.devtools.build.lib.syntax.SelectorList; -import com.google.devtools.build.lib.syntax.SelectorValue; +import com.google.devtools.build.lib.packages.BuildType; +import com.google.devtools.build.lib.packages.License; +import com.google.devtools.build.lib.packages.TriState; +import com.google.devtools.build.lib.syntax.Type.ConversionException; import com.google.devtools.build.lib.testutil.MoreAsserts; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -143,15 +141,15 @@ public class TypeTest { @Test public void testTriState() throws Exception { - assertEquals(TriState.YES, Type.TRISTATE.convert(1, null)); - assertEquals(TriState.NO, Type.TRISTATE.convert(0, null)); - assertEquals(TriState.AUTO, Type.TRISTATE.convert(-1, null)); - assertEquals(TriState.YES, Type.TRISTATE.convert(true, null)); - assertEquals(TriState.NO, Type.TRISTATE.convert(false, null)); - assertEquals(TriState.YES, Type.TRISTATE.convert(TriState.YES, null)); - assertEquals(TriState.NO, Type.TRISTATE.convert(TriState.NO, null)); - assertEquals(TriState.AUTO, Type.TRISTATE.convert(TriState.AUTO, null)); - assertThat(Type.TRISTATE.flatten(TriState.YES)).isEmpty(); + Assert.assertEquals(TriState.YES, BuildType.TRISTATE.convert(1, null)); + assertEquals(TriState.NO, BuildType.TRISTATE.convert(0, null)); + assertEquals(TriState.AUTO, BuildType.TRISTATE.convert(-1, null)); + assertEquals(TriState.YES, BuildType.TRISTATE.convert(true, null)); + assertEquals(TriState.NO, BuildType.TRISTATE.convert(false, null)); + assertEquals(TriState.YES, BuildType.TRISTATE.convert(TriState.YES, null)); + assertEquals(TriState.NO, BuildType.TRISTATE.convert(TriState.NO, null)); + assertEquals(TriState.AUTO, BuildType.TRISTATE.convert(TriState.AUTO, null)); + assertThat(BuildType.TRISTATE.flatten(TriState.YES)).isEmpty(); } @Test @@ -159,7 +157,7 @@ public class TypeTest { List<Integer> listOfCases = Lists.newArrayList(2, 3, -5, -2, 20); for (Object entry : listOfCases) { try { - Type.TRISTATE.convert(entry, null); + BuildType.TRISTATE.convert(entry, null); fail(); } catch (Type.ConversionException e) { // Expected. @@ -172,7 +170,7 @@ public class TypeTest { List<String> listOfCases = Lists.newArrayList("bad", "true", "auto", "false"); for (Object entry : listOfCases) { try { - Type.TRISTATE.convert(entry, null); + BuildType.TRISTATE.convert(entry, null); fail(); } catch (Type.ConversionException e) { // Expected. @@ -198,13 +196,13 @@ public class TypeTest { @Test public void testIllegalTagConversionByType() throws Exception { try { - Type.TRISTATE.toTagSet(TriState.AUTO, "some_tristate"); + BuildType.TRISTATE.toTagSet(TriState.AUTO, "some_tristate"); fail("Expect UnsuportedOperationException"); } catch (UnsupportedOperationException e) { // Success. } try { - Type.LICENSE.toTagSet(License.NO_LICENSE, "output_license"); + BuildType.LICENSE.toTagSet(License.NO_LICENSE, "output_license"); fail("Expect UnsuportedOperationException"); } catch (UnsupportedOperationException e) { // Success. @@ -224,25 +222,25 @@ public class TypeTest { @Test public void testLabel() throws Exception { Label label = Label.parseAbsolute("//foo:bar"); - assertEquals(label, Type.LABEL.convert("//foo:bar", null, currentRule)); - assertThat(Type.LABEL.flatten(label)).containsExactly(label); + assertEquals(label, BuildType.LABEL.convert("//foo:bar", null, currentRule)); + assertThat(BuildType.LABEL.flatten(label)).containsExactly(label); } @Test public void testNodepLabel() throws Exception { Label label = Label.parseAbsolute("//foo:bar"); - assertEquals(label, Type.NODEP_LABEL.convert("//foo:bar", null, currentRule)); - assertThat(Type.NODEP_LABEL.flatten(label)).containsExactly(label); + assertEquals(label, BuildType.NODEP_LABEL.convert("//foo:bar", null, currentRule)); + assertThat(BuildType.NODEP_LABEL.flatten(label)).containsExactly(label); } @Test public void testRelativeLabel() throws Exception { assertEquals(Label.parseAbsolute("//quux:wiz"), - Type.LABEL.convert(":wiz", null, currentRule)); + BuildType.LABEL.convert(":wiz", null, currentRule)); assertEquals(Label.parseAbsolute("//quux:wiz"), - Type.LABEL.convert("wiz", null, currentRule)); + BuildType.LABEL.convert("wiz", null, currentRule)); try { - Type.LABEL.convert("wiz", null); + BuildType.LABEL.convert("wiz", null); fail(); } catch (NullPointerException e) { /* ok */ @@ -252,7 +250,7 @@ public class TypeTest { @Test public void testInvalidLabel() throws Exception { try { - Type.LABEL.convert("not a label", null, currentRule); + BuildType.LABEL.convert("not a label", null, currentRule); fail(); } catch (Type.ConversionException e) { MoreAsserts.assertContainsWordsWithQuotes(e.getMessage(), "not a label"); @@ -262,7 +260,7 @@ public class TypeTest { @Test public void testNonLabel() throws Exception { try { - Type.LABEL.convert(3, null); + BuildType.LABEL.convert(3, null); fail(); } catch (Type.ConversionException e) { assertThat(e).hasMessage("expected value of type 'string', but got 3 (int)"); @@ -328,19 +326,19 @@ public class TypeTest { public void testLabelList() throws Exception { Object input = Arrays.asList("//foo:bar", ":wiz"); List<Label> converted = - Type.LABEL_LIST.convert(input , null, currentRule); + BuildType.LABEL_LIST.convert(input , null, currentRule); List<Label> expected = Arrays.asList(Label.parseAbsolute("//foo:bar"), Label.parseAbsolute("//quux:wiz")); assertEquals(expected, converted); assertNotSame(expected, converted); - assertThat(Type.LABEL_LIST.flatten(converted)).containsExactlyElementsIn(expected); + assertThat(BuildType.LABEL_LIST.flatten(converted)).containsExactlyElementsIn(expected); } @Test public void testNonLabelList() throws Exception { try { - Type.LABEL_LIST.convert(3, "foo", currentRule); + BuildType.LABEL_LIST.convert(3, "foo", currentRule); fail(); } catch (Type.ConversionException e) { assertThat(e).hasMessage("expected value of type 'list(label)' for foo, but got 3 (int)"); @@ -351,7 +349,7 @@ public class TypeTest { public void testLabelListBadElements() throws Exception { Object list = Arrays.<Object>asList("//foo:bar", 2, "foo"); try { - Type.LABEL_LIST.convert(list, null, currentRule); + BuildType.LABEL_LIST.convert(list, null, currentRule); fail(); } catch (Type.ConversionException e) { assertThat(e).hasMessage( @@ -363,7 +361,7 @@ public class TypeTest { public void testLabelListSyntaxError() throws Exception { Object list = Arrays.<Object>asList("//foo:bar/..", "foo"); try { - Type.LABEL_LIST.convert(list, "myexpr", currentRule); + BuildType.LABEL_LIST.convert(list, "myexpr", currentRule); fail(); } catch (Type.ConversionException e) { assertThat(e).hasMessage("invalid label '//foo:bar/..' in element 0 of myexpr: " @@ -376,7 +374,8 @@ public class TypeTest { public void testLabelListDict() throws Exception { Object input = ImmutableMap.of("foo", Arrays.asList("//foo:bar"), "wiz", Arrays.asList(":bang")); - Map<String, List<Label>> converted = Type.LABEL_LIST_DICT.convert(input, null, currentRule); + Map<String, List<Label>> converted = + BuildType.LABEL_LIST_DICT.convert(input, null, currentRule); Label fooLabel = Label.parseAbsolute("//foo:bar"); Label bangLabel = Label.parseAbsolute("//quux:bang"); Map<?, ?> expected = ImmutableMap.<String, List<Label>>of( @@ -384,7 +383,7 @@ public class TypeTest { "wiz", Arrays.<Label>asList(bangLabel)); assertEquals(expected, converted); assertNotSame(expected, converted); - assertThat(Type.LABEL_LIST_DICT.flatten(converted)).containsExactly(fooLabel, bangLabel); + assertThat(BuildType.LABEL_LIST_DICT.flatten(converted)).containsExactly(fooLabel, bangLabel); } @Test @@ -392,7 +391,7 @@ public class TypeTest { Object input = ImmutableMap.of(2, Arrays.asList("//foo:bar"), "wiz", Arrays.asList(":bang")); try { - Type.LABEL_LIST_DICT.convert(input, null, currentRule); + BuildType.LABEL_LIST_DICT.convert(input, null, currentRule); fail(); } catch (Type.ConversionException e) { assertThat(e).hasMessage( @@ -405,7 +404,7 @@ public class TypeTest { Object input = ImmutableMap.of("foo", "//foo:bar", "wiz", Arrays.asList(":bang")); try { - Type.LABEL_LIST_DICT.convert(input, null, currentRule); + BuildType.LABEL_LIST_DICT.convert(input, null, currentRule); fail(); } catch (Type.ConversionException e) { assertThat(e).hasMessage( @@ -420,7 +419,7 @@ public class TypeTest { "bar", Arrays.asList("//foo:bar"), "wiz", Arrays.asList(":bang")); try { - Type.LABEL_LIST_DICT.convert(input, null); + BuildType.LABEL_LIST_DICT.convert(input, null); fail(); } catch (Type.ConversionException e) { assertThat(e).hasMessage("expected value of type 'list(label)' for dict value element, " @@ -433,7 +432,7 @@ public class TypeTest { Object input = ImmutableMap.of("foo", Arrays.asList("//foo:.."), "wiz", Arrays.asList(":bang")); try { - Type.LABEL_LIST_DICT.convert(input, "baz", currentRule); + BuildType.LABEL_LIST_DICT.convert(input, "baz", currentRule); fail(); } catch (Type.ConversionException e) { assertThat(e).hasMessage("invalid label '//foo:..' in element 0 of dict value element: " @@ -559,193 +558,4 @@ public class TypeTest { assertThat(e).hasMessage("Expected a map for dictionary but got a java.lang.String"); } } - - @Test - public void testFilesetEntry() throws Exception { - Label srcDir = Label.create("foo", "src"); - Label entryLabel = Label.create("foo", "entry"); - FilesetEntry input = - new FilesetEntry(srcDir, ImmutableList.of(entryLabel), null, null, null, null); - assertEquals(input, Type.FILESET_ENTRY.convert(input, null, currentRule)); - assertThat(Type.FILESET_ENTRY.flatten(input)).containsExactly(entryLabel); - } - - @Test - public void testFilesetEntryList() throws Exception { - Label srcDir = Label.create("foo", "src"); - Label entry1Label = Label.create("foo", "entry1"); - Label entry2Label = Label.create("foo", "entry"); - List<FilesetEntry> input = ImmutableList.of( - new FilesetEntry(srcDir, ImmutableList.of(entry1Label), null, null, null, null), - new FilesetEntry(srcDir, ImmutableList.of(entry2Label), null, null, null, null)); - assertEquals(input, Type.FILESET_ENTRY_LIST.convert(input, null, currentRule)); - assertThat(Type.FILESET_ENTRY_LIST.flatten(input)).containsExactly(entry1Label, entry2Label); - } - - /** - * Tests basic {@link Type.Selector} functionality. - */ - @Test - public void testSelector() throws Exception { - Object input = ImmutableMap.of( - "//conditions:a", "//a:a", - "//conditions:b", "//b:b", - Type.Selector.DEFAULT_CONDITION_KEY, "//d:d"); - Type.Selector<Label> selector = new Type.Selector<>(input, null, currentRule, Type.LABEL); - assertEquals(Type.LABEL, selector.getOriginalType()); - - Map<Label, Label> expectedMap = ImmutableMap.of( - Label.parseAbsolute("//conditions:a"), Label.create("a", "a"), - Label.parseAbsolute("//conditions:b"), Label.create("b", "b"), - Label.parseAbsolute(Type.Selector.DEFAULT_CONDITION_KEY), Label.create("d", "d")); - assertSameContents(expectedMap.entrySet(), selector.getEntries().entrySet()); - } - - /** - * Tests that creating a {@link Type.Selector} over a mismatching native type triggers an - * exception. - */ - @Test - public void testSelectorWrongType() throws Exception { - Object input = ImmutableMap.of( - "//conditions:a", "not a label", - "//conditions:b", "also not a label", - Type.Selector.DEFAULT_CONDITION_KEY, "whatever"); - try { - new Type.Selector<Label>(input, null, currentRule, Type.LABEL); - fail("Expected Selector instantiation to fail since the input isn't a selection of labels"); - } catch (ConversionException e) { - assertThat(e.getMessage()).contains("invalid label 'not a label'"); - } - } - - /** - * Tests that non-label selector keys trigger an exception. - */ - @Test - public void testSelectorKeyIsNotALabel() throws Exception { - Object input = ImmutableMap.of( - "not a label", "//a:a", - Type.Selector.DEFAULT_CONDITION_KEY, "whatever"); - try { - new Type.Selector<Label>(input, null, currentRule, Type.LABEL); - fail("Expected Selector instantiation to fail since the key isn't a label"); - } catch (ConversionException e) { - assertThat(e.getMessage()).contains("invalid label 'not a label'"); - } - } - - /** - * Tests that {@link Type.Selector} correctly references its default value. - */ - @Test - public void testSelectorDefault() throws Exception { - Object input = ImmutableMap.of( - "//conditions:a", "//a:a", - "//conditions:b", "//b:b", - Type.Selector.DEFAULT_CONDITION_KEY, "//d:d"); - assertEquals( - Label.create("d", "d"), - new Type.Selector<Label>(input, null, currentRule, Type.LABEL).getDefault()); - } - - @Test - public void testSelectorList() throws Exception { - Object selector1 = new SelectorValue(ImmutableMap.of("//conditions:a", - ImmutableList.of("//a:a"), "//conditions:b", ImmutableList.of("//b:b"))); - Object selector2 = new SelectorValue(ImmutableMap.of("//conditions:c", - ImmutableList.of("//c:c"), "//conditions:d", ImmutableList.of("//d:d"))); - Type.SelectorList<List<Label>> selectorList = new Type.SelectorList<>( - ImmutableList.of(selector1, selector2), null, currentRule, Type.LABEL_LIST); - - assertEquals(Type.LABEL_LIST, selectorList.getOriginalType()); - assertSameContents( - ImmutableSet.of( - Label.parseAbsolute("//conditions:a"), Label.parseAbsolute("//conditions:b"), - Label.parseAbsolute("//conditions:c"), Label.parseAbsolute("//conditions:d")), - selectorList.getKeyLabels()); - - List<Type.Selector<List<Label>>> selectors = selectorList.getSelectors(); - assertSameContents( - ImmutableMap.of( - Label.parseAbsolute("//conditions:a"), ImmutableList.of(Label.create("a", "a")), - Label.parseAbsolute("//conditions:b"), ImmutableList.of(Label.create("b", "b"))) - .entrySet(), - selectors.get(0).getEntries().entrySet()); - assertSameContents( - ImmutableMap.of( - Label.parseAbsolute("//conditions:c"), ImmutableList.of(Label.create("c", "c")), - Label.parseAbsolute("//conditions:d"), ImmutableList.of(Label.create("d", "d"))) - .entrySet(), - selectors.get(1).getEntries().entrySet()); - } - - @Test - public void testSelectorListMixedTypes() throws Exception { - Object selector1 = - new SelectorValue(ImmutableMap.of("//conditions:a", ImmutableList.of("//a:a"))); - Object selector2 = - new SelectorValue(ImmutableMap.of("//conditions:b", "//b:b")); - try { - new Type.SelectorList<>(ImmutableList.of(selector1, selector2), null, currentRule, - Type.LABEL_LIST); - fail("Expected SelectorList initialization to fail on mixed element types"); - } catch (ConversionException e) { - assertThat(e.getMessage()).contains("expected value of type 'list(label)'"); - } - } - - /** - * Tests that {@link Type#selectableConvert} returns either the native type or a selector - * on that type, in accordance with the provided input. - */ - @SuppressWarnings("unchecked") - @Test - public void testSelectableConvert() throws Exception { - Object nativeInput = Arrays.asList("//a:a1", "//a:a2"); - Object selectableInput = - SelectorList.of(new SelectorValue(ImmutableMap.of( - "//conditions:a", nativeInput, - Type.Selector.DEFAULT_CONDITION_KEY, nativeInput))); - List<Label> expectedLabels = ImmutableList.of(Label.create("a", "a1"), Label.create("a", "a2")); - - // Conversion to direct type: - Object converted = Type.LABEL_LIST.selectableConvert(nativeInput, null, currentRule); - assertTrue(converted instanceof List<?>); - assertSameContents(expectedLabels, (List<Label>) converted); - - // Conversion to selectable type: - converted = Type.LABEL_LIST.selectableConvert(selectableInput, null, currentRule); - Type.SelectorList<?> selectorList = (Type.SelectorList<?>) converted; - assertSameContents( - ImmutableMap.of( - Label.parseAbsolute("//conditions:a"), expectedLabels, - Label.parseAbsolute(Type.Selector.DEFAULT_CONDITION_KEY), expectedLabels).entrySet(), - ((Type.Selector<Label>) selectorList.getSelectors().get(0)).getEntries().entrySet()); - } - - /** - * Tests that {@link Type#convert} fails on selector inputs. - */ - @Test - public void testConvertDoesNotAcceptSelectables() throws Exception { - Object selectableInput = SelectorList.of( - new SelectorValue(ImmutableMap.of("//conditions:a", Arrays.asList("//a:a1", "//a:a2")))); - try { - Type.LABEL_LIST.convert(selectableInput, null, currentRule); - fail("Expected conversion to fail on a selectable input"); - } catch (ConversionException e) { - assertThat(e.getMessage()).contains("expected value of type 'list(label)'"); - } - } - - /** - * Tests for "reserved" key labels (i.e. not intended to map to actual targets). - */ - @Test - public void testReservedKeyLabels() throws Exception { - assertFalse(Type.Selector.isReservedLabel(Label.parseAbsolute("//condition:a"))); - assertTrue(Type.Selector.isReservedLabel( - Label.parseAbsolute(Type.Selector.DEFAULT_CONDITION_KEY))); - } } diff --git a/src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java b/src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java index b4227722dc..6a24a801d0 100644 --- a/src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java +++ b/src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java @@ -18,8 +18,9 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.devtools.build.lib.packages.Attribute; import com.google.devtools.build.lib.packages.Attribute.AllowedValueSet; +import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.RuleClass; -import com.google.devtools.build.lib.packages.Type; +import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.util.FileTypeSet; import java.util.Collection; @@ -56,7 +57,7 @@ public class BuildRuleWithDefaultsBuilder extends BuildRuleBuilder { */ private String getDummyFileLabel(String rulePkg, String filePkg, String extension, Type<?> attrType) { - boolean isInput = (attrType == Type.LABEL || attrType == Type.LABEL_LIST); + boolean isInput = (attrType == BuildType.LABEL || attrType == BuildType.LABEL_LIST); String fileName = (isInput ? "dummy_input" : "dummy_output") + extension; generateFiles.add(filePkg + "/" + fileName); if (rulePkg.equals(filePkg)) { @@ -121,7 +122,7 @@ public class BuildRuleWithDefaultsBuilder extends BuildRuleBuilder { } } if (label != null) { - if (attrType == Type.LABEL_LIST || attrType == Type.OUTPUT_LIST) { + if (attrType == BuildType.LABEL_LIST || attrType == BuildType.OUTPUT_LIST) { addMultiValueAttributes(attribute.getName(), label); } else { setSingleValueAttribute(attribute.getName(), label); @@ -174,7 +175,8 @@ public class BuildRuleWithDefaultsBuilder extends BuildRuleBuilder { public BuildRuleWithDefaultsBuilder popuplateAttributes(String rulePkg, boolean heuristics) { for (Attribute attribute : ruleClass.getAttributes()) { if (attribute.isMandatory()) { - if (attribute.getType() == Type.LABEL_LIST || attribute.getType() == Type.OUTPUT_LIST) { + if (attribute.getType() == BuildType.LABEL_LIST + || attribute.getType() == BuildType.OUTPUT_LIST) { if (attribute.isNonEmpty()) { popuplateLabelAttribute(rulePkg, attribute); } else { @@ -182,7 +184,8 @@ public class BuildRuleWithDefaultsBuilder extends BuildRuleBuilder { // doesn't support that, and it makes little sense anyway popuplateLabelAttribute(rulePkg, attribute); } - } else if (attribute.getType() == Type.LABEL || attribute.getType() == Type.OUTPUT) { + } else if (attribute.getType() == BuildType.LABEL + || attribute.getType() == BuildType.OUTPUT) { popuplateLabelAttribute(rulePkg, attribute); } else { // Non label type attributes @@ -211,7 +214,7 @@ public class BuildRuleWithDefaultsBuilder extends BuildRuleBuilder { // Heuristics which might help to generate valid rules. // This is a bit hackish, but it helps some generated ruleclasses to pass analysis phase. private void populateAttributesHeuristics(String rulePkg, Attribute attribute) { - if (attribute.getName().equals("srcs") && attribute.getType() == Type.LABEL_LIST) { + if (attribute.getName().equals("srcs") && attribute.getType() == BuildType.LABEL_LIST) { // If there is a srcs attribute it might be better to populate it even if it's not mandatory popuplateLabelAttribute(rulePkg, attribute); } else if (attribute.getName().equals("main_class") && attribute.getType() == Type.STRING) { diff --git a/src/test/java/com/google/devtools/build/lib/testutil/TestRuleClassProvider.java b/src/test/java/com/google/devtools/build/lib/testutil/TestRuleClassProvider.java index 9681475406..ed4f0b61bc 100644 --- a/src/test/java/com/google/devtools/build/lib/testutil/TestRuleClassProvider.java +++ b/src/test/java/com/google/devtools/build/lib/testutil/TestRuleClassProvider.java @@ -15,10 +15,10 @@ package com.google.devtools.build.lib.testutil; import static com.google.devtools.build.lib.packages.Attribute.attr; -import static com.google.devtools.build.lib.packages.Type.INTEGER; -import static com.google.devtools.build.lib.packages.Type.LABEL_LIST; -import static com.google.devtools.build.lib.packages.Type.OUTPUT_LIST; -import static com.google.devtools.build.lib.packages.Type.STRING_LIST; +import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; +import static com.google.devtools.build.lib.packages.BuildType.OUTPUT_LIST; +import static com.google.devtools.build.lib.syntax.Type.INTEGER; +import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; |