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
diff --git a/python/Android.bp b/python/Android.bp
index 99c02bd..e49fa6a 100644
--- a/python/Android.bp
+++ b/python/Android.bp
@@ -27,15 +27,3 @@
],
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,
- },
-}
diff --git a/python/binary.go b/python/binary.go
index 1f49a54..670e0d3 100644
--- a/python/binary.go
+++ b/python/binary.go
@@ -116,22 +116,6 @@
// 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 @@
}
})
}
-
- 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)
}
diff --git a/python/builder.go b/python/builder.go
index f7f9a99..b4ab206 100644
--- a/python/builder.go
+++ b/python/builder.go
@@ -43,17 +43,7 @@
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 @@
"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 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 @@
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())
diff --git a/python/proto.go b/python/proto.go
index 53ebb58..400e72c 100644
--- a/python/proto.go
+++ b/python/proto.go
@@ -18,7 +18,7 @@
"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 @@
zipCmd := rule.Command().
BuiltTool("soong_zip").
FlagWithOutput("-o ", srcsZipFile)
- if pkgPath != "" {
- zipCmd.FlagWithArg("-P ", pkgPath)
- }
zipCmd.FlagWithArg("-C ", outDir.String()).
FlagWithArg("-D ", outDir.String())
diff --git a/python/python.go b/python/python.go
index 6f3a0ec..24e1bb2 100644
--- a/python/python.go
+++ b/python/python.go
@@ -120,15 +120,6 @@
// 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 @@
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 @@
}
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)
}
}
diff --git a/python/scripts/stub_template_host.txt b/python/scripts/stub_template_host.txt
index a0ddffe..5eedc18 100644
--- a/python/scripts/stub_template_host.txt
+++ b/python/scripts/stub_template_host.txt
@@ -23,16 +23,7 @@
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:
diff --git a/python/tests/dont_import_folder_of_entrypoint/Android.bp b/python/tests/dont_import_folder_of_entrypoint/Android.bp
index ea5076e..e54e9b2 100644
--- a/python/tests/dont_import_folder_of_entrypoint/Android.bp
+++ b/python/tests/dont_import_folder_of_entrypoint/Android.bp
@@ -9,7 +9,6 @@
"mypkg/main.py",
"mypkg/mymodule.py",
],
- defaults: ["modern_python_path_defaults"],
}
python_test_host {
diff --git a/python/tests/proto_pkg_path/Android.bp b/python/tests/proto_pkg_path/Android.bp
index ef79850..a6bfd3f 100644
--- a/python/tests/proto_pkg_path/Android.bp
+++ b/python/tests/proto_pkg_path/Android.bp
@@ -12,6 +12,5 @@
pkg_path: "mylib/subpackage",
proto: {
canonical_path_from_root: false,
- respect_pkg_path: true,
},
}
diff --git a/python/tests/top_level_dirs/Android.bp b/python/tests/top_level_dirs/Android.bp
index fe13d4f..574350a 100644
--- a/python/tests/top_level_dirs/Android.bp
+++ b/python/tests/top_level_dirs/Android.bp
@@ -9,5 +9,4 @@
"main.py",
"mypkg/mymodule.py",
],
- dont_add_top_level_directories_to_path: true,
}