diff --git a/go.go b/go.go index 37edb36..58f5fd3 100644 --- a/go.go +++ b/go.go @@ -122,7 +122,7 @@ 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, GoCmd string) ([]string, error) { +func GoMainDirs(packages []string, GoCmd string, cmdOnly bool) ([]string, error) { args := make([]string, 0, len(packages)+3) args = append(args, "list", "-f", "{{.Name}}|{{.ImportPath}}") args = append(args, packages...) @@ -144,9 +144,10 @@ func GoMainDirs(packages []string, GoCmd string) ([]string, error) { continue } - if parts[0] == "main" { - results = append(results, parts[1]) + if parts[0] != "main" && cmdOnly { + continue } + results = append(results, parts[1]) } return results, nil diff --git a/main.go b/main.go index d8098c9..4b52569 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,7 @@ func realMain() int { var tags string var verbose bool var flagGcflags, flagAsmflags string - var flagCgo, flagRebuild, flagListOSArch bool + var flagCgo, flagRebuild, flagBuildLib, flagListOSArch bool var flagGoCmd string flags := flag.NewFlagSet("gox", flag.ExitOnError) flags.Usage = func() { printUsage() } @@ -39,6 +39,7 @@ func realMain() int { flags.BoolVar(&verbose, "verbose", false, "verbose") flags.BoolVar(&flagCgo, "cgo", false, "") flags.BoolVar(&flagRebuild, "rebuild", false, "") + flags.BoolVar(&flagBuildLib, "build-lib", false, "") flags.BoolVar(&flagListOSArch, "osarch-list", false, "") flags.StringVar(&flagGcflags, "gcflags", "", "") flags.StringVar(&flagAsmflags, "asmflags", "", "") @@ -95,7 +96,7 @@ func realMain() int { } // Get the packages that are in the given paths - mainDirs, err := GoMainDirs(packages, flagGoCmd) + mainDirs, err := GoMainDirs(packages, flagGoCmd, !flagBuildLib) if err != nil { fmt.Fprintf(os.Stderr, "Error reading packages: %s", err) return 1 @@ -194,6 +195,7 @@ Options: -parallel=-1 Amount of parallelism, defaults to number of CPUs -gocmd="go" Build command, defaults to Go -rebuild Force rebuilding of package that were up to date + -build-lib Force the build of a library package. By default gox only build for main packages. -verbose Verbose mode Output path template: