From 178a3dfda8bf72abf22758597a90a4afb8eed181 Mon Sep 17 00:00:00 2001 From: Janak Ramakrishnan Date: Wed, 4 May 2016 17:47:59 +0000 Subject: Allow modules to inject a custom AttributeContainer. -- MOS_MIGRATED_REVID=121497233 --- .../build/lib/packages/AttributeContainer.java | 11 ++++- .../build/lib/packages/ExternalPackageBuilder.java | 36 ++++++++++++-- .../build/lib/packages/PackageFactory.java | 56 +++++++++++++++++----- .../devtools/build/lib/packages/RuleFactory.java | 43 +++++++++++++---- .../build/lib/packages/WorkspaceFactory.java | 16 ++++--- .../build/lib/rules/SkylarkRuleClassFunctions.java | 8 +++- .../devtools/build/lib/runtime/BlazeModule.java | 8 ++++ .../devtools/build/lib/runtime/BlazeRuntime.java | 28 ++++++++++- .../build/lib/analysis/config/StampTest.java | 6 ++- .../build/lib/packages/RuleFactoryTest.java | 33 ++++++++----- .../lib/packages/util/PackageFactoryApparatus.java | 10 +++- .../build/lib/skylark/util/SkylarkTestCase.java | 2 +- 12 files changed, 207 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/main/java/com/google/devtools/build/lib/packages/AttributeContainer.java b/src/main/java/com/google/devtools/build/lib/packages/AttributeContainer.java index 15917f6b8b..8c5bfffaa6 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/AttributeContainer.java +++ b/src/main/java/com/google/devtools/build/lib/packages/AttributeContainer.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.packages; +import com.google.common.base.Function; import com.google.devtools.build.lib.events.Location; import java.util.BitSet; @@ -46,7 +47,7 @@ public class AttributeContainer { /** * Create a container for a rule of the given rule class. */ - AttributeContainer(RuleClass ruleClass) { + public AttributeContainer(RuleClass ruleClass) { this(ruleClass, new Location[ruleClass.getAttributeCount()]); } @@ -117,4 +118,12 @@ public class AttributeContainer { Integer index = ruleClass.getAttributeIndex(attribute.getName()); attributeLocations[index] = location; } + + public static final Function ATTRIBUTE_CONTAINER_FACTORY = + new Function() { + @Override + public AttributeContainer apply(RuleClass ruleClass) { + return new AttributeContainer(ruleClass); + } + }; } diff --git a/src/main/java/com/google/devtools/build/lib/packages/ExternalPackageBuilder.java b/src/main/java/com/google/devtools/build/lib/packages/ExternalPackageBuilder.java index ebafff7355..91e6c06368 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/ExternalPackageBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/packages/ExternalPackageBuilder.java @@ -20,6 +20,7 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.events.StoredEventHandler; +import com.google.devtools.build.lib.packages.Package.Builder; import com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap; import com.google.devtools.build.lib.syntax.FuncallExpression; import com.google.devtools.build.lib.util.Preconditions; @@ -44,19 +45,37 @@ public class ExternalPackageBuilder { BuildLangTypedAttributeValuesMap attributeValues = new BuildLangTypedAttributeValuesMap(kwargs); Rule rule = RuleFactory.createRule( - pkg, ruleClass, attributeValues, eventHandler, ast, ast.getLocation(), /*env=*/ null); + pkg, + ruleClass, + attributeValues, + eventHandler, + ast, + ast.getLocation(), + /*env=*/ null, + new AttributeContainer(ruleClass)); pkg.addEvents(eventHandler.getEvents()); overwriteRule(pkg, rule); for (Map.Entry entry : ruleClass.getExternalBindingsFunction().apply(rule).entrySet()) { Label nameLabel = Label.parseAbsolute("//external:" + entry.getKey()); - addBindRule(pkg, bindRuleClass, nameLabel, entry.getValue(), rule.getLocation()); + addBindRule( + pkg, + bindRuleClass, + nameLabel, + entry.getValue(), + rule.getLocation(), + new AttributeContainer(ruleClass)); } return rule; } - public void addBindRule( - Package.Builder pkg, RuleClass bindRuleClass, Label virtual, Label actual, Location location) + void addBindRule( + Builder pkg, + RuleClass bindRuleClass, + Label virtual, + Label actual, + Location location, + AttributeContainer attributeContainer) throws RuleFactory.InvalidRuleException, Package.NameConflictException, InterruptedException { Map attributes = Maps.newHashMap(); @@ -71,7 +90,14 @@ public class ExternalPackageBuilder { new BuildLangTypedAttributeValuesMap(attributes); Rule rule = RuleFactory.createRule( - pkg, bindRuleClass, attributeValues, handler, /*ast=*/ null, location, /*env=*/ null); + pkg, + bindRuleClass, + attributeValues, + handler, + /*ast=*/ null, + location, + /*env=*/ null, + attributeContainer); overwriteRule(pkg, rule); rule.setVisibility(ConstantRuleVisibility.PUBLIC); } diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java index 6f86bbd76d..670b99ba7e 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java +++ b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.packages; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -331,31 +332,48 @@ public final class PackageFactory { */ @VisibleForTesting public PackageFactory(RuleClassProvider ruleClassProvider) { - this(ruleClassProvider, null, ImmutableList.of(), "test"); + this( + ruleClassProvider, + null, + AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY, + ImmutableList.of(), + "test"); } @VisibleForTesting public PackageFactory(RuleClassProvider ruleClassProvider, EnvironmentExtension environmentExtension) { - this(ruleClassProvider, null, ImmutableList.of(environmentExtension), "test"); + this( + ruleClassProvider, + null, + AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY, + ImmutableList.of(environmentExtension), + "test"); } @VisibleForTesting public PackageFactory(RuleClassProvider ruleClassProvider, Iterable environmentExtensions) { - this(ruleClassProvider, null, environmentExtensions, "test"); + this( + ruleClassProvider, + null, + AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY, + environmentExtensions, + "test"); } /** * Constructs a {@code PackageFactory} instance with a specific glob path translator * and rule factory. */ - public PackageFactory(RuleClassProvider ruleClassProvider, + public PackageFactory( + RuleClassProvider ruleClassProvider, Map platformSetRegexps, + Function attributeContainerFactory, Iterable environmentExtensions, String version) { this.platformSetRegexps = platformSetRegexps; - this.ruleFactory = new RuleFactory(ruleClassProvider); + this.ruleFactory = new RuleFactory(ruleClassProvider, attributeContainerFactory); this.ruleClassProvider = ruleClassProvider; threadPool = new ThreadPoolExecutor(100, 100, 15L, TimeUnit.SECONDS, new LinkedBlockingQueue(), @@ -1102,7 +1120,8 @@ public final class PackageFactory { throws RuleFactory.InvalidRuleException, Package.NameConflictException, InterruptedException { RuleClass ruleClass = getBuiltInRuleClass(ruleClassName, ruleFactory); BuildLangTypedAttributeValuesMap attributeValues = new BuildLangTypedAttributeValuesMap(kwargs); - RuleFactory.createAndAddRule(context, ruleClass, attributeValues, ast, env); + AttributeContainer attributeContainer = ruleFactory.getAttributeContainer(ruleClass); + RuleFactory.createAndAddRule(context, ruleClass, attributeValues, ast, env, attributeContainer); } private static RuleClass getBuiltInRuleClass(String ruleClassName, RuleFactory ruleFactory) { @@ -1374,17 +1393,21 @@ public final class PackageFactory { * footprint when making changes here! */ public static class PackageContext { - final Package.LegacyBuilder pkgBuilder; final Globber globber; final EventHandler eventHandler; + private final Function attributeContainerFactory; @VisibleForTesting - public PackageContext(Package.LegacyBuilder pkgBuilder, Globber globber, - EventHandler eventHandler) { + public PackageContext( + Package.LegacyBuilder pkgBuilder, + Globber globber, + EventHandler eventHandler, + Function attributeContainerFactory) { this.pkgBuilder = pkgBuilder; this.eventHandler = eventHandler; this.globber = globber; + this.attributeContainerFactory = attributeContainerFactory; } /** @@ -1407,6 +1430,10 @@ public final class PackageFactory { public Package.Builder getBuilder() { return pkgBuilder; } + + public Function getAttributeContainerFactory() { + return attributeContainerFactory; + } } private final ClassObject nativeModule; @@ -1521,7 +1548,9 @@ public final class PackageFactory { Event.replayEventsOn(eventHandler, pastEvents); // Stuff that closes over the package context: - PackageContext context = new PackageContext(pkgBuilder, globber, eventHandler); + PackageContext context = + new PackageContext( + pkgBuilder, globber, eventHandler, ruleFactory.getAttributeContainerFactory()); buildPkgEnv(pkgEnv, context, ruleFactory); pkgEnv.setupDynamic(PKG_CONTEXT, context); pkgEnv.setupDynamic(Runtime.PKG_NAME, packageId.getPackageFragment().getPathString()); @@ -1593,7 +1622,12 @@ public final class PackageFactory { .setDefaultVisibilitySet(false); // Stuff that closes over the package context: - PackageContext context = new PackageContext(pkgBuilder, globber, NullEventHandler.INSTANCE); + PackageContext context = + new PackageContext( + pkgBuilder, + globber, + NullEventHandler.INSTANCE, + ruleFactory.getAttributeContainerFactory()); buildPkgEnv(pkgEnv, context, ruleFactory); try { pkgEnv.update("glob", newGlobFunction.apply(context, /*async=*/true)); diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java b/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java index 4837b04763..3b6cf4c904 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java +++ b/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.packages; +import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.LabelSyntaxException; @@ -47,11 +48,15 @@ public class RuleFactory { * Maps rule class name to the metaclass instance for that rule. */ private final ImmutableMap ruleClassMap; + private final Function attributeContainerFactory; /** * Constructs a RuleFactory instance. */ - public RuleFactory(RuleClassProvider provider) { + public RuleFactory( + RuleClassProvider provider, + Function attributeContainerFactory) { + this.attributeContainerFactory = attributeContainerFactory; this.ruleClassMap = ImmutableMap.copyOf(provider.getRuleClassMap()); } @@ -69,6 +74,14 @@ public class RuleFactory { return ruleClassMap.get(ruleClassName); } + AttributeContainer getAttributeContainer(RuleClass ruleClass) { + return attributeContainerFactory.apply(ruleClass); + } + + Function getAttributeContainerFactory() { + return attributeContainerFactory; + } + /** * Creates and returns a rule instance. * @@ -82,7 +95,8 @@ public class RuleFactory { EventHandler eventHandler, @Nullable FuncallExpression ast, Location location, - @Nullable Environment env) + @Nullable Environment env, + AttributeContainer attributeContainer) throws InvalidRuleException, InterruptedException { Preconditions.checkNotNull(ruleClass); String ruleClassName = ruleClass.getName(); @@ -120,7 +134,7 @@ public class RuleFactory { eventHandler, ast, generator.location, - new AttributeContainer(ruleClass)); + attributeContainer); } catch (LabelSyntaxException e) { throw new RuleFactory.InvalidRuleException(ruleClass + " " + e.getMessage()); } @@ -141,6 +155,7 @@ public class RuleFactory { * @param ast the abstract syntax tree of the rule expression (optional) * @param location the location at which this rule was declared * @param env the lexical environment of the function call which declared this rule (optional) + * @param attributeContainer the {@link AttributeContainer} the rule will contain * @throws InvalidRuleException if the rule could not be constructed for any * reason (e.g. no {@code name} attribute is defined) * @throws NameConflictException if the rule's name or output files conflict with others in this @@ -154,10 +169,19 @@ public class RuleFactory { EventHandler eventHandler, @Nullable FuncallExpression ast, Location location, - @Nullable Environment env) + @Nullable Environment env, + AttributeContainer attributeContainer) throws InvalidRuleException, NameConflictException, InterruptedException { - Rule rule = createRule( - pkgBuilder, ruleClass, attributeValues, eventHandler, ast, location, env); + Rule rule = + createRule( + pkgBuilder, + ruleClass, + attributeValues, + eventHandler, + ast, + location, + env, + attributeContainer); pkgBuilder.addRule(rule); return rule; } @@ -175,6 +199,7 @@ public class RuleFactory { * @param ast the abstract syntax tree of the rule expression (mandatory because this looks up a * {@link Location} from the {@code ast}) * @param env the lexical environment of the function call which declared this rule (optional) + * @param attributeContainer the {@link AttributeContainer} the rule will contain * @throws InvalidRuleException if the rule could not be constructed for any reason (e.g. no * {@code name} attribute is defined) * @throws NameConflictException if the rule's name or output files conflict with others in this @@ -186,7 +211,8 @@ public class RuleFactory { RuleClass ruleClass, BuildLangTypedAttributeValuesMap attributeValues, FuncallExpression ast, - @Nullable Environment env) + @Nullable Environment env, + AttributeContainer attributeContainer) throws InvalidRuleException, NameConflictException, InterruptedException { return createAndAddRule( context.pkgBuilder, @@ -195,7 +221,8 @@ public class RuleFactory { context.eventHandler, ast, ast.getLocation(), - env); + env, + attributeContainer); } /** diff --git a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java index f8d885fc01..6df9f05411 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java +++ b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java @@ -329,11 +329,11 @@ public class WorkspaceFactory { ruleClass, nameLabel, actual == null ? null : Label.parseAbsolute(actual), - ast.getLocation()); - } catch ( - RuleFactory.InvalidRuleException | Package.NameConflictException - | LabelSyntaxException - e) { + ast.getLocation(), + ruleFactory.getAttributeContainer(ruleClass)); + } catch (RuleFactory.InvalidRuleException + | Package.NameConflictException + | LabelSyntaxException e) { throw new EvalException(ast.getLocation(), e.getMessage()); } @@ -390,7 +390,8 @@ public class WorkspaceFactory { private static ImmutableMap createWorkspaceFunctions( RuleClassProvider ruleClassProvider, boolean allowOverride) { ImmutableMap.Builder mapBuilder = ImmutableMap.builder(); - RuleFactory ruleFactory = new RuleFactory(ruleClassProvider); + RuleFactory ruleFactory = + new RuleFactory(ruleClassProvider, AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY); mapBuilder.put(BIND, newBindFunction(ruleFactory)); for (String ruleClass : ruleFactory.getRuleClassNames()) { if (!ruleClass.equals(BIND)) { @@ -421,7 +422,8 @@ public class WorkspaceFactory { } workspaceEnv.setupDynamic( PackageFactory.PKG_CONTEXT, - new PackageFactory.PackageContext(builder, null, localReporter)); + new PackageFactory.PackageContext( + builder, null, localReporter, AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY)); } catch (EvalException e) { throw new AssertionError(e); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java index c8c0c86494..3898b60ef2 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java @@ -531,7 +531,13 @@ public class SkylarkRuleClassFunctions { PackageContext pkgContext = (PackageContext) env.lookup(PackageFactory.PKG_CONTEXT); BuildLangTypedAttributeValuesMap attributeValues = new BuildLangTypedAttributeValuesMap((Map) args[0]); - return RuleFactory.createAndAddRule(pkgContext, ruleClass, attributeValues, ast, env); + return RuleFactory.createAndAddRule( + pkgContext, + ruleClass, + attributeValues, + ast, + env, + pkgContext.getAttributeContainerFactory().apply(ruleClass)); } catch (InvalidRuleException | NameConflictException | NoSuchVariableException e) { throw new EvalException(ast.getLocation(), e.getMessage()); } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java index 0037fd0d2f..25f692a723 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.runtime; +import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -25,9 +26,11 @@ import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; import com.google.devtools.build.lib.analysis.WorkspaceStatusAction; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.exec.OutputService; +import com.google.devtools.build.lib.packages.AttributeContainer; import com.google.devtools.build.lib.packages.NoSuchThingException; import com.google.devtools.build.lib.packages.PackageFactory; import com.google.devtools.build.lib.packages.Preprocessor; +import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.query2.AbstractBlazeQueryEnvironment; import com.google.devtools.build.lib.query2.QueryEnvironmentFactory; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction; @@ -188,6 +191,11 @@ public abstract class BlazeModule { return ImmutableList.of(); } + @Nullable + protected Function getAttributeContainerSupplier() { + return null; + } + /** * Services provided for Blaze modules via BlazeRuntime. */ diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java index 58f09d8ce5..250e2942df 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java @@ -37,8 +37,10 @@ import com.google.devtools.build.lib.analysis.config.ConfigurationFactory; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.OutputFilter; import com.google.devtools.build.lib.flags.CommandNameCache; +import com.google.devtools.build.lib.packages.AttributeContainer; import com.google.devtools.build.lib.packages.PackageFactory; import com.google.devtools.build.lib.packages.Preprocessor; +import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleClassProvider; import com.google.devtools.build.lib.profiler.AutoProfiler; import com.google.devtools.build.lib.profiler.MemoryProfiler; @@ -1217,6 +1219,23 @@ public final class BlazeRuntime { } } + Function attributeContainerFactory = null; + for (BlazeModule module : blazeModules) { + Function attrContainerFactory = + module.getAttributeContainerSupplier(); + if (attrContainerFactory != null) { + Preconditions.checkState( + attributeContainerFactory == null, + "At most one attribute container supplier supported. But found two: %s and %s", + attrContainerFactory, + attributeContainerFactory); + attributeContainerFactory = attrContainerFactory; + } + } + if (attributeContainerFactory == null) { + attributeContainerFactory = AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY; + } + ConfiguredRuleClassProvider ruleClassProvider = ruleClassBuilder.build(); List extensions = new ArrayList<>(); @@ -1224,8 +1243,13 @@ public final class BlazeRuntime { extensions.add(module.getPackageEnvironmentExtension()); } - PackageFactory packageFactory = new PackageFactory( - ruleClassProvider, platformRegexps, extensions, BlazeVersionInfo.instance().getVersion()); + PackageFactory packageFactory = + new PackageFactory( + ruleClassProvider, + platformRegexps, + attributeContainerFactory, + extensions, + BlazeVersionInfo.instance().getVersion()); if (configurationFactory == null) { configurationFactory = new ConfigurationFactory( 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 28a887f01d..03b9e8676e 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 @@ -16,6 +16,7 @@ package com.google.devtools.build.lib.analysis.config; import static org.junit.Assert.assertEquals; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; +import com.google.devtools.build.lib.packages.AttributeContainer; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleFactory; @@ -37,7 +38,10 @@ public class StampTest extends BuildViewTestCase { */ @Test public void testNoStampingForTests() throws Exception { - RuleFactory ruleFactory = new RuleFactory(TestRuleClassProvider.getRuleClassProvider()); + RuleFactory ruleFactory = + new RuleFactory( + TestRuleClassProvider.getRuleClassProvider(), + AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY); for (String name : ruleFactory.getRuleClassNames()) { RuleClass ruleClass = ruleFactory.getRuleClass(name); if (TargetUtils.isTestRuleName(name) && ruleClass.hasAttr("stamp", BuildType.TRISTATE)) { diff --git a/src/test/java/com/google/devtools/build/lib/packages/RuleFactoryTest.java b/src/test/java/com/google/devtools/build/lib/packages/RuleFactoryTest.java index 6c10d46603..a716e22f8a 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/RuleFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/packages/RuleFactoryTest.java @@ -44,7 +44,8 @@ import java.util.Map; public class RuleFactoryTest extends PackageLoadingTestCase { private ConfiguredRuleClassProvider provider = TestRuleClassProvider.getRuleClassProvider(); - private RuleFactory ruleFactory = new RuleFactory(provider); + private RuleFactory ruleFactory = + new RuleFactory(provider, AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY); public static final Location LOCATION_42 = Location.fromFileAndOffsets(null, 42, 42); @@ -60,15 +61,17 @@ public class RuleFactoryTest extends PackageLoadingTestCase { attributeValues.put("name", "foo"); attributeValues.put("alwayslink", true); + RuleClass ruleClass = provider.getRuleClassMap().get("cc_library"); Rule rule = RuleFactory.createAndAddRule( pkgBuilder, - provider.getRuleClassMap().get("cc_library"), + ruleClass, new BuildLangTypedAttributeValuesMap(attributeValues), new Reporter(), /*ast=*/ null, LOCATION_42, - /*env=*/ null); + /*env=*/ null, + new AttributeContainer(ruleClass)); assertSame(rule, rule.getAssociatedRule()); @@ -119,15 +122,17 @@ public class RuleFactoryTest extends PackageLoadingTestCase { attributeValues.put("name", "foo"); attributeValues.put("actual", "//foo:bar"); + RuleClass ruleClass = provider.getRuleClassMap().get("bind"); Rule rule = RuleFactory.createAndAddRule( pkgBuilder, - provider.getRuleClassMap().get("bind"), + ruleClass, new BuildLangTypedAttributeValuesMap(attributeValues), new Reporter(), /*ast=*/ null, Location.fromFileAndOffsets(myPkgPath.asFragment(), 42, 42), - /*env=*/ null); + /*env=*/ null, + new AttributeContainer(ruleClass)); assertFalse(rule.containsErrors()); } @@ -143,15 +148,17 @@ public class RuleFactoryTest extends PackageLoadingTestCase { attributeValues.put("name", "foo"); attributeValues.put("actual", "//bar:baz"); + RuleClass ruleClass = provider.getRuleClassMap().get("bind"); try { RuleFactory.createAndAddRule( pkgBuilder, - provider.getRuleClassMap().get("bind"), + ruleClass, new BuildLangTypedAttributeValuesMap(attributeValues), new Reporter(), /*ast=*/ null, LOCATION_42, - /*env=*/ null); + /*env=*/ null, + new AttributeContainer(ruleClass)); fail(); } catch (RuleFactory.InvalidRuleException e) { assertThat(e.getMessage()).contains("must be in the WORKSPACE file"); @@ -170,15 +177,17 @@ public class RuleFactoryTest extends PackageLoadingTestCase { attributeValues.put("name", "foo"); attributeValues.put("alwayslink", true); + RuleClass ruleClass = provider.getRuleClassMap().get("cc_library"); try { RuleFactory.createAndAddRule( pkgBuilder, - provider.getRuleClassMap().get("cc_library"), + ruleClass, new BuildLangTypedAttributeValuesMap(attributeValues), new Reporter(), /*ast=*/ null, Location.fromFileAndOffsets(myPkgPath.asFragment(), 42, 42), - /*env=*/ null); + /*env=*/ null, + new AttributeContainer(ruleClass)); fail(); } catch (RuleFactory.InvalidRuleException e) { assertThat(e.getMessage()).contains("cannot be in the WORKSPACE file"); @@ -208,15 +217,17 @@ public class RuleFactoryTest extends PackageLoadingTestCase { Map attributeValues = new HashMap<>(); attributeValues.put("outs", Lists.newArrayList(".")); attributeValues.put("name", "some"); + RuleClass ruleClass = provider.getRuleClassMap().get("genrule"); try { RuleFactory.createAndAddRule( pkgBuilder, - provider.getRuleClassMap().get("genrule"), + ruleClass, new BuildLangTypedAttributeValuesMap(attributeValues), new Reporter(), /*ast=*/ null, Location.fromFileAndOffsets(myPkgPath.asFragment(), 42, 42), - /*env=*/ null); + /*env=*/ null, + new AttributeContainer(ruleClass)); fail(); } catch (RuleFactory.InvalidRuleException e) { assertTrue(e.getMessage(), e.getMessage().contains("output file name can't be equal '.'")); diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java b/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java index d3c99a43fe..2a18f26647 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java @@ -19,6 +19,7 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; +import com.google.devtools.build.lib.packages.AttributeContainer; import com.google.devtools.build.lib.packages.CachingPackageLocator; import com.google.devtools.build.lib.packages.ConstantRuleVisibility; import com.google.devtools.build.lib.packages.GlobCache; @@ -50,8 +51,13 @@ public class PackageFactoryApparatus { EventHandler eventHandler, PackageFactory.EnvironmentExtension... environmentExtensions) { this.eventHandler = eventHandler; RuleClassProvider ruleClassProvider = TestRuleClassProvider.getRuleClassProvider(); - factory = new PackageFactory(ruleClassProvider, null, - ImmutableList.copyOf(environmentExtensions), "test"); + factory = + new PackageFactory( + ruleClassProvider, + null, + AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY, + ImmutableList.copyOf(environmentExtensions), + "test"); } /** diff --git a/src/test/java/com/google/devtools/build/lib/skylark/util/SkylarkTestCase.java b/src/test/java/com/google/devtools/build/lib/skylark/util/SkylarkTestCase.java index c19af161a0..cf17c9dbb3 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/util/SkylarkTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/util/SkylarkTestCase.java @@ -64,7 +64,7 @@ public abstract class SkylarkTestCase extends BuildViewTestCase { PackageFactory.PKG_CONTEXT, // This dummy pkgContext works because no Skylark unit test attempts to actually // create rules. Creating actual rules is tested in SkylarkIntegrationTest. - new PackageContext(null, null, getEventHandler())); + new PackageContext(null, null, getEventHandler(), null)); } }; } -- cgit v1.2.3