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

Commit 2751df5c authored by Cole Faust's avatar Cole Faust Committed by Automerger Merge Worker
Browse files

Merge "Precompile python sources" am: 56080ddc

parents ab97575c 56080ddc
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -359,7 +359,8 @@ func (oz *OutputZip) getUninitializedPythonPackages(inputZips []InputZip) ([]str
		}
		for _, file := range inputZip.Entries() {
			pyPkg := getPackage(file.Name)
			if filepath.Base(file.Name) == "__init__.py" {
			baseName := filepath.Base(file.Name)
			if baseName == "__init__.py" || baseName == "__init__.pyc" {
				if _, found := initedPackages[pyPkg]; found {
					panic(fmt.Errorf("found __init__.py path duplicates during pars merging: %q", file.Name))
				}
+7 −7
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import (
	"android/soong/cc"
	"android/soong/dexpreopt"
	"android/soong/genrule"
	"android/soong/python"
)

// Legacy preparer used for running tests within the java package.
@@ -49,7 +48,6 @@ var prepareForJavaTest = android.GroupFixturePreparers(
	// Include all the default java modules.
	PrepareForTestWithJavaDefaultModules,
	PrepareForTestWithOverlayBuildComponents,
	python.PrepareForTestWithPythonBuildComponents,
	android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
		ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory)
	}),
@@ -1440,24 +1438,26 @@ func TestAidlEnforcePermissionsException(t *testing.T) {
}

func TestDataNativeBinaries(t *testing.T) {
	ctx, _ := testJava(t, `
	ctx := android.GroupFixturePreparers(
		prepareForJavaTest,
		android.PrepareForTestWithAllowMissingDependencies).RunTestWithBp(t, `
		java_test_host {
			name: "foo",
			srcs: ["a.java"],
			data_native_bins: ["bin"]
		}

		python_binary_host {
		cc_binary_host {
			name: "bin",
			srcs: ["bin.py"],
			srcs: ["bin.cpp"],
		}
	`)
	`).TestContext

	buildOS := ctx.Config().BuildOS.String()

	test := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost)
	entries := android.AndroidMkEntriesForTest(t, ctx, test)[0]
	expected := []string{"out/soong/.intermediates/bin/" + buildOS + "_x86_64_PY3/bin:bin"}
	expected := []string{"out/soong/.intermediates/bin/" + buildOS + "_x86_64/bin:bin"}
	actual := entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"]
	android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_COMPATIBILITY_SUPPORT_FILES", ctx.Config(), expected, actual)
}
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ bootstrap_go_package {
        "blueprint",
        "soong-android",
        "soong-tradefed",
        "soong-cc",
    ],
    srcs: [
        "binary.go",
+11 −62
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@ import (
	"path/filepath"
	"strings"

	"github.com/google/blueprint"

	"android/soong/android"
)

@@ -109,14 +107,14 @@ func (p *PythonBinaryModule) GenerateAndroidBuildActions(ctx android.ModuleConte
}

func (p *PythonBinaryModule) buildBinary(ctx android.ModuleContext) {
	depsSrcsZips := p.collectPathsFromTransitiveDeps(ctx)
	embeddedLauncher := p.isEmbeddedLauncherEnabled()
	depsSrcsZips := p.collectPathsFromTransitiveDeps(ctx, embeddedLauncher)
	main := ""
	if p.autorun() {
		main = p.getPyMainFile(ctx, p.srcsPathMappings)
	}

	var launcherPath android.OptionalPath
	embeddedLauncher := p.isEmbeddedLauncherEnabled()
	if embeddedLauncher {
		ctx.VisitDirectDepsWithTag(launcherTag, func(m android.Module) {
			if provider, ok := m.(IntermPathProvider); ok {
@@ -128,9 +126,16 @@ func (p *PythonBinaryModule) buildBinary(ctx android.ModuleContext) {
			}
		})
	}
	srcsZips := make(android.Paths, 0, len(depsSrcsZips)+1)
	if embeddedLauncher {
		srcsZips = append(srcsZips, p.precompiledSrcsZip)
	} else {
		srcsZips = append(srcsZips, p.srcsZip)
	}
	srcsZips = append(srcsZips, depsSrcsZips...)
	p.installSource = registerBuildActionForParFile(ctx, embeddedLauncher, launcherPath,
		p.getHostInterpreterName(ctx, p.properties.Actual_version),
		main, p.getStem(ctx), append(android.Paths{p.srcsZip}, depsSrcsZips...))
		main, p.getStem(ctx), srcsZips)

	var sharedLibs []string
	// if embedded launcher is enabled, we need to collect the shared library dependencies of the
@@ -170,64 +175,8 @@ func (p *PythonBinaryModule) AndroidMkEntries() []android.AndroidMkEntries {
func (p *PythonBinaryModule) DepsMutator(ctx android.BottomUpMutatorContext) {
	p.PythonLibraryModule.DepsMutator(ctx)

	versionVariation := []blueprint.Variation{
		{"python_version", p.properties.Actual_version},
	}

	// If this module will be installed and has an embedded launcher, we need to add dependencies for:
	//   * standard library
	//   * launcher
	//   * shared dependencies of the launcher
	if p.isEmbeddedLauncherEnabled() {
		var stdLib string
		var launcherModule string
		// Add launcher shared lib dependencies. Ideally, these should be
		// derived from the `shared_libs` property of the launcher. However, we
		// cannot read the property at this stage and it will be too late to add
		// dependencies later.
		launcherSharedLibDeps := []string{
			"libsqlite",
		}
		// Add launcher-specific dependencies for bionic
		if ctx.Target().Os.Bionic() {
			launcherSharedLibDeps = append(launcherSharedLibDeps, "libc", "libdl", "libm")
		}
		if ctx.Target().Os == android.LinuxMusl && !ctx.Config().HostStaticBinaries() {
			launcherSharedLibDeps = append(launcherSharedLibDeps, "libc_musl")
		}

		switch p.properties.Actual_version {
		case pyVersion2:
			stdLib = "py2-stdlib"

			launcherModule = "py2-launcher"
			if p.autorun() {
				launcherModule = "py2-launcher-autorun"
			}

			launcherSharedLibDeps = append(launcherSharedLibDeps, "libc++")

		case pyVersion3:
			stdLib = "py3-stdlib"

			launcherModule = "py3-launcher"
			if p.autorun() {
				launcherModule = "py3-launcher-autorun"
			}
			if ctx.Config().HostStaticBinaries() && ctx.Target().Os == android.LinuxMusl {
				launcherModule += "-static"
			}

			if ctx.Device() {
				launcherSharedLibDeps = append(launcherSharedLibDeps, "liblog")
			}
		default:
			panic(fmt.Errorf("unknown Python Actual_version: %q for module: %q.",
				p.properties.Actual_version, ctx.ModuleName()))
		}
		ctx.AddVariationDependencies(versionVariation, pythonLibTag, stdLib)
		ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherTag, launcherModule)
		ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherSharedLibTag, launcherSharedLibDeps...)
		p.AddDepsOnPythonLauncherAndStdlib(ctx, pythonLibTag, launcherTag, launcherSharedLibTag, p.autorun(), ctx.Target())
	}
}

+11 −0
Original line number Diff line number Diff line
@@ -70,6 +70,17 @@ var (
			CommandDeps: []string{"$mergeParCmd"},
		},
		"srcsZips", "launcher")

	precompile = pctx.AndroidStaticRule("precompilePython", blueprint.RuleParams{
		Command: `LD_LIBRARY_PATH="$ldLibraryPath" ` +
			`PYTHONPATH=$stdlibZip/internal/stdlib ` +
			`$launcher build/soong/python/scripts/precompile_python.py $in $out`,
		CommandDeps: []string{
			"$stdlibZip",
			"$launcher",
			"build/soong/python/scripts/precompile_python.py",
		},
	}, "stdlibZip", "launcher", "ldLibraryPath")
)

func init() {
Loading