From 98c306ce9bc9eae35987fe4fe502f8d0a19f94a5 Mon Sep 17 00:00:00 2001 From: Ben Collins Date: Sat, 18 Jul 2015 12:14:19 -0500 Subject: [PATCH] Merged pull request http://github.com/mitchellh/gox/pull/8 --- go.go | 42 +++++++++++++++++++++++++++++++----------- main.go | 3 ++- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/go.go b/go.go index e001b63..8f53095 100644 --- a/go.go +++ b/go.go @@ -46,7 +46,9 @@ func GoCrossCompile(opts *CompileOpts) error { return err } tplData := OutputTemplateData{ - Dir: filepath.Base(opts.PackagePath), + // If compiling a file, use that file's name without extension. + // Otherwise use the package name + Dir: filepath.Base(strings.TrimSuffix(opts.PackagePath, ".go")), OS: opts.Platform.OS, Arch: opts.Platform.Arch, } @@ -68,9 +70,9 @@ func GoCrossCompile(opts *CompileOpts) error { // Go prefixes the import directory with '_' when it is outside // the GOPATH.For this, we just drop it since we move to that - // directory to build. + // directory to build. Only do this for packages, not files. chdir := "" - if opts.PackagePath[0] == '_' { + if opts.PackagePath[0] == '_' && filepath.Ext(opts.PackagePath) != ".go" { if runtime.GOOS == "windows" { // We have to replace weird paths like this: // @@ -108,17 +110,33 @@ func GoCrossCompile(opts *CompileOpts) error { // GoMainDirs returns the file paths to the packages that are "main" // packages, from the list of packages given. The list of packages can // include relative paths, the special "..." Go keyword, etc. -func GoMainDirs(packages []string) ([]string, error) { - args := make([]string, 0, len(packages)+3) - args = append(args, "list", "-f", "{{.Name}}|{{.ImportPath}}") - args = append(args, packages...) +func GoMainDirs(compileThese []string) ([]string, error) { + // Separate the packages from the files + files := make([]string, 0) + packages := make([]string, 0) + for _, p := range compileThese { + if filepath.Ext(p) == ".go" { + files = append(files, p) + } else { + packages = append(packages, p) + } + } - output, err := execGo(nil, "", args...) - if err != nil { - return nil, err + results := make([]string, 0) + output := "" + + if len(packages) != 0 { + args := make([]string, 0, len(packages)+3) + args = append(args, "list", "-f", "{{.Name}}|{{.ImportPath}}") + args = append(args, packages...) + + var err error + output, err = execGo(nil, "", args...) + if err != nil { + return nil, err + } } - results := make([]string, 0, len(output)) for _, line := range strings.Split(output, "\n") { if line == "" { continue @@ -135,6 +153,8 @@ func GoMainDirs(packages []string) ([]string, error) { } } + results = append(results, files...) + return results, nil } diff --git a/main.go b/main.go index be8c3ee..faadf24 100644 --- a/main.go +++ b/main.go @@ -146,7 +146,8 @@ func printUsage() { const helpText = `Usage: gox [options] [packages] - Gox cross-compiles Go applications in parallel. + Gox cross-compiles Go applications in parallel. (Patched version, see + https://github.com/mitchellh/gox/pull/8) If no specific operating systems or architectures are specified, Gox will build for all pairs supported by your version of Go.