diff options
author | 2018-05-02 06:07:26 -0700 | |
---|---|---|
committer | 2018-05-02 06:08:57 -0700 | |
commit | 2f0153d4361e90654ee09d90201f6409c061964f (patch) | |
tree | c7498877ca334a8fa7d8761dd406cabfc1d8d814 /src/main/java | |
parent | fa26e6e89d3c733cdf4524075f7347328da36cb2 (diff) |
Add JavaHostRuntimeAlias. Migrate JavaRuntimeAlias and JavaToolchainAlias to use base class CommonAliasRule.
RELNOTES[NEW]: The java_host_runtime_alias rule is now implemented in Java.
PiperOrigin-RevId: 195081632
Diffstat (limited to 'src/main/java')
7 files changed, 104 insertions, 167 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index 13ad5af5b8..82bf157c47 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -862,6 +862,7 @@ java_library( "rules/java/JavaBinary.java", "rules/java/JavaCcLinkParamsProvider.java", "rules/java/JavaConfigurationLoader.java", + "rules/java/JavaHostRuntimeAliasRule.java", "rules/java/JavaImport.java", "rules/java/JavaImportBaseRule.java", "rules/java/JavaInfo.java", @@ -871,7 +872,7 @@ java_library( "rules/java/JavaPlugin.java", "rules/java/JavaPrimaryClassProvider.java", "rules/java/JavaRuntime.java", - "rules/java/JavaRuntimeAlias.java", + "rules/java/JavaRuntimeAliasRule.java", "rules/java/JavaRuntimeClasspathProvider.java", "rules/java/JavaRuntimeRule.java", "rules/java/JavaRuntimeSuite.java", @@ -879,7 +880,7 @@ java_library( "rules/java/JavaSkylarkCommon.java", "rules/java/JavaSourceInfoProvider.java", "rules/java/JavaToolchain.java", - "rules/java/JavaToolchainAlias.java", + "rules/java/JavaToolchainAliasRule.java", "rules/java/JavaToolchainRule.java", "rules/java/JavaToolchainSkylarkApiProvider.java", "rules/java/ProguardHelper.java", diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/JavaRules.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/JavaRules.java index 05167303c8..7da470d40a 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/JavaRules.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/JavaRules.java @@ -29,16 +29,17 @@ import com.google.devtools.build.lib.rules.core.CoreRules; import com.google.devtools.build.lib.rules.extra.ActionListenerRule; import com.google.devtools.build.lib.rules.extra.ExtraActionRule; import com.google.devtools.build.lib.rules.java.JavaConfigurationLoader; +import com.google.devtools.build.lib.rules.java.JavaHostRuntimeAliasRule; import com.google.devtools.build.lib.rules.java.JavaImportBaseRule; import com.google.devtools.build.lib.rules.java.JavaInfo; import com.google.devtools.build.lib.rules.java.JavaOptions; import com.google.devtools.build.lib.rules.java.JavaPackageConfigurationRule; import com.google.devtools.build.lib.rules.java.JavaRuleClasses.IjarBaseRule; -import com.google.devtools.build.lib.rules.java.JavaRuntimeAlias; +import com.google.devtools.build.lib.rules.java.JavaRuntimeAliasRule; import com.google.devtools.build.lib.rules.java.JavaRuntimeRule; import com.google.devtools.build.lib.rules.java.JavaRuntimeSuiteRule; import com.google.devtools.build.lib.rules.java.JavaSkylarkCommon; -import com.google.devtools.build.lib.rules.java.JavaToolchainAlias; +import com.google.devtools.build.lib.rules.java.JavaToolchainAliasRule; import com.google.devtools.build.lib.rules.java.JavaToolchainRule; import com.google.devtools.build.lib.rules.java.ProguardLibraryRule; import com.google.devtools.build.lib.rules.java.proto.JavaProtoSkylarkCommon; @@ -77,8 +78,9 @@ public class JavaRules implements RuleSet { builder.addRuleDefinition(new JavaPackageConfigurationRule()); builder.addRuleDefinition(new JavaRuntimeRule()); builder.addRuleDefinition(new JavaRuntimeSuiteRule()); - builder.addRuleDefinition(new JavaRuntimeAlias.JavaRuntimeAliasRule()); - builder.addRuleDefinition(new JavaToolchainAlias.JavaToolchainAliasRule()); + builder.addRuleDefinition(new JavaRuntimeAliasRule()); + builder.addRuleDefinition(new JavaHostRuntimeAliasRule()); + builder.addRuleDefinition(new JavaToolchainAliasRule()); builder.addRuleDefinition(new ExtraActionRule()); builder.addRuleDefinition(new ActionListenerRule()); diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHostRuntimeAliasRule.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHostRuntimeAliasRule.java new file mode 100644 index 0000000000..c1dcc7649f --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHostRuntimeAliasRule.java @@ -0,0 +1,36 @@ +// Copyright 2017 The Bazel Authors. 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.rules.java; + +import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; +import com.google.devtools.build.lib.analysis.config.HostTransition; +import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.packages.Attribute; +import com.google.devtools.build.lib.rules.LateBoundAlias.CommonAliasRule; + +/** Implementation of the {@code java_runtime_alias} rule. */ +public class JavaHostRuntimeAliasRule extends CommonAliasRule { + public JavaHostRuntimeAliasRule() { + super("java_host_runtime_alias", JavaSemantics::hostJdkAttribute, JavaConfiguration.class); + } + + @Override + protected Attribute.Builder<Label> makeAttribute(RuleDefinitionEnvironment environment) { + Attribute.Builder<Label> builder = super.makeAttribute(environment); + return builder + .cfg(HostTransition.INSTANCE) + .mandatoryProviders(JavaRuntimeInfo.PROVIDER.id()); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeAlias.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeAlias.java deleted file mode 100644 index 181e8106aa..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeAlias.java +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2017 The Bazel Authors. 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.rules.java; - -import static com.google.devtools.build.lib.packages.Attribute.attr; -import static com.google.devtools.build.lib.packages.BuildType.LABEL; - -import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; -import com.google.devtools.build.lib.analysis.BaseRuleClasses; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.FileProvider; -import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; -import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.RuleDefinition; -import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; -import com.google.devtools.build.lib.analysis.RunfilesProvider; -import com.google.devtools.build.lib.analysis.TemplateVariableInfo; -import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; -import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.packages.RuleClass; - -/** - * Implementation of the {@code java_runtime_alias} rule. - */ -public class JavaRuntimeAlias implements RuleConfiguredTargetFactory { - - @Override - public ConfiguredTarget create(RuleContext ruleContext) - throws InterruptedException, RuleErrorException, ActionConflictException { - // Sadly, we can't use an AliasConfiguredTarget here because we need to be prepared for the case - // when --javabase is not a label. For the time being. - TransitiveInfoCollection runtime = ruleContext.getPrerequisite(":jvm", Mode.TARGET); - JavaRuntimeInfo javaRuntimeInfo = JavaRuntimeInfo.from(runtime, ruleContext); - return new RuleConfiguredTargetBuilder(ruleContext) - .addNativeDeclaredProvider(javaRuntimeInfo) - .addNativeDeclaredProvider(new JavaRuntimeToolchainInfo(javaRuntimeInfo)) - .addNativeDeclaredProvider(runtime.get(TemplateVariableInfo.PROVIDER)) - .addProvider(RunfilesProvider.class, runtime.getProvider(RunfilesProvider.class)) - .setFilesToBuild(runtime.getProvider(FileProvider.class).getFilesToBuild()) - .build(); - } - - /** - * Rule definition for the {@code java_runtime_alias} rule. - */ - public static class JavaRuntimeAliasRule implements RuleDefinition { - - @Override - public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) { - return builder - .requiresConfigurationFragments(JavaConfiguration.class) - .removeAttribute("licenses") - .removeAttribute("distribs") - .add(attr(":jvm", LABEL) - .value(JavaSemantics.jvmAttribute(environment)) - .mandatoryProviders(JavaRuntimeInfo.PROVIDER.id())) - .build(); - } - - @Override - public Metadata getMetadata() { - return Metadata.builder() - .name("java_runtime_alias") - .ancestors(BaseRuleClasses.BaseRule.class) - .factoryClass(JavaRuntimeAlias.class) - .build(); - } - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeAliasRule.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeAliasRule.java new file mode 100644 index 0000000000..239e92ec70 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeAliasRule.java @@ -0,0 +1,33 @@ +// Copyright 2017 The Bazel Authors. 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.rules.java; + +import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; +import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.packages.Attribute; +import com.google.devtools.build.lib.rules.LateBoundAlias.CommonAliasRule; + +/** Implementation of the {@code java_runtime_alias} rule. */ +public class JavaRuntimeAliasRule extends CommonAliasRule { + public JavaRuntimeAliasRule() { + super("java_runtime_alias", JavaSemantics::jvmAttribute, JavaConfiguration.class); + } + + @Override + protected Attribute.Builder<Label> makeAttribute(RuleDefinitionEnvironment environment) { + Attribute.Builder<Label> builder = super.makeAttribute(environment); + return builder.mandatoryProviders(JavaRuntimeInfo.PROVIDER.id()); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainAlias.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainAlias.java deleted file mode 100644 index ff12fc1f43..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainAlias.java +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2017 The Bazel Authors. 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.rules.java; - -import static com.google.devtools.build.lib.packages.Attribute.attr; -import static com.google.devtools.build.lib.packages.BuildType.LABEL; - -import com.google.common.collect.ImmutableMap; -import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; -import com.google.devtools.build.lib.analysis.AliasProvider; -import com.google.devtools.build.lib.analysis.BaseRuleClasses; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.RuleDefinition; -import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; -import com.google.devtools.build.lib.analysis.VisibilityProvider; -import com.google.devtools.build.lib.analysis.VisibilityProviderImpl; -import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.packages.RuleClass; -import com.google.devtools.build.lib.rules.AliasConfiguredTarget; - -/** - * Implementation of the {@code java_toolchain_alias} rule. - */ -public class JavaToolchainAlias implements RuleConfiguredTargetFactory { - - @Override - public ConfiguredTarget create(RuleContext ruleContext) - throws InterruptedException, RuleErrorException, ActionConflictException { - ConfiguredTarget actual = - (ConfiguredTarget) ruleContext.getPrerequisite(":java_toolchain", Mode.TARGET); - return new AliasConfiguredTarget( - ruleContext, - actual, - ImmutableMap.of( - AliasProvider.class, - AliasProvider.fromAliasRule(ruleContext.getLabel(), actual), - VisibilityProvider.class, - new VisibilityProviderImpl(ruleContext.getVisibility()))); - } - - /** - * Rule definition for the {@code java_toolchain_alias} rule. - */ - public static class JavaToolchainAliasRule implements RuleDefinition { - - @Override - public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) { - return builder - .requiresConfigurationFragments(JavaConfiguration.class) - .removeAttribute("licenses") - .removeAttribute("distribs") - .add(attr(":java_toolchain", LABEL).value(JavaSemantics.JAVA_TOOLCHAIN)) - .build(); - } - - @Override - public Metadata getMetadata() { - return Metadata.builder() - .name("java_toolchain_alias") - .ancestors(BaseRuleClasses.BaseRule.class) - .factoryClass(JavaToolchainAlias.class) - .build(); - } - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainAliasRule.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainAliasRule.java new file mode 100644 index 0000000000..feca01c85a --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainAliasRule.java @@ -0,0 +1,26 @@ +// Copyright 2017 The Bazel Authors. 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.rules.java; + +import com.google.devtools.build.lib.rules.LateBoundAlias.CommonAliasRule; + +/** + * Implementation of the {@code java_toolchain_alias} rule. + */ +public class JavaToolchainAliasRule extends CommonAliasRule{ + public JavaToolchainAliasRule() { + super("java_toolchain_alias", env -> JavaSemantics.JAVA_TOOLCHAIN, JavaConfiguration.class); + } +} |