diff options
author | Colin Cross <ccross@android.com> | 2019-12-12 10:23:57 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2020-01-09 14:19:46 -0800 |
commit | 05c25ccb4adb5329add700b533416c226cdbfa96 (patch) | |
tree | 79912c740318a967a9091285a5be7aece8fdcf6c /android/module.go | |
parent | 62c085d7fefd0297d06c417992d48bc68da42645 (diff) | |
download | build_soong-05c25ccb4adb5329add700b533416c226cdbfa96.tar.gz build_soong-05c25ccb4adb5329add700b533416c226cdbfa96.tar.bz2 build_soong-05c25ccb4adb5329add700b533416c226cdbfa96.zip |
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 'android/module.go')
-rw-r--r-- | android/module.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/android/module.go b/android/module.go index c9980072..67d1f129 100644 --- a/android/module.go +++ b/android/module.go @@ -16,13 +16,13 @@ package android import ( "fmt" + "os" "path" "path/filepath" "strings" "text/scanner" "github.com/google/blueprint" - "github.com/google/blueprint/pathtools" "github.com/google/blueprint/proptools" ) @@ -91,7 +91,8 @@ type EarlyModuleContext interface { Glob(globPattern string, excludes []string) Paths GlobFiles(globPattern string, excludes []string) Paths - Fs() pathtools.FileSystem + IsSymlink(path Path) bool + Readlink(path Path) string } // BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns @@ -1172,6 +1173,22 @@ func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Pa return pathsForModuleSrcFromFullPath(e, ret, false) } +func (b *earlyModuleContext) IsSymlink(path Path) bool { + fileInfo, err := b.config.fs.Lstat(path.String()) + if err != nil { + b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err) + } + return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink +} + +func (b *earlyModuleContext) Readlink(path Path) string { + dest, err := b.config.fs.Readlink(path.String()) + if err != nil { + b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err) + } + return dest +} + func (e *earlyModuleContext) Module() Module { module, _ := e.EarlyModuleContext.Module().(Module) return module |