Merge "Make @soong_injection usable in standalone builds." am: b9ebb7dfd8
am: 8178b454a3
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1703387 Change-Id: I10f11da584ff914b653a647670cf097f3d27f02e
This commit is contained in:
commit
3114ff6f5a
|
@ -347,7 +347,10 @@ func (r *builtinBazelRunner) issueBazelCommand(paths *bazelPaths, runName bazel.
|
|||
|
||||
bazelCmd := exec.Command(paths.bazelPath, cmdFlags...)
|
||||
bazelCmd.Dir = absolutePath(paths.syntheticWorkspaceDir())
|
||||
bazelCmd.Env = append(os.Environ(), "HOME="+paths.homeDir, pwdPrefix(),
|
||||
bazelCmd.Env = append(os.Environ(),
|
||||
"HOME="+paths.homeDir,
|
||||
pwdPrefix(),
|
||||
"BUILD_DIR="+absolutePath(paths.buildDir),
|
||||
// Disables local host detection of gcc; toolchain information is defined
|
||||
// explicitly in BUILD files.
|
||||
"BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1")
|
||||
|
@ -583,8 +586,9 @@ func (context *bazelContext) InvokeBazel() error {
|
|||
var err error
|
||||
|
||||
soongInjectionPath := absolutePath(context.paths.injectedFilesDir())
|
||||
if _, err := os.Stat(soongInjectionPath); os.IsNotExist(err) {
|
||||
err = os.Mkdir(soongInjectionPath, 0777)
|
||||
mixedBuildsPath := filepath.Join(soongInjectionPath, "mixed_builds")
|
||||
if _, err := os.Stat(mixedBuildsPath); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(mixedBuildsPath, 0777)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -596,14 +600,14 @@ func (context *bazelContext) InvokeBazel() error {
|
|||
}
|
||||
|
||||
err = ioutil.WriteFile(
|
||||
filepath.Join(soongInjectionPath, "main.bzl"),
|
||||
filepath.Join(mixedBuildsPath, "main.bzl"),
|
||||
context.mainBzlFileContents(), 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(
|
||||
filepath.Join(soongInjectionPath, "BUILD.bazel"),
|
||||
filepath.Join(mixedBuildsPath, "BUILD.bazel"),
|
||||
context.mainBuildFileContents(), 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -615,7 +619,7 @@ func (context *bazelContext) InvokeBazel() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buildrootLabel := "@soong_injection//:buildroot"
|
||||
buildrootLabel := "@soong_injection//mixed_builds:buildroot"
|
||||
cqueryOutput, cqueryErr, err = context.issueBazelCommand(
|
||||
context.paths,
|
||||
bazel.CqueryBuildRootRunName,
|
||||
|
@ -676,7 +680,7 @@ func (context *bazelContext) InvokeBazel() error {
|
|||
_, _, err = context.issueBazelCommand(
|
||||
context.paths,
|
||||
bazel.BazelBuildPhonyRootRunName,
|
||||
bazelCommand{"build", "@soong_injection//:phonyroot"})
|
||||
bazelCommand{"build", "@soong_injection//mixed_builds:phonyroot"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -11,7 +11,7 @@ func TestRequestResultsAfterInvokeBazel(t *testing.T) {
|
|||
label := "//foo:bar"
|
||||
arch := Arm64
|
||||
bazelContext, _ := testBazelContext(t, map[bazelCommand]string{
|
||||
bazelCommand{command: "cquery", expression: "kind(rule, deps(@soong_injection//:buildroot))"}: `//foo:bar|arm64>>out/foo/bar.txt`,
|
||||
bazelCommand{command: "cquery", expression: "kind(rule, deps(@soong_injection//mixed_builds:buildroot))"}: `//foo:bar|arm64>>out/foo/bar.txt`,
|
||||
})
|
||||
g, ok := bazelContext.GetOutputFiles(label, arch)
|
||||
if ok {
|
||||
|
@ -35,13 +35,13 @@ func TestInvokeBazelWritesBazelFiles(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Did not expect error invoking Bazel, but got %s", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(baseDir, "soong_injection", "main.bzl")); os.IsNotExist(err) {
|
||||
if _, err := os.Stat(filepath.Join(baseDir, "soong_injection", "mixed_builds", "main.bzl")); os.IsNotExist(err) {
|
||||
t.Errorf("Expected main.bzl to exist, but it does not")
|
||||
} else if err != nil {
|
||||
t.Errorf("Unexpected error stating main.bzl %s", err)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(filepath.Join(baseDir, "soong_injection", "BUILD.bazel")); os.IsNotExist(err) {
|
||||
if _, err := os.Stat(filepath.Join(baseDir, "soong_injection", "mixed_builds", "BUILD.bazel")); os.IsNotExist(err) {
|
||||
t.Errorf("Expected BUILD.bazel to exist, but it does not")
|
||||
} else if err != nil {
|
||||
t.Errorf("Unexpected error stating BUILD.bazel %s", err)
|
||||
|
@ -56,7 +56,7 @@ func TestInvokeBazelWritesBazelFiles(t *testing.T) {
|
|||
|
||||
func TestInvokeBazelPopulatesBuildStatements(t *testing.T) {
|
||||
bazelContext, _ := testBazelContext(t, map[bazelCommand]string{
|
||||
bazelCommand{command: "aquery", expression: "deps(@soong_injection//:buildroot)"}: `
|
||||
bazelCommand{command: "aquery", expression: "deps(@soong_injection//mixed_builds:buildroot)"}: `
|
||||
{
|
||||
"artifacts": [{
|
||||
"id": 1,
|
||||
|
@ -105,7 +105,7 @@ func testBazelContext(t *testing.T, bazelCommandResults map[bazelCommand]string)
|
|||
outputBase: "outputbase",
|
||||
workspaceDir: "workspace_dir",
|
||||
}
|
||||
aqueryCommand := bazelCommand{command: "aquery", expression: "deps(@soong_injection//:buildroot)"}
|
||||
aqueryCommand := bazelCommand{command: "aquery", expression: "deps(@soong_injection//mixed_builds:buildroot)"}
|
||||
if _, exists := bazelCommandResults[aqueryCommand]; !exists {
|
||||
bazelCommandResults[aqueryCommand] = "{}\n"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue