Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Add a flag to build library only source tree. #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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