Selaa lähdekoodia

Remove flags that enable the new python path behavior

The new behavior has been enabled by default, and these
flags aren't necessary anymore.

Fixes: 245583294
Test: m py_dont_import_folder_of_entrypoint_test && /ssd/aosp-master/out/host/linux-x86/testcases/py_dont_import_folder_of_entrypoint_test/x86_64/py_dont_import_folder_of_entrypoint_test
Change-Id: I5b6f98da51791bc5d28662ef799a10c1bb6a35a0
Cole Faust 1 vuosi sitten
vanhempi
commit
caf766b74f

+ 0 - 12
python/Android.bp

@@ -27,15 +27,3 @@ bootstrap_go_package {
     ],
     pluginFor: ["soong_build"],
 }
-
-// We're transitioning all of these flags to be true by default.
-// This is a defaults flag that can be used to easily add all of them to
-// certain modules.
-python_defaults {
-    name: "modern_python_path_defaults",
-    dont_add_top_level_directories_to_path: true,
-    dont_add_entrypoint_folder_to_path: true,
-    proto: {
-        respect_pkg_path: true,
-    },
-}

+ 1 - 22
python/binary.go

@@ -116,22 +116,6 @@ type BinaryProperties struct {
 	// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
 	// explicitly.
 	Auto_gen_config *bool
-
-	// Currently, both the root of the zipfile and all the directories 1 level
-	// below that are added to the python path. When this flag is set to true,
-	// only the root of the zipfile will be added to the python path. This flag
-	// will be removed after all the python modules in the tree have been updated
-	// to support it. When using embedded_launcher: true, this is already the
-	// behavior. The default is currently false.
-	Dont_add_top_level_directories_to_path *bool
-
-	// Setting this to true will mimic Python 3.11+'s PYTHON_SAFE_PATH environment
-	// variable or -P flag, even on older python versions. This is a temporary
-	// flag while modules are changed to support it, eventually true will be the
-	// default and the flag will be removed. The default is currently false. It
-	// is only applicable when embedded_launcher is false, when embedded_launcher
-	// is true this is already implied.
-	Dont_add_entrypoint_folder_to_path *bool
 }
 
 type binaryDecorator struct {
@@ -191,14 +175,9 @@ func (binary *binaryDecorator) bootstrap(ctx android.ModuleContext, actualVersio
 			}
 		})
 	}
-
-	addTopDirectoriesToPath := !proptools.BoolDefault(binary.binaryProperties.Dont_add_top_level_directories_to_path, true)
-	dontAddEntrypointFolderToPath := proptools.BoolDefault(binary.binaryProperties.Dont_add_entrypoint_folder_to_path, true)
-
 	binFile := registerBuildActionForParFile(ctx, embeddedLauncher, launcherPath,
 		binary.getHostInterpreterName(ctx, actualVersion),
-		main, binary.getStem(ctx), append(android.Paths{srcsZip}, depsSrcsZips...),
-		addTopDirectoriesToPath, dontAddEntrypointFolderToPath)
+		main, binary.getStem(ctx), append(android.Paths{srcsZip}, depsSrcsZips...))
 
 	return android.OptionalPathForPath(binFile)
 }

+ 14 - 44
python/builder.go

@@ -43,17 +43,7 @@ var (
 
 	hostPar = pctx.AndroidStaticRule("hostPar",
 		blueprint.RuleParams{
-			Command: `sed -e 's/%interpreter%/$interp/g' -e 's/%main%/$main/g' -e 's/ADD_TOP_DIRECTORIES_TO_PATH/$addTopDirectoriesToPath/g' build/soong/python/scripts/stub_template_host.txt > $out.main && ` +
-				`echo "#!/usr/bin/env $interp" >${out}.prefix &&` +
-				`$mergeParCmd -p --prefix ${out}.prefix -pm $out.main $out $srcsZips && ` +
-				`chmod +x $out && (rm -f $out.main; rm -f ${out}.prefix)`,
-			CommandDeps: []string{"$mergeParCmd", "build/soong/python/scripts/stub_template_host.txt"},
-		},
-		"interp", "main", "srcsZips", "addTopDirectoriesToPath")
-
-	hostParWithoutAddingEntrypointFolderToPath = pctx.AndroidStaticRule("hostParWithoutAddingEntrypointFolderToPath",
-		blueprint.RuleParams{
-			Command: `sed -e 's/%interpreter%/$interp/g' -e 's/%main%/__soong_entrypoint_redirector__.py/g' -e 's/ADD_TOP_DIRECTORIES_TO_PATH/$addTopDirectoriesToPath/g' build/soong/python/scripts/stub_template_host.txt > $out.main && ` +
+			Command: `sed -e 's/%interpreter%/$interp/g' -e 's/%main%/__soong_entrypoint_redirector__.py/g' build/soong/python/scripts/stub_template_host.txt > $out.main && ` +
 				"sed -e 's/ENTRY_POINT/$main/g' build/soong/python/scripts/main_non_embedded.py >`dirname $out`/__soong_entrypoint_redirector__.py && " +
 				"$parCmd -o $out.entrypoint_zip -C `dirname $out` -f `dirname $out`/__soong_entrypoint_redirector__.py && " +
 				`echo "#!/usr/bin/env $interp" >${out}.prefix &&` +
@@ -61,7 +51,7 @@ var (
 				"chmod +x $out && (rm -f $out.main; rm -f ${out}.prefix; rm -f $out.entrypoint_zip; rm -f `dirname $out`/__soong_entrypoint_redirector__.py)",
 			CommandDeps: []string{"$mergeParCmd", "$parCmd", "build/soong/python/scripts/stub_template_host.txt", "build/soong/python/scripts/main_non_embedded.py"},
 		},
-		"interp", "main", "srcsZips", "addTopDirectoriesToPath")
+		"interp", "main", "srcsZips")
 
 	embeddedPar = pctx.AndroidStaticRule("embeddedPar",
 		blueprint.RuleParams{
@@ -92,7 +82,7 @@ func init() {
 
 func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher bool,
 	launcherPath android.OptionalPath, interpreter, main, binName string,
-	srcsZips android.Paths, addTopDirectoriesToPath bool, dontAddEntrypointFolderToPath bool) android.Path {
+	srcsZips android.Paths) android.Path {
 
 	// .intermediate output path for bin executable.
 	binFile := android.PathForModuleOut(ctx, binName)
@@ -101,37 +91,17 @@ func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher b
 	implicits := srcsZips
 
 	if !embeddedLauncher {
-		addDirsString := "False"
-		if addTopDirectoriesToPath {
-			addDirsString = "True"
-		}
-		if dontAddEntrypointFolderToPath {
-			ctx.Build(pctx, android.BuildParams{
-				Rule:        hostParWithoutAddingEntrypointFolderToPath,
-				Description: "host python archive",
-				Output:      binFile,
-				Implicits:   implicits,
-				Args: map[string]string{
-					"interp":                  strings.Replace(interpreter, "/", `\/`, -1),
-					"main":                    strings.Replace(strings.TrimSuffix(main, pyExt), "/", ".", -1),
-					"srcsZips":                strings.Join(srcsZips.Strings(), " "),
-					"addTopDirectoriesToPath": addDirsString,
-				},
-			})
-		} else {
-			ctx.Build(pctx, android.BuildParams{
-				Rule:        hostPar,
-				Description: "host python archive",
-				Output:      binFile,
-				Implicits:   implicits,
-				Args: map[string]string{
-					"interp":                  strings.Replace(interpreter, "/", `\/`, -1),
-					"main":                    strings.Replace(main, "/", `\/`, -1),
-					"srcsZips":                strings.Join(srcsZips.Strings(), " "),
-					"addTopDirectoriesToPath": addDirsString,
-				},
-			})
-		}
+		ctx.Build(pctx, android.BuildParams{
+			Rule:        hostPar,
+			Description: "host python archive",
+			Output:      binFile,
+			Implicits:   implicits,
+			Args: map[string]string{
+				"interp":   strings.Replace(interpreter, "/", `\/`, -1),
+				"main":     strings.Replace(strings.TrimSuffix(main, pyExt), "/", ".", -1),
+				"srcsZips": strings.Join(srcsZips.Strings(), " "),
+			},
+		})
 	} else if launcherPath.Valid() {
 		// added launcherPath to the implicits Ninja dependencies.
 		implicits = append(implicits, launcherPath.Path())

+ 1 - 4
python/proto.go

@@ -18,7 +18,7 @@ import (
 	"android/soong/android"
 )
 
-func genProto(ctx android.ModuleContext, protoFile android.Path, flags android.ProtoFlags, pkgPath string) android.Path {
+func genProto(ctx android.ModuleContext, protoFile android.Path, flags android.ProtoFlags) android.Path {
 	srcsZipFile := android.PathForModuleGen(ctx, protoFile.Base()+".srcszip")
 
 	outDir := srcsZipFile.ReplaceExtension(ctx, "tmp")
@@ -36,9 +36,6 @@ func genProto(ctx android.ModuleContext, protoFile android.Path, flags android.P
 	zipCmd := rule.Command().
 		BuiltTool("soong_zip").
 		FlagWithOutput("-o ", srcsZipFile)
-	if pkgPath != "" {
-		zipCmd.FlagWithArg("-P ", pkgPath)
-	}
 	zipCmd.FlagWithArg("-C ", outDir.String()).
 		FlagWithArg("-D ", outDir.String())
 

+ 2 - 14
python/python.go

@@ -120,15 +120,6 @@ type BaseProperties struct {
 	// whether the binary is required to be built with embedded launcher for this actual_version.
 	// this is set by the python version mutator based on version-specific properties
 	Embedded_launcher *bool `blueprint:"mutated"`
-
-	Proto struct {
-		// Whether generated python protos should include the pkg_path in
-		// their import statements. This is a temporary flag to help transition to
-		// the new behavior where this is always true. It will be removed after all
-		// usages of protos with pkg_path have been updated. The default is currently
-		// false.
-		Respect_pkg_path *bool
-	}
 }
 
 type baseAttributes struct {
@@ -677,9 +668,7 @@ func (p *Module) createSrcsZip(ctx android.ModuleContext, pkgPath string) androi
 		protoFlags := android.GetProtoFlags(ctx, &p.protoProperties)
 		protoFlags.OutTypeFlag = "--python_out"
 
-		protosRespectPkgPath := proptools.BoolDefault(p.properties.Proto.Respect_pkg_path, true)
-		pkgPathForProtos := pkgPath
-		if pkgPathForProtos != "" && protosRespectPkgPath {
+		if pkgPath != "" {
 			pkgPathStagingDir := android.PathForModuleGen(ctx, "protos_staged_for_pkg_path")
 			rule := android.NewRuleBuilder(pctx, ctx)
 			var stagedProtoSrcs android.Paths
@@ -691,11 +680,10 @@ func (p *Module) createSrcsZip(ctx android.ModuleContext, pkgPath string) androi
 			}
 			rule.Build("stage_protos_for_pkg_path", "Stage protos for pkg_path")
 			protoSrcs = stagedProtoSrcs
-			pkgPathForProtos = ""
 		}
 
 		for _, srcFile := range protoSrcs {
-			zip := genProto(ctx, srcFile, protoFlags, pkgPathForProtos)
+			zip := genProto(ctx, srcFile, protoFlags)
 			zips = append(zips, zip)
 		}
 	}

+ 1 - 10
python/scripts/stub_template_host.txt

@@ -23,16 +23,7 @@ def Main():
     zf.extractall(runfiles_path)
     zf.close()
 
-    # Add runfiles path to PYTHONPATH.
-    python_path_entries = [runfiles_path]
-
-    if ADD_TOP_DIRECTORIES_TO_PATH:
-      # Add top dirs within runfiles path to PYTHONPATH.
-      top_entries = [os.path.join(runfiles_path, i) for i in os.listdir(runfiles_path)]
-      top_pkg_dirs = [i for i in top_entries if os.path.isdir(i)]
-      python_path_entries += top_pkg_dirs
-
-    new_python_path = ":".join(python_path_entries)
+    new_python_path = runfiles_path
     old_python_path = os.environ.get(PYTHON_PATH)
 
     if old_python_path:

+ 0 - 1
python/tests/dont_import_folder_of_entrypoint/Android.bp

@@ -9,7 +9,6 @@ python_test_host {
         "mypkg/main.py",
         "mypkg/mymodule.py",
     ],
-    defaults: ["modern_python_path_defaults"],
 }
 
 python_test_host {

+ 0 - 1
python/tests/proto_pkg_path/Android.bp

@@ -12,6 +12,5 @@ python_test_host {
     pkg_path: "mylib/subpackage",
     proto: {
         canonical_path_from_root: false,
-        respect_pkg_path: true,
     },
 }

+ 0 - 1
python/tests/top_level_dirs/Android.bp

@@ -9,5 +9,4 @@ python_test_host {
         "main.py",
         "mypkg/mymodule.py",
     ],
-    dont_add_top_level_directories_to_path: true,
 }