aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorNan Zhang2018-05-31 14:49:33 -0500
committerNan Zhang2018-06-04 14:32:55 -0500
commitbea0975f1882a8741dc3e9abe2bd69f7067953db (patch)
treec561f9cb883ba11a31a69e5a02f735d4d9a926d9 /python
parent1d2318d6cd9b7f64178afb4e3a8ce481dd603bbf (diff)
downloadplatform-build-soong-bea0975f1882a8741dc3e9abe2bd69f7067953db.tar.gz
platform-build-soong-bea0975f1882a8741dc3e9abe2bd69f7067953db.tar.xz
platform-build-soong-bea0975f1882a8741dc3e9abe2bd69f7067953db.zip
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
Diffstat (limited to 'python')
-rw-r--r--python/builder.go7
-rw-r--r--python/python.go18
-rw-r--r--python/python_test.go18
-rw-r--r--python/scripts/stub_template_host.txt5
4 files changed, 15 insertions, 33 deletions
diff --git a/python/builder.go b/python/builder.go
index 969f9efd..ec4cb4ea 100644
--- a/python/builder.go
+++ b/python/builder.go
@@ -96,11 +96,8 @@ func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher b
96 Output: binFile, 96 Output: binFile,
97 Implicits: implicits, 97 Implicits: implicits,
98 Args: map[string]string{ 98 Args: map[string]string{
99 "interp": strings.Replace(interpreter, "/", `\/`, -1), 99 "interp": strings.Replace(interpreter, "/", `\/`, -1),
100 // we need remove "runfiles/" suffix since stub script starts 100 "main": strings.Replace(main, "/", `\/`, -1),
101 // searching for main file in each sub-dir of "runfiles" directory tree.
102 "main": strings.Replace(strings.TrimPrefix(main, runFiles+"/"),
103 "/", `\/`, -1),
104 "template": template.String(), 101 "template": template.String(),
105 "stub": stub, 102 "stub": stub,
106 "mergedZip": mergedZip.String(), 103 "mergedZip": mergedZip.String(),
diff --git a/python/python.go b/python/python.go
index 6d6ac27b..4b9111f3 100644
--- a/python/python.go
+++ b/python/python.go
@@ -63,8 +63,7 @@ type BaseProperties struct {
63 // files of the current module. 63 // files of the current module.
64 // eg. Pkg_path = "a/b/c"; Other packages can reference this module by using 64 // eg. Pkg_path = "a/b/c"; Other packages can reference this module by using
65 // (from a.b.c import ...) statement. 65 // (from a.b.c import ...) statement.
66 // if left unspecified, all the source/data files of current module are copied to 66 // if left unspecified, all the source/data files path is unchanged within zip file.
67 // "runfiles/" tree directory directly.
68 Pkg_path *string `android:"arch_variant"` 67 Pkg_path *string `android:"arch_variant"`
69 68
70 // true, if the Python module is used internally, eg, Python std libs. 69 // true, if the Python module is used internally, eg, Python std libs.
@@ -215,7 +214,6 @@ var (
215 mainFileName = "__main__.py" 214 mainFileName = "__main__.py"
216 entryPointFile = "entry_point.txt" 215 entryPointFile = "entry_point.txt"
217 parFileExt = ".zip" 216 parFileExt = ".zip"
218 runFiles = "runfiles"
219 internal = "internal" 217 internal = "internal"
220) 218)
221 219
@@ -417,23 +415,11 @@ func (p *Module) GeneratePythonBuildActions(ctx android.ModuleContext) {
417 return 415 return
418 } 416 }
419 if p.properties.Is_internal != nil && *p.properties.Is_internal { 417 if p.properties.Is_internal != nil && *p.properties.Is_internal {
420 // pkg_path starts from "internal/" implicitly.
421 pkgPath = filepath.Join(internal, pkgPath) 418 pkgPath = filepath.Join(internal, pkgPath)
422 } else {
423 if !p.isEmbeddedLauncherEnabled(p.properties.Actual_version) {
424 // pkg_path starts from "runfiles/" implicitly.
425 pkgPath = filepath.Join(runFiles, pkgPath)
426 }
427 } 419 }
428 } else { 420 } else {
429 if p.properties.Is_internal != nil && *p.properties.Is_internal { 421 if p.properties.Is_internal != nil && *p.properties.Is_internal {
430 // pkg_path starts from "runfiles/" implicitly.
431 pkgPath = internal 422 pkgPath = internal
432 } else {
433 if !p.isEmbeddedLauncherEnabled(p.properties.Actual_version) {
434 // pkg_path starts from "runfiles/" implicitly.
435 pkgPath = runFiles
436 }
437 } 423 }
438 } 424 }
439 425
@@ -620,7 +606,7 @@ func (p *Module) walkTransitiveDeps(ctx android.ModuleContext) {
620func fillInMap(ctx android.ModuleContext, m map[string]string, 606func fillInMap(ctx android.ModuleContext, m map[string]string,
621 key, value, curModule, otherModule string) bool { 607 key, value, curModule, otherModule string) bool {
622 if oldValue, found := m[key]; found { 608 if oldValue, found := m[key]; found {
623 ctx.ModuleErrorf("found two files to be placed at the same runfiles location %q."+ 609 ctx.ModuleErrorf("found two files to be placed at the same location within zip %q."+
624 " First file: in module %s at path %q."+ 610 " First file: in module %s at path %q."+
625 " Second file: in module %s at path %q.", 611 " Second file: in module %s at path %q.",
626 key, curModule, oldValue, otherModule, value) 612 key, curModule, oldValue, otherModule, value)
diff --git a/python/python_test.go b/python/python_test.go
index 60a1c82a..e5fe126c 100644
--- a/python/python_test.go
+++ b/python/python_test.go
@@ -44,7 +44,7 @@ var (
44 badIdentifierErrTemplate = moduleVariantErrTemplate + 44 badIdentifierErrTemplate = moduleVariantErrTemplate +
45 "srcs: the path %q contains invalid token %q." 45 "srcs: the path %q contains invalid token %q."
46 dupRunfileErrTemplate = moduleVariantErrTemplate + 46 dupRunfileErrTemplate = moduleVariantErrTemplate +
47 "found two files to be placed at the same runfiles location %q." + 47 "found two files to be placed at the same location within zip %q." +
48 " First file: in module %s at path %q." + 48 " First file: in module %s at path %q." +
49 " Second file: in module %s at path %q." 49 " Second file: in module %s at path %q."
50 noSrcFileErr = moduleVariantErrTemplate + "doesn't have any source files!" 50 noSrcFileErr = moduleVariantErrTemplate + "doesn't have any source files!"
@@ -175,11 +175,11 @@ var (
175 }, 175 },
176 errors: []string{ 176 errors: []string{
177 fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11", 177 fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11",
178 "lib1", "PY3", "runfiles/a/b/c/-e/f/file1.py", "-e"), 178 "lib1", "PY3", "a/b/c/-e/f/file1.py", "-e"),
179 fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11", 179 fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11",
180 "lib1", "PY3", "runfiles/a/b/c/.file1.py", ".file1"), 180 "lib1", "PY3", "a/b/c/.file1.py", ".file1"),
181 fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11", 181 fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11",
182 "lib1", "PY3", "runfiles/a/b/c/123/file1.py", "123"), 182 "lib1", "PY3", "a/b/c/123/file1.py", "123"),
183 }, 183 },
184 }, 184 },
185 { 185 {
@@ -212,7 +212,7 @@ var (
212 }, 212 },
213 errors: []string{ 213 errors: []string{
214 fmt.Sprintf(dupRunfileErrTemplate, "dir/Blueprints:9:6", 214 fmt.Sprintf(dupRunfileErrTemplate, "dir/Blueprints:9:6",
215 "lib2", "PY3", "runfiles/a/b/c/file1.py", "lib2", "dir/file1.py", 215 "lib2", "PY3", "a/b/c/file1.py", "lib2", "dir/file1.py",
216 "lib1", "dir/c/file1.py"), 216 "lib1", "dir/c/file1.py"),
217 }, 217 },
218 }, 218 },
@@ -307,10 +307,10 @@ var (
307 name: "bin", 307 name: "bin",
308 actualVersion: "PY3", 308 actualVersion: "PY3",
309 pyRunfiles: []string{ 309 pyRunfiles: []string{
310 "runfiles/e/default.py", 310 "e/default.py",
311 "runfiles/e/bin.py", 311 "e/bin.py",
312 "runfiles/e/default_py3.py", 312 "e/default_py3.py",
313 "runfiles/e/file4.py", 313 "e/file4.py",
314 }, 314 },
315 srcsZip: "@prefix@/.intermediates/dir/bin/PY3/bin.py.srcszip", 315 srcsZip: "@prefix@/.intermediates/dir/bin/PY3/bin.py.srcszip",
316 depsSrcsZips: []string{ 316 depsSrcsZips: []string{
diff --git a/python/scripts/stub_template_host.txt b/python/scripts/stub_template_host.txt
index 386298eb..e6862114 100644
--- a/python/scripts/stub_template_host.txt
+++ b/python/scripts/stub_template_host.txt
@@ -11,7 +11,6 @@ import zipfile
11PYTHON_BINARY = '%interpreter%' 11PYTHON_BINARY = '%interpreter%'
12MAIN_FILE = '%main%' 12MAIN_FILE = '%main%'
13PYTHON_PATH = 'PYTHONPATH' 13PYTHON_PATH = 'PYTHONPATH'
14ZIP_RUNFILES_DIRECTORY_NAME = 'runfiles'
15 14
16def SearchPathEnv(name): 15def SearchPathEnv(name):
17 search_path = os.getenv('PATH', os.defpath).split(os.pathsep) 16 search_path = os.getenv('PATH', os.defpath).split(os.pathsep)
@@ -36,7 +35,7 @@ def ExtractRunfiles():
36 temp_dir = tempfile.mkdtemp("", "Soong.python_") 35 temp_dir = tempfile.mkdtemp("", "Soong.python_")
37 zf = zipfile.ZipFile(os.path.dirname(__file__)) 36 zf = zipfile.ZipFile(os.path.dirname(__file__))
38 zf.extractall(temp_dir) 37 zf.extractall(temp_dir)
39 return os.path.join(temp_dir, ZIP_RUNFILES_DIRECTORY_NAME) 38 return temp_dir
40 39
41def Main(): 40def Main():
42 args = sys.argv[1:] 41 args = sys.argv[1:]
@@ -83,7 +82,7 @@ def Main():
83 except: 82 except:
84 raise 83 raise
85 finally: 84 finally:
86 shutil.rmtree(os.path.dirname(runfiles_path), True) 85 shutil.rmtree(runfiles_path, True)
87 86
88if __name__ == '__main__': 87if __name__ == '__main__':
89 Main() 88 Main()