Merge branch 'tsg-custom_image'

This commit is contained in:
Péter Szilágyi 2015-09-17 14:23:29 +03:00
commit 3544aa27ec
1 changed files with 12 additions and 5 deletions

17
xgo.go
View File

@ -28,6 +28,7 @@ var srcRemote = flag.String("remote", "", "Version control remote repository to
var srcBranch = flag.String("branch", "", "Version control branch to build") var srcBranch = flag.String("branch", "", "Version control branch to build")
var crossDeps = flag.String("deps", "", "CGO dependencies (configure/make based archives)") var crossDeps = flag.String("deps", "", "CGO dependencies (configure/make based archives)")
var targets = flag.String("targets", "*/*", "Comma separated targets to build for") var targets = flag.String("targets", "*/*", "Comma separated targets to build for")
var dockerImage = flag.String("image", "", "Use a custom docker image instead of official distribution")
// Command line arguments to pass to go build // Command line arguments to pass to go build
var buildVerbose = flag.Bool("v", false, "Print the names of packages as they are compiled") var buildVerbose = flag.Bool("v", false, "Print the names of packages as they are compiled")
@ -45,21 +46,27 @@ func main() {
if len(flag.Args()) != 1 { if len(flag.Args()) != 1 {
log.Fatalf("Usage: %s [options] <go import path>", os.Args[0]) log.Fatalf("Usage: %s [options] <go import path>", os.Args[0])
} }
image := dockerDist + *goVersion
if dockerImage != nil {
image = *dockerImage
}
// Check that all required images are available // Check that all required images are available
found, err := checkDockerImage(dockerDist + *goVersion) found, err := checkDockerImage(image)
switch { switch {
case err != nil: case err != nil:
log.Fatalf("Failed to check docker image availability: %v.", err) log.Fatalf("Failed to check docker image availability: %v.", err)
case !found: case !found:
fmt.Println("not found!") fmt.Println("not found!")
if err := pullDockerImage(dockerDist + *goVersion); err != nil { if err := pullDockerImage(image); err != nil {
log.Fatalf("Failed to pull docker image from the registry: %v.", err) log.Fatalf("Failed to pull docker image from the registry: %v.", err)
} }
default: default:
fmt.Println("found.") fmt.Println("found.")
} }
// Cross compile the requested package into the local folder // Cross compile the requested package into the local folder
if err := compile(flag.Args()[0], *srcRemote, *srcBranch, *inPackage, *crossDeps, *outPrefix, *buildVerbose, *buildSteps, *buildRace, strings.Split(*targets, ",")); err != nil { if err := compile(flag.Args()[0], image, *srcRemote, *srcBranch, *inPackage, *crossDeps, *outPrefix, *buildVerbose, *buildSteps, *buildRace, strings.Split(*targets, ",")); err != nil {
log.Fatalf("Failed to cross compile package: %v.", err) log.Fatalf("Failed to cross compile package: %v.", err)
} }
} }
@ -91,7 +98,7 @@ func pullDockerImage(image string) error {
} }
// Cross compiles a requested package into the current working directory. // Cross compiles a requested package into the current working directory.
func compile(repo string, remote string, branch string, pack string, deps string, prefix string, verbose bool, steps bool, race bool, targets []string) error { func compile(repo string, image string, remote string, branch string, pack string, deps string, prefix string, verbose bool, steps bool, race bool, targets []string) error {
folder, err := os.Getwd() folder, err := os.Getwd()
if err != nil { if err != nil {
log.Fatalf("Failed to retrieve the working directory: %v.", err) log.Fatalf("Failed to retrieve the working directory: %v.", err)
@ -108,7 +115,7 @@ func compile(repo string, remote string, branch string, pack string, deps string
"-e", fmt.Sprintf("FLAG_X=%v", steps), "-e", fmt.Sprintf("FLAG_X=%v", steps),
"-e", fmt.Sprintf("FLAG_RACE=%v", race), "-e", fmt.Sprintf("FLAG_RACE=%v", race),
"-e", "TARGETS="+strings.Replace(strings.Join(targets, " "), "*", ".", -1), "-e", "TARGETS="+strings.Replace(strings.Join(targets, " "), "*", ".", -1),
dockerDist+*goVersion, repo)) image, repo))
} }
// Executes a command synchronously, redirecting its output to stdout. // Executes a command synchronously, redirecting its output to stdout.