Skip to content

Commit

Permalink
Migrate Android tests to use cc_toolchain_config rule instead of CROS…
Browse files Browse the repository at this point in the history
…STOOL file

Issue #5380

RELNOTES: None.
PiperOrigin-RevId: 240352653
  • Loading branch information
scentini authored and copybara-github committed Mar 26, 2019
1 parent 3f791e7 commit 8c0c57a
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 137 deletions.
5 changes: 4 additions & 1 deletion src/test/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ filegroup(
"//src/test/java/com/google/devtools/build/lib/buildeventstream:srcs",
"//src/test/java/com/google/devtools/build/lib/buildeventstream/transports:srcs",
"//src/test/java/com/google/devtools/build/lib/buildtool:srcs",
"//src/test/java/com/google/devtools/build/lib/packages/util/mock:srcs",
"//src/test/java/com/google/devtools/build/lib/profiler:srcs",
"//src/test/java/com/google/devtools/build/lib/profiler/callcounts:srcs",
"//src/test/java/com/google/devtools/build/lib/profiler/memory:srcs",
Expand Down Expand Up @@ -922,8 +923,10 @@ java_library(
"packages/util/*.java",
]),
resources = [
"packages/util/MOCK_ANDROID_CROSSTOOL",
"packages/util/MOCK_OSX_CROSSTOOL",
"//src/test/java/com/google/devtools/build/lib/packages/util/mock:android_cc_toolchain_config.bzl",
"//tools/build_defs/cc:action_names.bzl",
"//tools/cpp:cc_toolchain_config_lib.bzl",
"//tools/python:srcs",
],
deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
package com.google.devtools.build.lib.packages.util;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.util.ResourceFileLoader;
import com.google.devtools.build.lib.packages.util.Crosstool.CcToolchainConfig;
import com.google.devtools.build.lib.util.Pair;
import java.io.IOException;

/**
Expand All @@ -24,13 +25,63 @@
public class BazelMockAndroidSupport {

public static void setupNdk(MockToolsConfig config) throws IOException {
new Crosstool(config, "android/crosstool", /* disableCrosstool= */ false)
.setCrosstoolFile(
/*version=*/ "mock_version",
ResourceFileLoader.loadResource(
BazelMockAndroidSupport.class, "MOCK_ANDROID_CROSSTOOL"))
new Crosstool(config, "android/crosstool", /* disableCrosstool= */ true)
.setCcToolchainFile(
ResourceLoader.readFromResources(
"com/google/devtools/build/lib/packages/util/mock/android_cc_toolchain_config.bzl"))
.setToolchainConfigs(ImmutableList.of(x86Config().build(), armeabiV7a().build()))
.setSupportedArchs(ImmutableList.of("x86", "armeabi-v7a"))
.setSupportsHeaderParsing(false)
.write();
}

public static CcToolchainConfig.Builder x86Config() {
return CcToolchainConfig.builder()
.withCpu("x86")
.withCompiler("gcc")
.withToolchainIdentifier("x86")
.withHostSystemName("x86")
.withTargetSystemName("x86-linux-android")
.withTargetLibc("local")
.withAbiVersion("x86")
.withAbiLibcVersion("r7")
.withSysroot("")
.withToolPaths(
Pair.of("gcc", "x86/bin/i686-linux-android-gcc"),
Pair.of("ar", "x86/bin/i686-linux-android-ar"),
Pair.of("cpp", "x86/bin/i686-linux-android-cpp"),
Pair.of("gcov", "x86/bin/i686-linux-android-gcov"),
Pair.of("ld", "x86/bin/i686-linux-android-ld"),
Pair.of("nm", "x86/bin/i686-linux-android-nm"),
Pair.of("objcopy", "x86/bin/i686-linux-android-objcopy"),
Pair.of("objdump", "x86/bin/i686-linux-android-objdump"),
Pair.of("strip", "x86/bin/i686-linux-android-strip"),
Pair.of("ld-bfd", "x86/bin/i686-linux-android-ld.bfd"),
Pair.of("ld-gold", "x86/bin/i686-linux-android-ld.gold"));
}

public static CcToolchainConfig.Builder armeabiV7a() {
return CcToolchainConfig.builder()
.withCpu("armeabi-v7a")
.withCompiler("gcc")
.withToolchainIdentifier("armeabi-v7a")
.withHostSystemName("x86")
.withTargetSystemName("arm-linux-androideabi")
.withTargetLibc("local")
.withAbiVersion("armeabi-v7a")
.withAbiLibcVersion("r7")
.withSysroot("")
.withToolPaths(
Pair.of("gcc", "arm/bin/arm-linux-androideabi-gcc"),
Pair.of("ar", "arm/bin/arm-linux-androideabi-ar"),
Pair.of("cpp", "arm/bin/arm-linux-androideabi-cpp"),
Pair.of("gcov", "arm/bin/arm-linux-androideabi-gcov"),
Pair.of("ld", "arm/bin/arm-linux-androideabi-ld"),
Pair.of("nm", "arm/bin/arm-linux-androideabi-nm"),
Pair.of("objcopy", "arm/bin/arm-linux-androideabi-objcopy"),
Pair.of("objdump", "arm/bin/arm-linux-androideabi-objdump"),
Pair.of("strip", "arm/bin/arm-linux-androideabi-strip"),
Pair.of("ld-bfd", "arm/bin/arm-linux-androideabi-ld.bfd"),
Pair.of("ld-gold", "arm/bin/arm-linux-androideabi-ld.gold"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,54 @@ public static class Builder {
private ImmutableList<String> cxxBuiltinIncludeDirectories = ImmutableList.of();
private ImmutableList<Pair<String, String>> makeVariables = ImmutableList.of();
private String ccTargetOs = "";
private String cpu = "k8";
private String compiler = "compiler";
private String toolchainIdentifier = "mock-llvm-toolchain-k8";
private String hostSystemName = "local";
private String targetSystemName = "local";
private String targetLibc = "local";
private String abiVersion = "local";
private String abiLibcVersion = "local";

public Builder withCpu(String cpu) {
this.cpu = cpu;
return this;
}

public Builder withCompiler(String compiler) {
this.compiler = compiler;
return this;
}

public Builder withToolchainIdentifier(String toolchainIdentifier) {
this.toolchainIdentifier = toolchainIdentifier;
return this;
}

public Builder withHostSystemName(String hostSystemName) {
this.hostSystemName = hostSystemName;
return this;
}

public Builder withTargetSystemName(String targetSystemName) {
this.targetSystemName = targetSystemName;
return this;
}

public Builder withTargetLibc(String targetLibc) {
this.targetLibc = targetLibc;
return this;
}

public Builder withAbiVersion(String abiVersion) {
this.abiVersion = abiVersion;
return this;
}

public Builder withAbiLibcVersion(String abiLibcVersion) {
this.abiLibcVersion = abiLibcVersion;
return this;
}

public Builder withFeatures(String... features) {
this.features = ImmutableList.copyOf(features);
Expand Down Expand Up @@ -158,16 +206,16 @@ public Builder withMakeVariables(Pair<String, String>... makeVariables) {

public CcToolchainConfig build() {
return new CcToolchainConfig(
/* cpu= */ "k8",
/* compiler= */ "compiler",
/* toolchainIdentifier= */ "mock-llvm-toolchain-k8",
/* hostSystemName= */ "local",
/* targetSystemName= */ "local",
/* abiVersion= */ "local",
/* abiLibcVersion= */ "local",
/* targetLibc= */ "local",
/* builtinSysroot= */ builtinSysroot,
/* ccTargetOs= */ ccTargetOs,
cpu,
compiler,
toolchainIdentifier,
hostSystemName,
targetSystemName,
abiVersion,
abiLibcVersion,
targetLibc,
builtinSysroot,
ccTargetOs,
features,
actionConfigs,
artifactNamePatterns,
Expand Down Expand Up @@ -280,9 +328,10 @@ public String getCcToolchainConfigRule() {
private final String crosstoolTop;
private String version;
private String crosstoolFileContents;
private String ccToolchainConfigFileContents;
private ImmutableList<String> archs;
private boolean supportsHeaderParsing;
private ImmutableList<CcToolchainConfig> ccToolchainConfigList;
private ImmutableList<CcToolchainConfig> ccToolchainConfigList = ImmutableList.of();
private final boolean disableCrosstool;

Crosstool(MockToolsConfig config, String crosstoolTop, boolean disableCrosstool) {
Expand All @@ -297,6 +346,11 @@ public Crosstool setCrosstoolFile(String version, String crosstoolFileContents)
return this;
}

public Crosstool setCcToolchainFile(String ccToolchainConfigFileContents) {
this.ccToolchainConfigFileContents = ccToolchainConfigFileContents;
return this;
}

public Crosstool setSupportedArchs(ImmutableList<String> archs) {
this.archs = archs;
return this;
Expand Down Expand Up @@ -486,10 +540,7 @@ public void write() throws IOException {
config.create(crosstoolTop + "/" + version + "/x86/bin/ld");
config.overwrite(crosstoolTop + "/BUILD", build);
if (disableCrosstool) {
config.overwrite(
crosstoolTop + "/cc_toolchain_config.bzl",
ResourceLoader.readFromResources(
"com/google/devtools/build/lib/analysis/mock/cc_toolchain_config.bzl"));
config.overwrite(crosstoolTop + "/cc_toolchain_config.bzl", ccToolchainConfigFileContents);
config.overwrite(
TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/cpp/cc_toolchain_config_lib.bzl",
ResourceLoader.readFromResources(
Expand All @@ -499,6 +550,7 @@ public void write() throws IOException {
ResourceLoader.readFromResources(
TestConstants.BAZEL_REPO_PATH + "tools/build_defs/cc/action_names.bzl"));
config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/build_defs/cc/BUILD");
config.append(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/cpp/BUILD", "");
} else {
config.overwrite(crosstoolTop + "/CROSSTOOL", crosstoolFileContents);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public void setupCcToolchainConfigForCpu(MockToolsConfig config, String... cpus)
toolchainConfigBuilder.add(CcToolchainConfig.getCcToolchainConfigForCpu(cpu));
}
new Crosstool(config, crosstoolTop, /* disableCrosstool= */ true)
.setCcToolchainFile(readCcToolchainConfigFile())
.setSupportedArchs(getCrosstoolArchs())
.setToolchainConfigs(toolchainConfigBuilder.build())
.setSupportsHeaderParsing(true)
Expand All @@ -520,6 +521,7 @@ public void setupCcToolchainConfig(
config.linkTools(getRealFilesystemTools(crosstoolTop));
} else {
new Crosstool(config, crosstoolTop, /* disableCrosstool= */ true)
.setCcToolchainFile(readCcToolchainConfigFile())
.setSupportedArchs(getCrosstoolArchs())
.setToolchainConfigs(ImmutableList.of(ccToolchainConfig.build()))
.setSupportsHeaderParsing(true)
Expand Down Expand Up @@ -569,6 +571,11 @@ protected String readCrosstoolFile() throws IOException {
"com/google/devtools/build/lib/analysis/mock/MOCK_CROSSTOOL");
}

protected String readCcToolchainConfigFile() throws IOException {
return ResourceLoader.readFromResources(
"com/google/devtools/build/lib/analysis/mock/cc_toolchain_config.bzl");
}

public abstract String getMockCrosstoolVersion();

public abstract Label getMockCrosstoolLabel();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
licenses(["notice"])

exports_files(
["android_cc_toolchain_config.bzl"],
visibility = ["//visibility:public"],
)

filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src/test/java/com/google/devtools/build/lib:__pkg__"],
)
Loading

0 comments on commit 8c0c57a

Please sign in to comment.