diff options
author | Damien Martin-Guillerez <dmarting@google.com> | 2016-05-06 09:25:21 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2016-05-06 09:35:27 +0000 |
commit | cda4b4eae0c495a8f90f2a70a8db46e34062ee26 (patch) | |
tree | 1de10e0c9f937be58f8ff6e8fae5ac942115f059 /src/main/java/com | |
parent | 8a142fef810435ca0f45b410e67c3a6b29919c75 (diff) |
Rollback of commit 178a3dfda8bf72abf22758597a90a4afb8eed181.
*** Reason for rollback ***
Broke ci.bazel.io.
See #1234.
*** Original change description ***
Allow modules to inject a custom AttributeContainer.
--
MOS_MIGRATED_REVID=121658474
Diffstat (limited to 'src/main/java/com')
8 files changed, 35 insertions, 171 deletions
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 8c5bfffaa6..15917f6b8b 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,7 +13,6 @@ // 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; @@ -47,7 +46,7 @@ public class AttributeContainer { /** * Create a container for a rule of the given rule class. */ - public AttributeContainer(RuleClass ruleClass) { + AttributeContainer(RuleClass ruleClass) { this(ruleClass, new Location[ruleClass.getAttributeCount()]); } @@ -118,12 +117,4 @@ public class AttributeContainer { Integer index = ruleClass.getAttributeIndex(attribute.getName()); attributeLocations[index] = location; } - - public static final Function<RuleClass, AttributeContainer> ATTRIBUTE_CONTAINER_FACTORY = - new Function<RuleClass, AttributeContainer>() { - @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 91e6c06368..ebafff7355 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,7 +20,6 @@ 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; @@ -45,37 +44,19 @@ public class ExternalPackageBuilder { BuildLangTypedAttributeValuesMap attributeValues = new BuildLangTypedAttributeValuesMap(kwargs); Rule rule = RuleFactory.createRule( - pkg, - ruleClass, - attributeValues, - eventHandler, - ast, - ast.getLocation(), - /*env=*/ null, - new AttributeContainer(ruleClass)); + pkg, ruleClass, attributeValues, eventHandler, ast, ast.getLocation(), /*env=*/ null); pkg.addEvents(eventHandler.getEvents()); overwriteRule(pkg, rule); for (Map.Entry<String, Label> entry : ruleClass.getExternalBindingsFunction().apply(rule).entrySet()) { Label nameLabel = Label.parseAbsolute("//external:" + entry.getKey()); - addBindRule( - pkg, - bindRuleClass, - nameLabel, - entry.getValue(), - rule.getLocation(), - new AttributeContainer(ruleClass)); + addBindRule(pkg, bindRuleClass, nameLabel, entry.getValue(), rule.getLocation()); } return rule; } - void addBindRule( - Builder pkg, - RuleClass bindRuleClass, - Label virtual, - Label actual, - Location location, - AttributeContainer attributeContainer) + public void addBindRule( + Package.Builder pkg, RuleClass bindRuleClass, Label virtual, Label actual, Location location) throws RuleFactory.InvalidRuleException, Package.NameConflictException, InterruptedException { Map<String, Object> attributes = Maps.newHashMap(); @@ -90,14 +71,7 @@ public class ExternalPackageBuilder { new BuildLangTypedAttributeValuesMap(attributes); Rule rule = RuleFactory.createRule( - pkg, - bindRuleClass, - attributeValues, - handler, - /*ast=*/ null, - location, - /*env=*/ null, - attributeContainer); + pkg, bindRuleClass, attributeValues, handler, /*ast=*/ null, location, /*env=*/ null); 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 6dc557797c..048c30b60a 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,7 +15,6 @@ 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; @@ -332,48 +331,31 @@ public final class PackageFactory { */ @VisibleForTesting public PackageFactory(RuleClassProvider ruleClassProvider) { - this( - ruleClassProvider, - null, - AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY, - ImmutableList.<EnvironmentExtension>of(), - "test"); + this(ruleClassProvider, null, ImmutableList.<EnvironmentExtension>of(), "test"); } @VisibleForTesting public PackageFactory(RuleClassProvider ruleClassProvider, EnvironmentExtension environmentExtension) { - this( - ruleClassProvider, - null, - AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY, - ImmutableList.of(environmentExtension), - "test"); + this(ruleClassProvider, null, ImmutableList.of(environmentExtension), "test"); } @VisibleForTesting public PackageFactory(RuleClassProvider ruleClassProvider, Iterable<EnvironmentExtension> environmentExtensions) { - this( - ruleClassProvider, - null, - AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY, - environmentExtensions, - "test"); + this(ruleClassProvider, null, 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<String, String> platformSetRegexps, - Function<RuleClass, AttributeContainer> attributeContainerFactory, Iterable<EnvironmentExtension> environmentExtensions, String version) { this.platformSetRegexps = platformSetRegexps; - this.ruleFactory = new RuleFactory(ruleClassProvider, attributeContainerFactory); + this.ruleFactory = new RuleFactory(ruleClassProvider); this.ruleClassProvider = ruleClassProvider; threadPool = new ThreadPoolExecutor(100, 100, 15L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), @@ -1120,8 +1102,7 @@ public final class PackageFactory { throws RuleFactory.InvalidRuleException, Package.NameConflictException, InterruptedException { RuleClass ruleClass = getBuiltInRuleClass(ruleClassName, ruleFactory); BuildLangTypedAttributeValuesMap attributeValues = new BuildLangTypedAttributeValuesMap(kwargs); - AttributeContainer attributeContainer = ruleFactory.getAttributeContainer(ruleClass); - RuleFactory.createAndAddRule(context, ruleClass, attributeValues, ast, env, attributeContainer); + RuleFactory.createAndAddRule(context, ruleClass, attributeValues, ast, env); } private static RuleClass getBuiltInRuleClass(String ruleClassName, RuleFactory ruleFactory) { @@ -1393,21 +1374,17 @@ 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<RuleClass, AttributeContainer> attributeContainerFactory; @VisibleForTesting - public PackageContext( - Package.LegacyBuilder pkgBuilder, - Globber globber, - EventHandler eventHandler, - Function<RuleClass, AttributeContainer> attributeContainerFactory) { + public PackageContext(Package.LegacyBuilder pkgBuilder, Globber globber, + EventHandler eventHandler) { this.pkgBuilder = pkgBuilder; this.eventHandler = eventHandler; this.globber = globber; - this.attributeContainerFactory = attributeContainerFactory; } /** @@ -1430,10 +1407,6 @@ public final class PackageFactory { public Package.Builder getBuilder() { return pkgBuilder; } - - public Function<RuleClass, AttributeContainer> getAttributeContainerFactory() { - return attributeContainerFactory; - } } private final ClassObject nativeModule; @@ -1548,9 +1521,7 @@ public final class PackageFactory { Event.replayEventsOn(eventHandler, pastEvents); // Stuff that closes over the package context: - PackageContext context = - new PackageContext( - pkgBuilder, globber, eventHandler, ruleFactory.getAttributeContainerFactory()); + PackageContext context = new PackageContext(pkgBuilder, globber, eventHandler); buildPkgEnv(pkgEnv, context, ruleFactory); pkgEnv.setupDynamic(PKG_CONTEXT, context); pkgEnv.setupDynamic(Runtime.PKG_NAME, packageId.getPackageFragment().getPathString()); @@ -1622,12 +1593,7 @@ public final class PackageFactory { .setDefaultVisibilitySet(false); // Stuff that closes over the package context: - PackageContext context = - new PackageContext( - pkgBuilder, - globber, - NullEventHandler.INSTANCE, - ruleFactory.getAttributeContainerFactory()); + PackageContext context = new PackageContext(pkgBuilder, globber, NullEventHandler.INSTANCE); 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 3b6cf4c904..4837b04763 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,7 +14,6 @@ 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; @@ -48,15 +47,11 @@ public class RuleFactory { * Maps rule class name to the metaclass instance for that rule. */ private final ImmutableMap<String, RuleClass> ruleClassMap; - private final Function<RuleClass, AttributeContainer> attributeContainerFactory; /** * Constructs a RuleFactory instance. */ - public RuleFactory( - RuleClassProvider provider, - Function<RuleClass, AttributeContainer> attributeContainerFactory) { - this.attributeContainerFactory = attributeContainerFactory; + public RuleFactory(RuleClassProvider provider) { this.ruleClassMap = ImmutableMap.copyOf(provider.getRuleClassMap()); } @@ -74,14 +69,6 @@ public class RuleFactory { return ruleClassMap.get(ruleClassName); } - AttributeContainer getAttributeContainer(RuleClass ruleClass) { - return attributeContainerFactory.apply(ruleClass); - } - - Function<RuleClass, AttributeContainer> getAttributeContainerFactory() { - return attributeContainerFactory; - } - /** * Creates and returns a rule instance. * @@ -95,8 +82,7 @@ public class RuleFactory { EventHandler eventHandler, @Nullable FuncallExpression ast, Location location, - @Nullable Environment env, - AttributeContainer attributeContainer) + @Nullable Environment env) throws InvalidRuleException, InterruptedException { Preconditions.checkNotNull(ruleClass); String ruleClassName = ruleClass.getName(); @@ -134,7 +120,7 @@ public class RuleFactory { eventHandler, ast, generator.location, - attributeContainer); + new AttributeContainer(ruleClass)); } catch (LabelSyntaxException e) { throw new RuleFactory.InvalidRuleException(ruleClass + " " + e.getMessage()); } @@ -155,7 +141,6 @@ 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 @@ -169,19 +154,10 @@ public class RuleFactory { EventHandler eventHandler, @Nullable FuncallExpression ast, Location location, - @Nullable Environment env, - AttributeContainer attributeContainer) + @Nullable Environment env) throws InvalidRuleException, NameConflictException, InterruptedException { - Rule rule = - createRule( - pkgBuilder, - ruleClass, - attributeValues, - eventHandler, - ast, - location, - env, - attributeContainer); + Rule rule = createRule( + pkgBuilder, ruleClass, attributeValues, eventHandler, ast, location, env); pkgBuilder.addRule(rule); return rule; } @@ -199,7 +175,6 @@ 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 @@ -211,8 +186,7 @@ public class RuleFactory { RuleClass ruleClass, BuildLangTypedAttributeValuesMap attributeValues, FuncallExpression ast, - @Nullable Environment env, - AttributeContainer attributeContainer) + @Nullable Environment env) throws InvalidRuleException, NameConflictException, InterruptedException { return createAndAddRule( context.pkgBuilder, @@ -221,8 +195,7 @@ public class RuleFactory { context.eventHandler, ast, ast.getLocation(), - env, - attributeContainer); + env); } /** 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 6df9f05411..f8d885fc01 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(), - ruleFactory.getAttributeContainer(ruleClass)); - } catch (RuleFactory.InvalidRuleException - | Package.NameConflictException - | LabelSyntaxException e) { + ast.getLocation()); + } catch ( + RuleFactory.InvalidRuleException | Package.NameConflictException + | LabelSyntaxException + e) { throw new EvalException(ast.getLocation(), e.getMessage()); } @@ -390,8 +390,7 @@ public class WorkspaceFactory { private static ImmutableMap<String, BaseFunction> createWorkspaceFunctions( RuleClassProvider ruleClassProvider, boolean allowOverride) { ImmutableMap.Builder<String, BaseFunction> mapBuilder = ImmutableMap.builder(); - RuleFactory ruleFactory = - new RuleFactory(ruleClassProvider, AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY); + RuleFactory ruleFactory = new RuleFactory(ruleClassProvider); mapBuilder.put(BIND, newBindFunction(ruleFactory)); for (String ruleClass : ruleFactory.getRuleClassNames()) { if (!ruleClass.equals(BIND)) { @@ -422,8 +421,7 @@ public class WorkspaceFactory { } workspaceEnv.setupDynamic( PackageFactory.PKG_CONTEXT, - new PackageFactory.PackageContext( - builder, null, localReporter, AttributeContainer.ATTRIBUTE_CONTAINER_FACTORY)); + new PackageFactory.PackageContext(builder, null, localReporter)); } 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 3898b60ef2..c8c0c86494 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,13 +531,7 @@ public class SkylarkRuleClassFunctions { PackageContext pkgContext = (PackageContext) env.lookup(PackageFactory.PKG_CONTEXT); BuildLangTypedAttributeValuesMap attributeValues = new BuildLangTypedAttributeValuesMap((Map<String, Object>) args[0]); - return RuleFactory.createAndAddRule( - pkgContext, - ruleClass, - attributeValues, - ast, - env, - pkgContext.getAttributeContainerFactory().apply(ruleClass)); + return RuleFactory.createAndAddRule(pkgContext, ruleClass, attributeValues, ast, env); } 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 25f692a723..0037fd0d2f 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,7 +13,6 @@ // 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; @@ -26,11 +25,9 @@ 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; @@ -191,11 +188,6 @@ public abstract class BlazeModule { return ImmutableList.of(); } - @Nullable - protected Function<RuleClass, AttributeContainer> 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 250e2942df..58f09d8ce5 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,10 +37,8 @@ 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; @@ -1219,23 +1217,6 @@ public final class BlazeRuntime { } } - Function<RuleClass, AttributeContainer> attributeContainerFactory = null; - for (BlazeModule module : blazeModules) { - Function<RuleClass, AttributeContainer> 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<PackageFactory.EnvironmentExtension> extensions = new ArrayList<>(); @@ -1243,13 +1224,8 @@ public final class BlazeRuntime { extensions.add(module.getPackageEnvironmentExtension()); } - PackageFactory packageFactory = - new PackageFactory( - ruleClassProvider, - platformRegexps, - attributeContainerFactory, - extensions, - BlazeVersionInfo.instance().getVersion()); + PackageFactory packageFactory = new PackageFactory( + ruleClassProvider, platformRegexps, extensions, BlazeVersionInfo.instance().getVersion()); if (configurationFactory == null) { configurationFactory = new ConfigurationFactory( |