Sandbox soong_build by changing to root directory

This relands I12a0f907753fefd1997ab8b4ea2ac331234093cf along with
a fix to blueprint for absolute paths.

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.

Change-Id: I24ac485677aa102eec1a2521d16820da6ee1ae77
Fixes: 146437378
Test: m checkbuild
Test: m OUT_DIR=/tmp/out nothing
This commit is contained in:
Colin Cross
2020-01-11 01:11:46 +00:00
parent 47e4f9e1e8
commit 988414c2cf
23 changed files with 208 additions and 130 deletions

View File

@@ -135,12 +135,12 @@ type jsonConfigurable interface {
}
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 @@ func saveToConfigFile(config jsonConfigurable, filename string) error {
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 @@ func NewConfig(srcDir, buildDir string) (Config, error) {
buildDir: buildDir,
multilibConflicts: make(map[ArchType]bool),
fs: pathtools.OsFs,
fs: pathtools.NewOsFs(absSrcDir),
}
config.deviceConfig = &deviceConfig{
@@ -350,7 +361,7 @@ func NewConfig(srcDir, buildDir string) (Config, error) {
}
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 @@ func NewConfig(srcDir, buildDir string) (Config, error) {
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 @@ func (c *config) BootJars() []string {
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 {