<Hermetic> Replace Soong Python bootstrap process with embedded

launcher.

For Python2, we bundle embedded launcher as bootstrapper within every
.par file. This feature is only enabled for linux_x86_64 for now. We
provide a user flag: hermetic_enabled within bp file. By default, Pyhon2
still use classic bootstrapping way to construct .par file and relys on
host interpreter. Once embedded_launcher is enabled, launcher will be
used to bootstrap .par file and execute user program.

For Python3, the launcher will be ready soon, and for now it still relys
on classic bootstrapping.

Test: Real example is used to test.

Bug: b/63018041

Change-Id: I28deba413d8ad3af407595e46f77d663e79a3705
This commit is contained in:
Nan Zhang
2017-07-12 12:55:28 -07:00
parent ff2abe56da
commit d4e641b6e9
8 changed files with 374 additions and 236 deletions

View File

@@ -28,7 +28,7 @@ import (
"android/soong/android"
)
type pyBinary struct {
type pyModule struct {
name string
actualVersion string
pyRunfiles []string
@@ -41,7 +41,7 @@ var (
buildNamePrefix = "soong_python_test"
moduleVariantErrTemplate = "%s: module %q variant %q: "
pkgPathErrTemplate = moduleVariantErrTemplate +
"pkg_path: %q is not a valid format."
"pkg_path: %q must be a relative path contained in par file."
badIdentifierErrTemplate = moduleVariantErrTemplate +
"srcs: the path %q contains invalid token %q."
dupRunfileErrTemplate = moduleVariantErrTemplate +
@@ -58,7 +58,7 @@ var (
mockFiles map[string][]byte
errors []string
expectedBinaries []pyBinary
expectedBinaries []pyModule
}{
{
desc: "module without any src files",
@@ -278,7 +278,7 @@ var (
stubTemplateHost: []byte(`PYTHON_BINARY = '%interpreter%'
MAIN_FILE = '%main%'`),
},
expectedBinaries: []pyBinary{
expectedBinaries: []pyModule{
{
name: "bin",
actualVersion: "PY3",
@@ -363,14 +363,10 @@ func expectModule(t *testing.T, ctx *android.TestContext, buildDir, name, varian
expParSpec string, expDepsParSpecs []string) (testErrs []error) {
module := ctx.ModuleForTests(name, variant)
base, baseOk := module.Module().(*pythonBaseModule)
base, baseOk := module.Module().(*Module)
if !baseOk {
t.Fatalf("%s is not Python module!", name)
}
sub, subOk := base.subModule.(*pythonBinaryBase)
if !subOk {
t.Fatalf("%s is not Python binary!", name)
}
actPyRunfiles := []string{}
for _, path := range base.srcsPathMappings {
@@ -381,28 +377,28 @@ func expectModule(t *testing.T, ctx *android.TestContext, buildDir, name, varian
testErrs = append(testErrs, errors.New(fmt.Sprintf(
`binary "%s" variant "%s" has unexpected pyRunfiles: %q!`,
base.Name(),
base.properties.ActualVersion,
base.properties.Actual_version,
actPyRunfiles)))
}
if !reflect.DeepEqual(sub.depsPyRunfiles, expDepsPyRunfiles) {
if !reflect.DeepEqual(base.depsPyRunfiles, expDepsPyRunfiles) {
testErrs = append(testErrs, errors.New(fmt.Sprintf(
`binary "%s" variant "%s" has unexpected depsPyRunfiles: %q!`,
base.Name(),
base.properties.ActualVersion,
sub.depsPyRunfiles)))
base.properties.Actual_version,
base.depsPyRunfiles)))
}
if base.parSpec.soongParArgs() != strings.Replace(expParSpec, "@prefix@", buildDir, 1) {
testErrs = append(testErrs, errors.New(fmt.Sprintf(
`binary "%s" variant "%s" has unexpected parSpec: %q!`,
base.Name(),
base.properties.ActualVersion,
base.properties.Actual_version,
base.parSpec.soongParArgs())))
}
actDepsParSpecs := []string{}
for i, p := range sub.depsParSpecs {
for i, p := range base.depsParSpecs {
actDepsParSpecs = append(actDepsParSpecs, p.soongParArgs())
expDepsParSpecs[i] = strings.Replace(expDepsParSpecs[i], "@prefix@", buildDir, 1)
}
@@ -411,7 +407,7 @@ func expectModule(t *testing.T, ctx *android.TestContext, buildDir, name, varian
testErrs = append(testErrs, errors.New(fmt.Sprintf(
`binary "%s" variant "%s" has unexpected depsParSpecs: %q!`,
base.Name(),
base.properties.ActualVersion,
base.properties.Actual_version,
actDepsParSpecs)))
}