mirror of
https://github.com/status-im/xgo.git
synced 2025-01-30 20:35:00 +00:00
Support branch selection and building subpackages.
This commit is contained in:
parent
ccc86dbdce
commit
6bf2b5727f
@ -89,11 +89,19 @@ ENV GOPATH /go
|
|||||||
ENV BUILD ./build.sh
|
ENV BUILD ./build.sh
|
||||||
RUN \
|
RUN \
|
||||||
echo '#!/bin/bash' > $BUILD && \
|
echo '#!/bin/bash' > $BUILD && \
|
||||||
echo 'set -e' >> $BUILD && \
|
|
||||||
echo >> $BUILD && \
|
echo >> $BUILD && \
|
||||||
echo 'echo Fetching $1...' >> $BUILD && \
|
echo 'echo Fetching $1...' >> $BUILD && \
|
||||||
echo 'go get $1' >> $BUILD && \
|
echo 'go get -d $1' >> $BUILD && \
|
||||||
echo 'cd $GOPATH/src/$1' >> $BUILD && \
|
echo 'cd $GOPATH/src/$1' >> $BUILD && \
|
||||||
|
echo 'export GOPATH=$GOPATH:`pwd`/Godeps/_workspace' >> $BUILD && \
|
||||||
|
echo >> $BUILD && \
|
||||||
|
echo 'if [ "$BRANCH" != "" ]; then' >> $BUILD && \
|
||||||
|
echo ' if [ -d ".git" ]; then' >> $BUILD && \
|
||||||
|
echo ' git checkout $BRANCH' >> $BUILD && \
|
||||||
|
echo ' elif [ -d ".hg" ]; then' >> $BUILD && \
|
||||||
|
echo ' hg checkout $BRANCH' >> $BUILD && \
|
||||||
|
echo ' fi' >> $BUILD && \
|
||||||
|
echo 'fi' >> $BUILD && \
|
||||||
echo >> $BUILD && \
|
echo >> $BUILD && \
|
||||||
echo 'NAME=`basename $1`' >> $BUILD && \
|
echo 'NAME=`basename $1`' >> $BUILD && \
|
||||||
echo 'if [ "$OUT" != "" ]; then' >> $BUILD && \
|
echo 'if [ "$OUT" != "" ]; then' >> $BUILD && \
|
||||||
@ -104,33 +112,33 @@ RUN \
|
|||||||
echo 'if [ "$FLAG_RACE" == "true" ]; then R=-race; fi' >> $BUILD && \
|
echo 'if [ "$FLAG_RACE" == "true" ]; then R=-race; fi' >> $BUILD && \
|
||||||
echo >> $BUILD && \
|
echo >> $BUILD && \
|
||||||
echo 'echo Compiling for linux/amd64...' >> $BUILD && \
|
echo 'echo Compiling for linux/amd64...' >> $BUILD && \
|
||||||
echo 'GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go get' >> $BUILD && \
|
echo 'GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go get -d ./$PACK' >> $BUILD && \
|
||||||
echo 'GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build $V $R -o $NAME-linux-amd64$R' >> $BUILD && \
|
echo 'GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build $V $R -o $NAME-linux-amd64$R ./$PACK' >> $BUILD && \
|
||||||
echo >> $BUILD && \
|
echo >> $BUILD && \
|
||||||
echo 'echo Compiling for linux/386...' >> $BUILD && \
|
echo 'echo Compiling for linux/386...' >> $BUILD && \
|
||||||
echo 'GOOS=linux GOARCH=386 CGO_ENABLED=1 go get' >> $BUILD && \
|
echo 'GOOS=linux GOARCH=386 CGO_ENABLED=1 go get -d ./$PACK' >> $BUILD && \
|
||||||
echo 'GOOS=linux GOARCH=386 CGO_ENABLED=1 go build $V -o $NAME-linux-386' >> $BUILD && \
|
echo 'GOOS=linux GOARCH=386 CGO_ENABLED=1 go build $V -o $NAME-linux-386 ./$PACK' >> $BUILD && \
|
||||||
echo >> $BUILD && \
|
echo >> $BUILD && \
|
||||||
echo 'echo Compiling for linux/arm...' >> $BUILD && \
|
echo 'echo Compiling for linux/arm...' >> $BUILD && \
|
||||||
echo 'CC=arm-linux-gnueabi-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 GOARM=5 go get' >> $BUILD && \
|
echo 'CC=arm-linux-gnueabi-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 GOARM=5 go get -d ./$PACK' >> $BUILD && \
|
||||||
echo 'CC=arm-linux-gnueabi-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 GOARM=5 go build $V -o $NAME-linux-arm' >> $BUILD && \
|
echo 'CC=arm-linux-gnueabi-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 GOARM=5 go build $V -o $NAME-linux-arm ./$PACK' >> $BUILD && \
|
||||||
echo >> $BUILD && \
|
echo >> $BUILD && \
|
||||||
echo 'echo Compiling for windows/amd64...' >> $BUILD && \
|
echo 'echo Compiling for windows/amd64...' >> $BUILD && \
|
||||||
echo 'CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go get' >> $BUILD && \
|
echo 'CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go get -d ./$PACK' >> $BUILD && \
|
||||||
echo 'CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build $V $R -o $NAME-windows-amd64$R.exe' >> $BUILD && \
|
echo 'CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build $V $R -o $NAME-windows-amd64$R.exe ./$PACK' >> $BUILD && \
|
||||||
echo >> $BUILD && \
|
echo >> $BUILD && \
|
||||||
echo 'echo Compiling for windows/386...' >> $BUILD && \
|
echo 'echo Compiling for windows/386...' >> $BUILD && \
|
||||||
echo 'CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 CGO_ENABLED=1 go get' >> $BUILD && \
|
echo 'CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 CGO_ENABLED=1 go get -d ./$PACK' >> $BUILD && \
|
||||||
echo 'CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 CGO_ENABLED=1 go build $V -o $NAME-windows-386.exe' >> $BUILD && \
|
echo 'CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 CGO_ENABLED=1 go build $V -o $NAME-windows-386.exe ./$PACK' >> $BUILD && \
|
||||||
echo >> $BUILD && \
|
echo >> $BUILD && \
|
||||||
echo 'echo Compiling for darwin/amd64...' >> $BUILD && \
|
echo 'echo Compiling for darwin/amd64...' >> $BUILD && \
|
||||||
echo '`/osxcross/target/bin/osxcross-env`' >> $BUILD && \
|
echo '`/osxcross/target/bin/osxcross-env`' >> $BUILD && \
|
||||||
echo 'CC=o64-clang GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go get' >> $BUILD && \
|
echo 'CC=o64-clang GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go get -d ./$PACK' >> $BUILD && \
|
||||||
echo 'CC=o64-clang GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build $V $R -o $NAME-darwin-amd64$R' >> $BUILD && \
|
echo 'CC=o64-clang GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build $V $R -o $NAME-darwin-amd64$R ./$PACK' >> $BUILD && \
|
||||||
echo >> $BUILD && \
|
echo >> $BUILD && \
|
||||||
echo 'echo Compiling for darwin/386...' >> $BUILD && \
|
echo 'echo Compiling for darwin/386...' >> $BUILD && \
|
||||||
echo 'CC=o32-clang GOOS=darwin GOARCH=386 CGO_ENABLED=1 go get' >> $BUILD && \
|
echo 'CC=o32-clang GOOS=darwin GOARCH=386 CGO_ENABLED=1 go get -d ./$PACK' >> $BUILD && \
|
||||||
echo 'CC=o32-clang GOOS=darwin GOARCH=386 CGO_ENABLED=1 go build $V -o $NAME-darwin-386' >> $BUILD && \
|
echo 'CC=o32-clang GOOS=darwin GOARCH=386 CGO_ENABLED=1 go build $V -o $NAME-darwin-386 ./$PACK' >> $BUILD && \
|
||||||
echo >> $BUILD && \
|
echo >> $BUILD && \
|
||||||
echo 'echo Moving binaries to host...' >> $BUILD && \
|
echo 'echo Moving binaries to host...' >> $BUILD && \
|
||||||
echo 'cp `ls -t | head -n 7` /build' >> $BUILD && \
|
echo 'cp `ls -t | head -n 7` /build' >> $BUILD && \
|
||||||
|
12
xgo.go
12
xgo.go
@ -21,7 +21,9 @@ var dockerDist = "karalabe/xgo-"
|
|||||||
|
|
||||||
// Command line arguments to fine tune the compilation
|
// Command line arguments to fine tune the compilation
|
||||||
var goVersion = flag.String("go", "latest", "Go release to use for cross compilation")
|
var goVersion = flag.String("go", "latest", "Go release to use for cross compilation")
|
||||||
|
var inPackage = flag.String("in", "", "Sub-package to build if not root import")
|
||||||
var outPrefix = flag.String("out", "", "Prefix to use for output naming (empty = package name)")
|
var outPrefix = flag.String("out", "", "Prefix to use for output naming (empty = package name)")
|
||||||
|
var srcBranch = flag.String("branch", "", "Version control branch to build")
|
||||||
|
|
||||||
// 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")
|
||||||
@ -52,7 +54,7 @@ func main() {
|
|||||||
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], *outPrefix, *buildVerbose, *buildRace); err != nil {
|
if err := compile(flag.Args()[0], *srcBranch, *inPackage, *outPrefix, *buildVerbose, *buildRace); err != nil {
|
||||||
log.Fatalf("Failed to cross compile package: %v.", err)
|
log.Fatalf("Failed to cross compile package: %v.", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,18 +86,20 @@ 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(path string, prefix string, verbose bool, race bool) error {
|
func compile(repo string, branch string, pack string, prefix string, verbose bool, race bool) 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)
|
||||||
}
|
}
|
||||||
fmt.Printf("Cross compiling %s...\n", path)
|
fmt.Printf("Cross compiling %s...\n", repo)
|
||||||
return run(exec.Command("docker", "run",
|
return run(exec.Command("docker", "run",
|
||||||
"-v", folder+":/build",
|
"-v", folder+":/build",
|
||||||
|
"-e", "BRANCH="+branch,
|
||||||
|
"-e", "PACK="+pack,
|
||||||
"-e", "OUT="+prefix,
|
"-e", "OUT="+prefix,
|
||||||
"-e", fmt.Sprintf("FLAG_V=%v", verbose),
|
"-e", fmt.Sprintf("FLAG_V=%v", verbose),
|
||||||
"-e", fmt.Sprintf("FLAG_RACE=%v", race),
|
"-e", fmt.Sprintf("FLAG_RACE=%v", race),
|
||||||
dockerDist+*goVersion, path))
|
dockerDist+*goVersion, repo))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Executes a command synchronously, redirecting its output to stdout.
|
// Executes a command synchronously, redirecting its output to stdout.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user