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
diff --git a/android/config.go b/android/config.go
index 101f457..3c49c1a 100644
--- a/android/config.go
+++ b/android/config.go
@@ -135,12 +135,12 @@
}
func loadConfig(config *config) error {
- err := loadFromConfigFile(&config.FileConfigurableOptions, config.ConfigFileName)
+ err := loadFromConfigFile(&config.FileConfigurableOptions, absolutePath(config.ConfigFileName))
if err != nil {
return err
}
- return loadFromConfigFile(&config.productVariables, config.ProductVariablesFileName)
+ return loadFromConfigFile(&config.productVariables, absolutePath(config.ProductVariablesFileName))
}
// loads configuration options from a JSON file in the cwd.
@@ -204,6 +204,17 @@
return nil
}
+// NullConfig returns a mostly empty Config for use by standalone tools like dexpreopt_gen that
+// use the android package.
+func NullConfig(buildDir string) Config {
+ return Config{
+ config: &config{
+ buildDir: buildDir,
+ fs: pathtools.OsFs,
+ },
+ }
+}
+
// TestConfig returns a Config object suitable for using for tests
func TestConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
envCopy := make(map[string]string)
@@ -320,7 +331,7 @@
buildDir: buildDir,
multilibConflicts: make(map[ArchType]bool),
- fs: pathtools.OsFs,
+ fs: pathtools.NewOsFs(absSrcDir),
}
config.deviceConfig = &deviceConfig{
@@ -350,7 +361,7 @@
}
inMakeFile := filepath.Join(buildDir, ".soong.in_make")
- if _, err := os.Stat(inMakeFile); err == nil {
+ if _, err := os.Stat(absolutePath(inMakeFile)); err == nil {
config.inMake = true
}
@@ -398,6 +409,8 @@
return Config{config}, nil
}
+var TestConfigOsFs = map[string][]byte{}
+
// mockFileSystem replaces all reads with accesses to the provided map of
// filenames to contents stored as a byte slice.
func (c *config) mockFileSystem(bp string, fs map[string][]byte) {
@@ -901,8 +914,13 @@
return c.productVariables.BootJars
}
-func (c *config) DexpreoptGlobalConfig() string {
- return String(c.productVariables.DexpreoptGlobalConfig)
+func (c *config) DexpreoptGlobalConfig(ctx PathContext) ([]byte, error) {
+ if c.productVariables.DexpreoptGlobalConfig == nil {
+ return nil, nil
+ }
+ path := absolutePath(*c.productVariables.DexpreoptGlobalConfig)
+ ctx.AddNinjaFileDeps(path)
+ return ioutil.ReadFile(path)
}
func (c *config) FrameworksBaseDirExists(ctx PathContext) bool {