Loading cmd/merge_zips/merge_zips.go +17 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import ( "flag" "fmt" "hash/crc32" "io" "io/ioutil" "log" "os" Loading Loading @@ -66,6 +67,7 @@ var ( manifest = flag.String("m", "", "manifest file to insert in jar") pyMain = flag.String("pm", "", "__main__.py file to insert in par") entrypoint = flag.String("e", "", "par entrypoint file to insert in par") prefix = flag.String("prefix", "", "A file to prefix to the zip file") ignoreDuplicates = flag.Bool("ignore-duplicates", false, "take each entry from the first zip it exists in and don't warn") ) Loading @@ -77,7 +79,7 @@ func init() { func main() { flag.Usage = func() { fmt.Fprintln(os.Stderr, "usage: merge_zips [-jpsD] [-m manifest] [-e entrypoint] [-pm __main__.py] output [inputs...]") fmt.Fprintln(os.Stderr, "usage: merge_zips [-jpsD] [-m manifest] [--prefix script] [-e entrypoint] [-pm __main__.py] output [inputs...]") flag.PrintDefaults() } Loading @@ -99,6 +101,19 @@ func main() { log.Fatal(err) } defer output.Close() var offset int64 if *prefix != "" { prefixFile, err := os.Open(*prefix) if err != nil { log.Fatal(err) } offset, err = io.Copy(output, prefixFile) if err != nil { log.Fatal(err) } } writer := zip.NewWriter(output) defer func() { err := writer.Close() Loading @@ -106,6 +121,7 @@ func main() { log.Fatal(err) } }() writer.SetOffset(offset) // make readers readers := []namedZipReader{} Loading python/builder.go +15 −18 Original line number Diff line number Diff line Loading @@ -45,20 +45,22 @@ var ( hostPar = pctx.AndroidStaticRule("hostPar", blueprint.RuleParams{ Command: `sed -e 's/%interpreter%/$interp/g' -e 's/%main%/$main/g' $template > $stub && ` + `$mergeParCmd -p -pm $stub $mergedZip $srcsZips && echo '#!/usr/bin/env python' | cat - $mergedZip > $out && ` + `chmod +x $out && (rm -f $stub; rm -f $mergedZip)`, `echo "#!/usr/bin/env python" >${out}.prefix &&` + `$mergeParCmd -p --prefix ${out}.prefix -pm $stub $out $srcsZips && ` + `chmod +x $out && (rm -f $stub; rm -f ${out}.prefix)`, CommandDeps: []string{"$mergeParCmd"}, }, "interp", "main", "template", "stub", "mergedZip", "srcsZips") "interp", "main", "template", "stub", "srcsZips") embeddedPar = pctx.AndroidStaticRule("embeddedPar", blueprint.RuleParams{ Command: `echo '$main' > $entryPoint &&` + `$mergeParCmd -p -e $entryPoint $mergedZip $srcsZips && cat $launcher | cat - $mergedZip > $out && ` + `chmod +x $out && (rm -f $entryPoint; rm -f $mergedZip)`, // `echo -n` to trim the newline, since the python code just wants the name Command: `echo -n '$main' > $entryPoint &&` + `$mergeParCmd -p --prefix $launcher -e $entryPoint $out $srcsZips && ` + `chmod +x $out && (rm -f $entryPoint)`, CommandDeps: []string{"$mergeParCmd"}, }, "main", "entryPoint", "mergedZip", "srcsZips", "launcher") "main", "entryPoint", "srcsZips", "launcher") ) func init() { Loading @@ -73,9 +75,6 @@ func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher b launcherPath android.OptionalPath, interpreter, main, binName string, srcsZips android.Paths) android.Path { // .intermediate output path for merged zip file. mergedZip := android.PathForModuleOut(ctx, binName+".mergedzip") // .intermediate output path for bin executable. binFile := android.PathForModuleOut(ctx, binName) Loading @@ -100,7 +99,6 @@ func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher b "main": strings.Replace(main, "/", `\/`, -1), "template": template.String(), "stub": stub, "mergedZip": mergedZip.String(), "srcsZips": strings.Join(srcsZips.Strings(), " "), }, }) Loading @@ -117,9 +115,8 @@ func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher b Output: binFile, Implicits: implicits, Args: map[string]string{ "main": main, "main": strings.Replace(strings.TrimSuffix(main, pyExt), "/", ".", -1), "entryPoint": entryPoint, "mergedZip": mergedZip.String(), "srcsZips": strings.Join(srcsZips.Strings(), " "), "launcher": launcherPath.String(), }, Loading Loading
cmd/merge_zips/merge_zips.go +17 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import ( "flag" "fmt" "hash/crc32" "io" "io/ioutil" "log" "os" Loading Loading @@ -66,6 +67,7 @@ var ( manifest = flag.String("m", "", "manifest file to insert in jar") pyMain = flag.String("pm", "", "__main__.py file to insert in par") entrypoint = flag.String("e", "", "par entrypoint file to insert in par") prefix = flag.String("prefix", "", "A file to prefix to the zip file") ignoreDuplicates = flag.Bool("ignore-duplicates", false, "take each entry from the first zip it exists in and don't warn") ) Loading @@ -77,7 +79,7 @@ func init() { func main() { flag.Usage = func() { fmt.Fprintln(os.Stderr, "usage: merge_zips [-jpsD] [-m manifest] [-e entrypoint] [-pm __main__.py] output [inputs...]") fmt.Fprintln(os.Stderr, "usage: merge_zips [-jpsD] [-m manifest] [--prefix script] [-e entrypoint] [-pm __main__.py] output [inputs...]") flag.PrintDefaults() } Loading @@ -99,6 +101,19 @@ func main() { log.Fatal(err) } defer output.Close() var offset int64 if *prefix != "" { prefixFile, err := os.Open(*prefix) if err != nil { log.Fatal(err) } offset, err = io.Copy(output, prefixFile) if err != nil { log.Fatal(err) } } writer := zip.NewWriter(output) defer func() { err := writer.Close() Loading @@ -106,6 +121,7 @@ func main() { log.Fatal(err) } }() writer.SetOffset(offset) // make readers readers := []namedZipReader{} Loading
python/builder.go +15 −18 Original line number Diff line number Diff line Loading @@ -45,20 +45,22 @@ var ( hostPar = pctx.AndroidStaticRule("hostPar", blueprint.RuleParams{ Command: `sed -e 's/%interpreter%/$interp/g' -e 's/%main%/$main/g' $template > $stub && ` + `$mergeParCmd -p -pm $stub $mergedZip $srcsZips && echo '#!/usr/bin/env python' | cat - $mergedZip > $out && ` + `chmod +x $out && (rm -f $stub; rm -f $mergedZip)`, `echo "#!/usr/bin/env python" >${out}.prefix &&` + `$mergeParCmd -p --prefix ${out}.prefix -pm $stub $out $srcsZips && ` + `chmod +x $out && (rm -f $stub; rm -f ${out}.prefix)`, CommandDeps: []string{"$mergeParCmd"}, }, "interp", "main", "template", "stub", "mergedZip", "srcsZips") "interp", "main", "template", "stub", "srcsZips") embeddedPar = pctx.AndroidStaticRule("embeddedPar", blueprint.RuleParams{ Command: `echo '$main' > $entryPoint &&` + `$mergeParCmd -p -e $entryPoint $mergedZip $srcsZips && cat $launcher | cat - $mergedZip > $out && ` + `chmod +x $out && (rm -f $entryPoint; rm -f $mergedZip)`, // `echo -n` to trim the newline, since the python code just wants the name Command: `echo -n '$main' > $entryPoint &&` + `$mergeParCmd -p --prefix $launcher -e $entryPoint $out $srcsZips && ` + `chmod +x $out && (rm -f $entryPoint)`, CommandDeps: []string{"$mergeParCmd"}, }, "main", "entryPoint", "mergedZip", "srcsZips", "launcher") "main", "entryPoint", "srcsZips", "launcher") ) func init() { Loading @@ -73,9 +75,6 @@ func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher b launcherPath android.OptionalPath, interpreter, main, binName string, srcsZips android.Paths) android.Path { // .intermediate output path for merged zip file. mergedZip := android.PathForModuleOut(ctx, binName+".mergedzip") // .intermediate output path for bin executable. binFile := android.PathForModuleOut(ctx, binName) Loading @@ -100,7 +99,6 @@ func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher b "main": strings.Replace(main, "/", `\/`, -1), "template": template.String(), "stub": stub, "mergedZip": mergedZip.String(), "srcsZips": strings.Join(srcsZips.Strings(), " "), }, }) Loading @@ -117,9 +115,8 @@ func registerBuildActionForParFile(ctx android.ModuleContext, embeddedLauncher b Output: binFile, Implicits: implicits, Args: map[string]string{ "main": main, "main": strings.Replace(strings.TrimSuffix(main, pyExt), "/", ".", -1), "entryPoint": entryPoint, "mergedZip": mergedZip.String(), "srcsZips": strings.Join(srcsZips.Strings(), " "), "launcher": launcherPath.String(), }, Loading