diff options
author | 2019-12-12 10:23:57 -0800 | |
---|---|---|
committer | 2020-01-09 14:19:46 -0800 | |
commit | 05c25ccb4adb5329add700b533416c226cdbfa96 (patch) | |
tree | 79912c740318a967a9091285a5be7aece8fdcf6c /cc/compdb.go | |
parent | 62c085d7fefd0297d06c417992d48bc68da42645 (diff) |
Sandbox soong_build by changing to root directory
Store the current working directory and then change to the root
directory so that all file accesses must go through helpers in
the android package that properly track dependencies.
Fixes: 146437378
Test: m checkbuild
Change-Id: I12a0f907753fefd1997ab8b4ea2ac331234093cf
Diffstat (limited to 'cc/compdb.go')
-rw-r--r-- | cc/compdb.go | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/cc/compdb.go b/cc/compdb.go index dff14dbeb..ea124438e 100644 --- a/cc/compdb.go +++ b/cc/compdb.go @@ -79,9 +79,9 @@ func (c *compdbGeneratorSingleton) GenerateBuildActions(ctx android.SingletonCon // Create the output file. dir := android.PathForOutput(ctx, compdbOutputProjectsDirectory) - os.MkdirAll(dir.String(), 0777) + os.MkdirAll(filepath.Join(android.AbsSrcDirForExistingUseCases(), dir.String()), 0777) compDBFile := dir.Join(ctx, compdbFilename) - f, err := os.Create(compDBFile.String()) + f, err := os.Create(filepath.Join(android.AbsSrcDirForExistingUseCases(), compDBFile.String())) if err != nil { log.Fatalf("Could not create file %s: %s", compDBFile, err) } @@ -103,8 +103,8 @@ func (c *compdbGeneratorSingleton) GenerateBuildActions(ctx android.SingletonCon } f.Write(dat) - finalLinkPath := filepath.Join(ctx.Config().Getenv(envVariableCompdbLink), compdbFilename) - if finalLinkPath != "" { + if finalLinkDir := ctx.Config().Getenv(envVariableCompdbLink); finalLinkDir != "" { + finalLinkPath := filepath.Join(finalLinkDir, compdbFilename) os.Remove(finalLinkPath) if err := os.Symlink(compDBFile.String(), finalLinkPath); err != nil { log.Fatalf("Unable to symlink %s to %s: %s", compDBFile, finalLinkPath, err) @@ -174,18 +174,17 @@ func generateCompdbProject(compiledModule CompiledInterface, ctx android.Singlet return } - rootDir := getCompdbAndroidSrcRootDirectory(ctx) - pathToCC, err := ctx.Eval(pctx, rootDir+"/${config.ClangBin}/") + pathToCC, err := ctx.Eval(pctx, "${config.ClangBin}") ccPath := "/bin/false" cxxPath := "/bin/false" if err == nil { - ccPath = pathToCC + "clang" - cxxPath = pathToCC + "clang++" + ccPath = filepath.Join(pathToCC, "clang") + cxxPath = filepath.Join(pathToCC, "clang++") } for _, src := range srcs { if _, ok := builds[src.String()]; !ok { builds[src.String()] = compDbEntry{ - Directory: rootDir, + Directory: android.AbsSrcDirForExistingUseCases(), Arguments: getArguments(src, ctx, ccModule, ccPath, cxxPath), File: src.String(), } @@ -200,8 +199,3 @@ func evalAndSplitVariable(ctx android.SingletonContext, str string) ([]string, e } return []string{""}, err } - -func getCompdbAndroidSrcRootDirectory(ctx android.SingletonContext) string { - srcPath, _ := filepath.Abs(android.PathForSource(ctx).String()) - return srcPath -} |