Simplify python launcher, use __main__.py

Uses more python rather than C++, and skips less of Py_Main.

Test: build/soong/python/tests/runtests.sh
Change-Id: I03997d88e2e16047c96bb4e00e530229c42b3325
This commit is contained in:
Dan Willemsen
2018-11-29 21:39:59 -08:00
parent 7b88d7c9f6
commit 707542f298
4 changed files with 26 additions and 40 deletions

View File

@@ -54,15 +54,14 @@ var (
embeddedPar = pctx.AndroidStaticRule("embeddedPar",
blueprint.RuleParams{
// `echo -n` to trim the newline, since the python code just wants the name.
// /bin/sh (used by ninja) on Mac turns off posix mode, and stops supporting -n.
// Explicitly use bash instead.
Command: `/bin/bash -c "echo -n '$main' > $entryPoint" &&` +
`$mergeParCmd -p --prefix $launcher -e $entryPoint $out $srcsZips && ` +
`chmod +x $out && (rm -f $entryPoint)`,
CommandDeps: []string{"$mergeParCmd"},
// `echo -n` to trim the newline, since the python code just wants the name
Command: `rm -f $out.main && ` +
`sed 's/ENTRY_POINT/$main/' build/soong/python/scripts/main.py >$out.main &&` +
`$mergeParCmd -p -pm $out.main --prefix $launcher $out $srcsZips && ` +
`chmod +x $out && rm -rf $out.main`,
CommandDeps: []string{"$mergeParCmd", "$parCmd", "build/soong/python/scripts/main.py"},
},
"main", "entryPoint", "srcsZips", "launcher")
"main", "srcsZips", "launcher")
)
func init() {
@@ -108,19 +107,15 @@ func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher b
// added launcherPath to the implicits Ninja dependencies.
implicits = append(implicits, launcherPath.Path())
// .intermediate output path for entry_point.txt
entryPoint := android.PathForModuleOut(ctx, entryPointFile).String()
ctx.Build(pctx, android.BuildParams{
Rule: embeddedPar,
Description: "embedded python archive",
Output: binFile,
Implicits: implicits,
Args: map[string]string{
"main": strings.Replace(strings.TrimSuffix(main, pyExt), "/", ".", -1),
"entryPoint": entryPoint,
"srcsZips": strings.Join(srcsZips.Strings(), " "),
"launcher": launcherPath.String(),
"main": strings.Replace(strings.TrimSuffix(main, pyExt), "/", ".", -1),
"srcsZips": strings.Join(srcsZips.Strings(), " "),
"launcher": launcherPath.String(),
},
})
}