Skip to content

Commit

Permalink
Replace the native Java host runtime alias rule with a starlark imple…
Browse files Browse the repository at this point in the history
…mentation

in preparation for adding toolchain resolution support for the starlark
rules, and eventually removing them once the migration to toolchain
resolution is complete.

PiperOrigin-RevId: 233962397
  • Loading branch information
cushon authored and Copybara-Service committed Feb 15, 2019
1 parent a5819a1 commit 62c7aa4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.google.devtools.build.lib.rules.extra.ExtraActionRule;
import com.google.devtools.build.lib.rules.java.JavaCcLinkParamsProvider;
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;
Expand Down Expand Up @@ -83,7 +82,6 @@ public void init(ConfiguredRuleClassProvider.Builder builder) {
builder.addRuleDefinition(new JavaPackageConfigurationRule());
builder.addRuleDefinition(new JavaRuntimeRule());
builder.addRuleDefinition(new JavaRuntimeAliasRule());
builder.addRuleDefinition(new JavaHostRuntimeAliasRule());
builder.addRuleDefinition(new JavaToolchainAliasRule());

builder.addRuleDefinition(new ExtraActionRule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ java_library(
"JavaBinary.java",
"JavaCcLinkParamsProvider.java",
"JavaConfigurationLoader.java",
"JavaHostRuntimeAliasRule.java",
"JavaImport.java",
"JavaImportBaseRule.java",
"JavaInfo.java",
Expand Down

This file was deleted.

4 changes: 4 additions & 0 deletions src/test/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,9 @@ java_library(
],
exclude = ["analysis/util/DefaultBuildOptionsForTesting.java"],
),
data = [
"//tools/jdk:srcs",
],
resources = [
"analysis/mock/MOCK_CROSSTOOL",
],
Expand Down Expand Up @@ -692,6 +695,7 @@ java_library(
"//third_party:jsr305",
"//third_party:mockito",
"//third_party/protobuf:protobuf_java",
"@bazel_tools//tools/java/runfiles",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
// limitations under the License.
package com.google.devtools.build.lib.analysis.mock;

import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.io.MoreFiles;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
import com.google.devtools.build.lib.analysis.PlatformConfigurationLoader;
import com.google.devtools.build.lib.analysis.ShellConfiguration;
Expand Down Expand Up @@ -46,8 +49,12 @@
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.runfiles.Runfiles;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/** Subclass of {@link AnalysisMock} using Bazel-specific semantics. */
Expand Down Expand Up @@ -92,8 +99,19 @@ public void setupMockClient(MockToolsConfig config, List<String> workspaceConten
config.create("/protobuf/WORKSPACE");
config.overwrite("WORKSPACE", workspaceContents.toArray(new String[workspaceContents.size()]));
config.create("/bazel_tools_workspace/WORKSPACE", "workspace(name = 'bazel_tools')");
Runfiles runfiles = Runfiles.create();
for (String filename :
Arrays.asList("tools/jdk/toolchain_utils.bzl", "tools/jdk/java_toolchain_alias.bzl")) {
java.nio.file.Path path = Paths.get(runfiles.rlocation("io_bazel/" + filename));
if (!Files.exists(path)) {
continue; // the io_bazel workspace root only exists for Bazel
}
config.create(
"/bazel_tools_workspace/" + filename, MoreFiles.asCharSource(path, UTF_8).read());
}
config.create(
"/bazel_tools_workspace/tools/jdk/BUILD",
"load(':java_toolchain_alias.bzl', 'java_host_runtime_alias')",
"package(default_visibility=['//visibility:public'])",
"java_toolchain(",
" name = 'toolchain',",
Expand Down Expand Up @@ -368,3 +386,4 @@ public void addExtraRepositoryFunctions(
repositoryHandlers.put(LocalConfigPlatformRule.NAME, new LocalConfigPlatformFunction());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ public final void setupSkylarkRule() throws Exception {
scratch.file(RULE_DIRECTORY + "/" + file.getName(), Files.readAllBytes(file.toPath()));
}
scratch.file(RULE_DIRECTORY + "/BUILD", "exports_files(['java_lite_proto_library.bzl'])");
scratch.file(
"tools/jdk/build_defs.bzl",
Files.readAllBytes(Runfiles.location("tools/jdk/build_defs.bzl").toPath()));
scratch.file(
"tools/jdk/toolchain_utils.bzl",
Files.readAllBytes(Runfiles.location("tools/jdk/toolchain_utils.bzl").toPath()));
invalidatePackages();
}

Expand Down

0 comments on commit 62c7aa4

Please sign in to comment.