aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2019-02-16 22:33:00 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-02-16 22:33:00 +0000
commit41364fe521b39d01404d3df2703f31897389d0f0 (patch)
treed5b15d35c18e2e21f0c7f9276fe4c87770bf1600 /python
parentd8c94cb566ea4d98794a367d5798638a44d13977 (diff)
parent707542f2989751e9a834e5d0bd30dc23cbcc8d16 (diff)
downloadandroid_build_soong-41364fe521b39d01404d3df2703f31897389d0f0.tar.gz
android_build_soong-41364fe521b39d01404d3df2703f31897389d0f0.tar.bz2
android_build_soong-41364fe521b39d01404d3df2703f31897389d0f0.zip
Merge "Simplify python launcher, use __main__.py"
Diffstat (limited to 'python')
-rw-r--r--python/builder.go25
-rw-r--r--python/scripts/main.py12
2 files changed, 22 insertions, 15 deletions
diff --git a/python/builder.go b/python/builder.go
index cbbe56e4..e277bfd9 100644
--- a/python/builder.go
+++ b/python/builder.go
@@ -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(),
},
})
}
diff --git a/python/scripts/main.py b/python/scripts/main.py
new file mode 100644
index 00000000..225dbe4c
--- /dev/null
+++ b/python/scripts/main.py
@@ -0,0 +1,12 @@
+import runpy
+import sys
+
+sys.argv[0] = __loader__.archive
+
+# Set sys.executable to None. The real executable is available as
+# sys.argv[0], and too many things assume sys.executable is a regular Python
+# binary, which isn't available. By setting it to None we get clear errors
+# when people try to use it.
+sys.executable = None
+
+runpy._run_module_as_main("ENTRY_POINT", alter_argv=False)