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

@@ -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