Fix embedded_launcher can't find files

The problem came from Python libraries doesn't know the information that
we enabled embedded_launcher (only Python binary knows about that). And
we can't simply remove runfiles dir for Python libraries since host
Python mode need this.

Bug: b/80441699
Test: m perf_profo_flames
Change-Id: I73ffc4d7504f95a708ae7cca47bc6c15a673aa31
This commit is contained in:
Nan Zhang 2018-05-31 12:49:33 -07:00
parent 1d2318d6cd
commit bea0975f18
4 changed files with 15 additions and 33 deletions

View File

@ -96,11 +96,8 @@ func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher b
Output: binFile,
Implicits: implicits,
Args: map[string]string{
"interp": strings.Replace(interpreter, "/", `\/`, -1),
// we need remove "runfiles/" suffix since stub script starts
// searching for main file in each sub-dir of "runfiles" directory tree.
"main": strings.Replace(strings.TrimPrefix(main, runFiles+"/"),
"/", `\/`, -1),
"interp": strings.Replace(interpreter, "/", `\/`, -1),
"main": strings.Replace(main, "/", `\/`, -1),
"template": template.String(),
"stub": stub,
"mergedZip": mergedZip.String(),

View File

@ -63,8 +63,7 @@ type BaseProperties struct {
// files of the current module.
// eg. Pkg_path = "a/b/c"; Other packages can reference this module by using
// (from a.b.c import ...) statement.
// if left unspecified, all the source/data files of current module are copied to
// "runfiles/" tree directory directly.
// if left unspecified, all the source/data files path is unchanged within zip file.
Pkg_path *string `android:"arch_variant"`
// true, if the Python module is used internally, eg, Python std libs.
@ -215,7 +214,6 @@ var (
mainFileName = "__main__.py"
entryPointFile = "entry_point.txt"
parFileExt = ".zip"
runFiles = "runfiles"
internal = "internal"
)
@ -417,23 +415,11 @@ func (p *Module) GeneratePythonBuildActions(ctx android.ModuleContext) {
return
}
if p.properties.Is_internal != nil && *p.properties.Is_internal {
// pkg_path starts from "internal/" implicitly.
pkgPath = filepath.Join(internal, pkgPath)
} else {
if !p.isEmbeddedLauncherEnabled(p.properties.Actual_version) {
// pkg_path starts from "runfiles/" implicitly.
pkgPath = filepath.Join(runFiles, pkgPath)
}
}
} else {
if p.properties.Is_internal != nil && *p.properties.Is_internal {
// pkg_path starts from "runfiles/" implicitly.
pkgPath = internal
} else {
if !p.isEmbeddedLauncherEnabled(p.properties.Actual_version) {
// pkg_path starts from "runfiles/" implicitly.
pkgPath = runFiles
}
}
}
@ -620,7 +606,7 @@ func (p *Module) walkTransitiveDeps(ctx android.ModuleContext) {
func fillInMap(ctx android.ModuleContext, m map[string]string,
key, value, curModule, otherModule string) bool {
if oldValue, found := m[key]; found {
ctx.ModuleErrorf("found two files to be placed at the same runfiles location %q."+
ctx.ModuleErrorf("found two files to be placed at the same location within zip %q."+
" First file: in module %s at path %q."+
" Second file: in module %s at path %q.",
key, curModule, oldValue, otherModule, value)

View File

@ -44,7 +44,7 @@ var (
badIdentifierErrTemplate = moduleVariantErrTemplate +
"srcs: the path %q contains invalid token %q."
dupRunfileErrTemplate = moduleVariantErrTemplate +
"found two files to be placed at the same runfiles location %q." +
"found two files to be placed at the same location within zip %q." +
" First file: in module %s at path %q." +
" Second file: in module %s at path %q."
noSrcFileErr = moduleVariantErrTemplate + "doesn't have any source files!"
@ -175,11 +175,11 @@ var (
},
errors: []string{
fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11",
"lib1", "PY3", "runfiles/a/b/c/-e/f/file1.py", "-e"),
"lib1", "PY3", "a/b/c/-e/f/file1.py", "-e"),
fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11",
"lib1", "PY3", "runfiles/a/b/c/.file1.py", ".file1"),
"lib1", "PY3", "a/b/c/.file1.py", ".file1"),
fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11",
"lib1", "PY3", "runfiles/a/b/c/123/file1.py", "123"),
"lib1", "PY3", "a/b/c/123/file1.py", "123"),
},
},
{
@ -212,7 +212,7 @@ var (
},
errors: []string{
fmt.Sprintf(dupRunfileErrTemplate, "dir/Blueprints:9:6",
"lib2", "PY3", "runfiles/a/b/c/file1.py", "lib2", "dir/file1.py",
"lib2", "PY3", "a/b/c/file1.py", "lib2", "dir/file1.py",
"lib1", "dir/c/file1.py"),
},
},
@ -307,10 +307,10 @@ var (
name: "bin",
actualVersion: "PY3",
pyRunfiles: []string{
"runfiles/e/default.py",
"runfiles/e/bin.py",
"runfiles/e/default_py3.py",
"runfiles/e/file4.py",
"e/default.py",
"e/bin.py",
"e/default_py3.py",
"e/file4.py",
},
srcsZip: "@prefix@/.intermediates/dir/bin/PY3/bin.py.srcszip",
depsSrcsZips: []string{

View File

@ -11,7 +11,6 @@ import zipfile
PYTHON_BINARY = '%interpreter%'
MAIN_FILE = '%main%'
PYTHON_PATH = 'PYTHONPATH'
ZIP_RUNFILES_DIRECTORY_NAME = 'runfiles'
def SearchPathEnv(name):
search_path = os.getenv('PATH', os.defpath).split(os.pathsep)
@ -36,7 +35,7 @@ def ExtractRunfiles():
temp_dir = tempfile.mkdtemp("", "Soong.python_")
zf = zipfile.ZipFile(os.path.dirname(__file__))
zf.extractall(temp_dir)
return os.path.join(temp_dir, ZIP_RUNFILES_DIRECTORY_NAME)
return temp_dir
def Main():
args = sys.argv[1:]
@ -83,7 +82,7 @@ def Main():
except:
raise
finally:
shutil.rmtree(os.path.dirname(runfiles_path), True)
shutil.rmtree(runfiles_path, True)
if __name__ == '__main__':
Main()