Skip to content

Commit

Permalink
Add a flag to build library only source tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgsb committed Oct 9, 2018
1 parent 51ed453 commit 175230e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions go.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand All @@ -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", "", "")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 175230e

Please sign in to comment.