Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b2ea6c19 authored by Cole Faust's avatar Cole Faust Committed by Gerrit Code Review
Browse files

Merge "Remove flags that enable the new python path behavior"

parents a38504fd caf766b7
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -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
Original line number Diff line number Diff line
@@ -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
Original line number Diff line number Diff line
@@ -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,24 +91,6 @@ 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",
@@ -126,12 +98,10 @@ func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher b
			Implicits:   implicits,
			Args: map[string]string{
				"interp":   strings.Replace(interpreter, "/", `\/`, -1),
					"main":                    strings.Replace(main, "/", `\/`, -1),
				"main":     strings.Replace(strings.TrimSuffix(main, pyExt), "/", ".", -1),
				"srcsZips": strings.Join(srcsZips.Strings(), " "),
					"addTopDirectoriesToPath": addDirsString,
			},
		})
		}
	} else if launcherPath.Valid() {
		// added launcherPath to the implicits Ninja dependencies.
		implicits = append(implicits, launcherPath.Path())
+1 −4
Original line number Diff line number Diff line
@@ -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
Original line number Diff line number Diff line
@@ -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)
		}
	}
Loading