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
diff --git a/python/builder.go b/python/builder.go
index 969f9ef..ec4cb4e 100644
--- a/python/builder.go
+++ b/python/builder.go
@@ -96,11 +96,8 @@
 			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(),
diff --git a/python/python.go b/python/python.go
index 6d6ac27..4b9111f 100644
--- a/python/python.go
+++ b/python/python.go
@@ -63,8 +63,7 @@
 	// 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 @@
 	mainFileName       = "__main__.py"
 	entryPointFile     = "entry_point.txt"
 	parFileExt         = ".zip"
-	runFiles           = "runfiles"
 	internal           = "internal"
 )
 
@@ -417,23 +415,11 @@
 			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 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)
diff --git a/python/python_test.go b/python/python_test.go
index 60a1c82..e5fe126 100644
--- a/python/python_test.go
+++ b/python/python_test.go
@@ -44,7 +44,7 @@
 	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 @@
 			},
 			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 @@
 			},
 			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 @@
 					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{
diff --git a/python/scripts/stub_template_host.txt b/python/scripts/stub_template_host.txt
index 386298e..e686211 100644
--- a/python/scripts/stub_template_host.txt
+++ b/python/scripts/stub_template_host.txt
@@ -11,7 +11,6 @@
 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 @@
   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 @@
   except:
     raise
   finally:
-    shutil.rmtree(os.path.dirname(runfiles_path), True)
+    shutil.rmtree(runfiles_path, True)
 
 if __name__ == '__main__':
   Main()