diff options
author | 2022-12-07 01:14:52 +0000 | |
---|---|---|
committer | 2022-12-07 01:25:03 +0000 | |
commit | 067210f70db32f980675bf24d6c96a91a0309474 (patch) | |
tree | 387505621d0a95b09f80f199cab22b618fb648ee | |
parent | c082eb8eac3ce1ab54f728bc0f2584c88a93d4c9 (diff) |
Create soong_injection files in ReadWrite mode
The synthetic soong_injection workspace is shared between api_bp2build
(used in API export) and bp2build (used in API domain analysis which
runs mixed builds by default). The former creates them in ReadOnly mode,
but the latter creates them in ReadWrite mode (to allow users to
edit/experiment). To prevent errors in the end-to-end builds in
multittree, make api_bp2build create these files in ReadWrite mode as
well.
Test: mulittree_build locally
Change-Id: I8766d88951a3b625739e4dc12d468450ad7322ea
-rw-r--r-- | cmd/soong_build/main.go | 7 | ||||
-rw-r--r-- | cmd/soong_build/queryview.go | 13 |
2 files changed, 19 insertions, 1 deletions
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index e7323dd35..2ef7c1250 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -237,7 +237,12 @@ func runApiBp2build(configuration android.Config, ctx *android.Context, extraNin soongInjectionFiles := bp2build.CreateSoongInjectionFiles(configuration, bp2build.CreateCodegenMetrics()) absoluteSoongInjectionDir := shared.JoinPath(topDir, configuration.SoongOutDir(), bazel.SoongInjectionDirName) for _, file := range soongInjectionFiles { - writeReadOnlyFile(absoluteSoongInjectionDir, file) + // The API targets in api_bp2build workspace do not have any dependency on api_bp2build. + // But we need to create these files to prevent errors during Bazel analysis. + // These need to be created in Read-Write mode. + // This is because the subsequent step (bp2build in api domain analysis) creates them in Read-Write mode + // to allow users to edit/experiment in the synthetic workspace. + writeReadWriteFile(absoluteSoongInjectionDir, file) } workspace := shared.JoinPath(configuration.SoongOutDir(), "api_bp2build") diff --git a/cmd/soong_build/queryview.go b/cmd/soong_build/queryview.go index a87652221..45b451c78 100644 --- a/cmd/soong_build/queryview.go +++ b/cmd/soong_build/queryview.go @@ -91,6 +91,19 @@ func writeReadOnlyFile(dir string, f bp2build.BazelFile) error { return err } +func writeReadWriteFile(dir string, f bp2build.BazelFile) error { + dir = filepath.Join(dir, f.Dir) + if err := createDirectoryIfNonexistent(dir); err != nil { + return err + } + pathToFile := filepath.Join(dir, f.Basename) + + // 0644 is read-write + err := ioutil.WriteFile(pathToFile, []byte(f.Contents), 0644) + + return err +} + func createDirectoryIfNonexistent(dir string) error { if _, err := os.Stat(dir); os.IsNotExist(err) { return os.MkdirAll(dir, os.ModePerm) |