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
This commit is contained in:
@@ -27,15 +27,3 @@ bootstrap_go_package {
|
|||||||
],
|
],
|
||||||
pluginFor: ["soong_build"],
|
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,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
@@ -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
|
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
|
||||||
// explicitly.
|
// explicitly.
|
||||||
Auto_gen_config *bool
|
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 {
|
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,
|
binFile := registerBuildActionForParFile(ctx, embeddedLauncher, launcherPath,
|
||||||
binary.getHostInterpreterName(ctx, actualVersion),
|
binary.getHostInterpreterName(ctx, actualVersion),
|
||||||
main, binary.getStem(ctx), append(android.Paths{srcsZip}, depsSrcsZips...),
|
main, binary.getStem(ctx), append(android.Paths{srcsZip}, depsSrcsZips...))
|
||||||
addTopDirectoriesToPath, dontAddEntrypointFolderToPath)
|
|
||||||
|
|
||||||
return android.OptionalPathForPath(binFile)
|
return android.OptionalPathForPath(binFile)
|
||||||
}
|
}
|
||||||
|
@@ -43,17 +43,7 @@ var (
|
|||||||
|
|
||||||
hostPar = pctx.AndroidStaticRule("hostPar",
|
hostPar = pctx.AndroidStaticRule("hostPar",
|
||||||
blueprint.RuleParams{
|
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 && ` +
|
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 && ` +
|
||||||
`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 && ` +
|
|
||||||
"sed -e 's/ENTRY_POINT/$main/g' build/soong/python/scripts/main_non_embedded.py >`dirname $out`/__soong_entrypoint_redirector__.py && " +
|
"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 && " +
|
"$parCmd -o $out.entrypoint_zip -C `dirname $out` -f `dirname $out`/__soong_entrypoint_redirector__.py && " +
|
||||||
`echo "#!/usr/bin/env $interp" >${out}.prefix &&` +
|
`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)",
|
"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"},
|
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",
|
embeddedPar = pctx.AndroidStaticRule("embeddedPar",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
@@ -92,7 +82,7 @@ func init() {
|
|||||||
|
|
||||||
func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher bool,
|
func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher bool,
|
||||||
launcherPath android.OptionalPath, interpreter, main, binName string,
|
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.
|
// .intermediate output path for bin executable.
|
||||||
binFile := android.PathForModuleOut(ctx, binName)
|
binFile := android.PathForModuleOut(ctx, binName)
|
||||||
@@ -101,37 +91,17 @@ func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher b
|
|||||||
implicits := srcsZips
|
implicits := srcsZips
|
||||||
|
|
||||||
if !embeddedLauncher {
|
if !embeddedLauncher {
|
||||||
addDirsString := "False"
|
ctx.Build(pctx, android.BuildParams{
|
||||||
if addTopDirectoriesToPath {
|
Rule: hostPar,
|
||||||
addDirsString = "True"
|
Description: "host python archive",
|
||||||
}
|
Output: binFile,
|
||||||
if dontAddEntrypointFolderToPath {
|
Implicits: implicits,
|
||||||
ctx.Build(pctx, android.BuildParams{
|
Args: map[string]string{
|
||||||
Rule: hostParWithoutAddingEntrypointFolderToPath,
|
"interp": strings.Replace(interpreter, "/", `\/`, -1),
|
||||||
Description: "host python archive",
|
"main": strings.Replace(strings.TrimSuffix(main, pyExt), "/", ".", -1),
|
||||||
Output: binFile,
|
"srcsZips": strings.Join(srcsZips.Strings(), " "),
|
||||||
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,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else if launcherPath.Valid() {
|
} else if launcherPath.Valid() {
|
||||||
// added launcherPath to the implicits Ninja dependencies.
|
// added launcherPath to the implicits Ninja dependencies.
|
||||||
implicits = append(implicits, launcherPath.Path())
|
implicits = append(implicits, launcherPath.Path())
|
||||||
|
@@ -18,7 +18,7 @@ import (
|
|||||||
"android/soong/android"
|
"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")
|
srcsZipFile := android.PathForModuleGen(ctx, protoFile.Base()+".srcszip")
|
||||||
|
|
||||||
outDir := srcsZipFile.ReplaceExtension(ctx, "tmp")
|
outDir := srcsZipFile.ReplaceExtension(ctx, "tmp")
|
||||||
@@ -36,9 +36,6 @@ func genProto(ctx android.ModuleContext, protoFile android.Path, flags android.P
|
|||||||
zipCmd := rule.Command().
|
zipCmd := rule.Command().
|
||||||
BuiltTool("soong_zip").
|
BuiltTool("soong_zip").
|
||||||
FlagWithOutput("-o ", srcsZipFile)
|
FlagWithOutput("-o ", srcsZipFile)
|
||||||
if pkgPath != "" {
|
|
||||||
zipCmd.FlagWithArg("-P ", pkgPath)
|
|
||||||
}
|
|
||||||
zipCmd.FlagWithArg("-C ", outDir.String()).
|
zipCmd.FlagWithArg("-C ", outDir.String()).
|
||||||
FlagWithArg("-D ", outDir.String())
|
FlagWithArg("-D ", outDir.String())
|
||||||
|
|
||||||
|
@@ -120,15 +120,6 @@ type BaseProperties struct {
|
|||||||
// whether the binary is required to be built with embedded launcher for this actual_version.
|
// 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
|
// this is set by the python version mutator based on version-specific properties
|
||||||
Embedded_launcher *bool `blueprint:"mutated"`
|
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 {
|
type baseAttributes struct {
|
||||||
@@ -677,9 +668,7 @@ func (p *Module) createSrcsZip(ctx android.ModuleContext, pkgPath string) androi
|
|||||||
protoFlags := android.GetProtoFlags(ctx, &p.protoProperties)
|
protoFlags := android.GetProtoFlags(ctx, &p.protoProperties)
|
||||||
protoFlags.OutTypeFlag = "--python_out"
|
protoFlags.OutTypeFlag = "--python_out"
|
||||||
|
|
||||||
protosRespectPkgPath := proptools.BoolDefault(p.properties.Proto.Respect_pkg_path, true)
|
if pkgPath != "" {
|
||||||
pkgPathForProtos := pkgPath
|
|
||||||
if pkgPathForProtos != "" && protosRespectPkgPath {
|
|
||||||
pkgPathStagingDir := android.PathForModuleGen(ctx, "protos_staged_for_pkg_path")
|
pkgPathStagingDir := android.PathForModuleGen(ctx, "protos_staged_for_pkg_path")
|
||||||
rule := android.NewRuleBuilder(pctx, ctx)
|
rule := android.NewRuleBuilder(pctx, ctx)
|
||||||
var stagedProtoSrcs android.Paths
|
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")
|
rule.Build("stage_protos_for_pkg_path", "Stage protos for pkg_path")
|
||||||
protoSrcs = stagedProtoSrcs
|
protoSrcs = stagedProtoSrcs
|
||||||
pkgPathForProtos = ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, srcFile := range protoSrcs {
|
for _, srcFile := range protoSrcs {
|
||||||
zip := genProto(ctx, srcFile, protoFlags, pkgPathForProtos)
|
zip := genProto(ctx, srcFile, protoFlags)
|
||||||
zips = append(zips, zip)
|
zips = append(zips, zip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,16 +23,7 @@ def Main():
|
|||||||
zf.extractall(runfiles_path)
|
zf.extractall(runfiles_path)
|
||||||
zf.close()
|
zf.close()
|
||||||
|
|
||||||
# Add runfiles path to PYTHONPATH.
|
new_python_path = runfiles_path
|
||||||
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)
|
|
||||||
old_python_path = os.environ.get(PYTHON_PATH)
|
old_python_path = os.environ.get(PYTHON_PATH)
|
||||||
|
|
||||||
if old_python_path:
|
if old_python_path:
|
||||||
|
@@ -9,7 +9,6 @@ python_test_host {
|
|||||||
"mypkg/main.py",
|
"mypkg/main.py",
|
||||||
"mypkg/mymodule.py",
|
"mypkg/mymodule.py",
|
||||||
],
|
],
|
||||||
defaults: ["modern_python_path_defaults"],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
python_test_host {
|
python_test_host {
|
||||||
|
@@ -12,6 +12,5 @@ python_test_host {
|
|||||||
pkg_path: "mylib/subpackage",
|
pkg_path: "mylib/subpackage",
|
||||||
proto: {
|
proto: {
|
||||||
canonical_path_from_root: false,
|
canonical_path_from_root: false,
|
||||||
respect_pkg_path: true,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -9,5 +9,4 @@ python_test_host {
|
|||||||
"main.py",
|
"main.py",
|
||||||
"mypkg/mymodule.py",
|
"mypkg/mymodule.py",
|
||||||
],
|
],
|
||||||
dont_add_top_level_directories_to_path: true,
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user