Support setting repository remotes too.

This commit is contained in:
Péter Szilágyi 2015-05-05 14:57:11 +03:00
parent 38765bed91
commit 84f5af0336
2 changed files with 18 additions and 6 deletions

View File

@ -118,11 +118,21 @@ RUN \
echo 'cd $GOPATH/src/$1' >> $BUILD && \
echo 'export GOPATH=$GOPATH:`pwd`/Godeps/_workspace' >> $BUILD && \
echo >> $BUILD && \
echo 'if [ "$BRANCH" != "" ]; then' >> $BUILD && \
echo 'if [ "$REPO_REMOTE" != "" ]; then' >> $BUILD && \
echo ' if [ -d ".git" ]; then' >> $BUILD && \
echo ' git checkout $BRANCH' >> $BUILD && \
echo ' git remote set-url origin $REPO_REMOTE' >> $BUILD && \
echo ' git pull' >> $BUILD && \
echo ' elif [ -d ".hg" ]; then' >> $BUILD && \
echo ' hg checkout $BRANCH' >> $BUILD && \
echo ' echo -e "[paths]\ndefault = $REPO_REMOTE\n" >> .hg/hgrc' >> $BUILD && \
echo ' hg pull' >> $BUILD && \
echo ' fi' >> $BUILD && \
echo 'fi' >> $BUILD && \
echo >> $BUILD && \
echo 'if [ "$REPO_BRANCH" != "" ]; then' >> $BUILD && \
echo ' if [ -d ".git" ]; then' >> $BUILD && \
echo ' git checkout $REPO_BRANCH' >> $BUILD && \
echo ' elif [ -d ".hg" ]; then' >> $BUILD && \
echo ' hg checkout $REPO_BRANCH' >> $BUILD && \
echo ' fi' >> $BUILD && \
echo 'fi' >> $BUILD && \
echo >> $BUILD && \

8
xgo.go
View File

@ -23,6 +23,7 @@ var dockerDist = "karalabe/xgo-"
var goVersion = flag.String("go", "latest", "Go release to use for cross compilation")
var inPackage = flag.String("pkg", "", "Sub-package to build if not root import")
var outPrefix = flag.String("out", "", "Prefix to use for output naming (empty = package name)")
var srcRemote = flag.String("remote", "", "Version control remote repository to build")
var srcBranch = flag.String("branch", "", "Version control branch to build")
var crossDeps = flag.String("deps", "", "CGO dependencies (configure/make based archives)")
@ -55,7 +56,7 @@ func main() {
fmt.Println("found.")
}
// Cross compile the requested package into the local folder
if err := compile(flag.Args()[0], *srcBranch, *inPackage, *crossDeps, *outPrefix, *buildVerbose, *buildRace); err != nil {
if err := compile(flag.Args()[0], *srcRemote, *srcBranch, *inPackage, *crossDeps, *outPrefix, *buildVerbose, *buildRace); err != nil {
log.Fatalf("Failed to cross compile package: %v.", err)
}
}
@ -87,7 +88,7 @@ func pullDockerImage(image string) error {
}
// Cross compiles a requested package into the current working directory.
func compile(repo string, branch string, pack string, deps string, prefix string, verbose bool, race bool) error {
func compile(repo string, remote string, branch string, pack string, deps string, prefix string, verbose bool, race bool) error {
folder, err := os.Getwd()
if err != nil {
log.Fatalf("Failed to retrieve the working directory: %v.", err)
@ -95,7 +96,8 @@ func compile(repo string, branch string, pack string, deps string, prefix string
fmt.Printf("Cross compiling %s...\n", repo)
return run(exec.Command("docker", "run",
"-v", folder+":/build",
"-e", "BRANCH="+branch,
"-e", "REPO_REMOTE="+remote,
"-e", "REPO_BRANCH="+branch,
"-e", "PACK="+pack,
"-e", "DEPS="+deps,
"-e", "OUT="+prefix,