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
diff --git a/python/builder.go b/python/builder.go
index cbbe56e..e277bfd 100644
--- a/python/builder.go
+++ b/python/builder.go
@@ -54,15 +54,14 @@
 
 	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 @@
 		// 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(),
 			},
 		})
 	}