From 3bd8baa7e926d97f623d0ac8b87fd3f8fc1632bf Mon Sep 17 00:00:00 2001 From: Oscar Campos Date: Tue, 24 Feb 2015 18:20:06 +0000 Subject: [PATCH] added bootstrap option to compile go1.5 or superior --- VERSION | 2 +- cache/git.go | 14 +++++++++----- cache/source.go | 11 ++++++++++- commands/install.go | 19 +++++++++++++------ version.go | 2 +- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/VERSION b/VERSION index 9084fa2..524cb55 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.0 +1.1.1 diff --git a/cache/git.go b/cache/git.go index 002946f..2088dab 100644 --- a/cache/git.go +++ b/cache/git.go @@ -122,6 +122,7 @@ func cloneSource() error { } func copySource(ver string) error { + var out []byte fmt.Fprint(Output, "Copying source... ") destination := filepath.Join(CacheDirectory(), ver) os.RemoveAll(destination) @@ -134,10 +135,13 @@ func copySource(ver string) error { os.Chdir(curr) }() os.Chdir(TARGET) - out, err := exec.Command("git", "checkout", ver).CombinedOutput() - if err != nil { - fmt.Fprintln(Output, utils.Fail("✖")) - return err + if ver != "go" && ver != "tip" { + out, err := exec.Command("git", "checkout", ver).CombinedOutput() + log.Println(string(out), err) + if err != nil { + fmt.Fprintln(Output, utils.Fail("✖")) + return fmt.Errorf("%s", out) + } } out, err = exec.Command("cp", "-R", "../git", destination).CombinedOutput() if err != nil { @@ -168,7 +172,7 @@ func pull() error { } func lookupVersion(ver string, availableVersions []string) (index int) { - if ver == "go" { + if ver == "go" || ver == "tip" { return 0xBEDEAD } diff --git a/cache/source.go b/cache/source.go index 371a93b..8cd6084 100644 --- a/cache/source.go +++ b/cache/source.go @@ -51,11 +51,17 @@ func AlreadyCompiled(ver string) bool { } // compile a given version of go in the cache -func Compile(ver string, verbose, nocgo bool) error { +func Compile(ver string, verbose, nocgo bool, boostrap ...string) error { fmt.Fprint(Output, "Compiling... ") if verbose { fmt.Fprint(Output, "\n") } + + bs := "" + if len(boostrap) > 0 { + bs = boostrap[0] + } + currdir, _ := os.Getwd() prefixed := false err := os.Chdir(filepath.Join(CacheDirectory(), ver, "go", "src")) @@ -81,6 +87,9 @@ func Compile(ver string, verbose, nocgo bool) error { if nocgo { os.Setenv("CGO_ENABLED", "0") } + if bs != "" { + os.Setenv("GOROOT_BOOTSTRAP", bs) + } if err := utils.Exec(verbose, cmd); err != nil { return err } diff --git a/commands/install.go b/commands/install.go index f89b63c..5709ca4 100644 --- a/commands/install.go +++ b/commands/install.go @@ -31,7 +31,7 @@ import ( var cmdInstall = &Command{ Name: "install", - Usage: "install [-s] [-b] [-v] [-f] [-n] version", + Usage: "install [-s] [-b] [-v] [-f] [-n] [-x] version", Short: "Installs a new Go version", Long: `Install a new version of Go, it can be installed directly from the official mercurial or git repositories, from a tarball packaed source or directly in @@ -45,6 +45,9 @@ If the given version is already installed, we can force it's reinstallation using the -f or --force flags, to compile the newly downloaded Go version with CGO_ENABLED=0 the -n or --ncgo flag should be passed. +The -x or -bootstrap flag is used to compile go 1.5 and superior, you should +pass the path of a valid go 1.4 instalation as value for this parameter. + Use the -v or --verbose flags to run the command with verbose output, this is useful to debug in case of errors during the compilation phase. `, @@ -57,6 +60,7 @@ var ( sourceInstall bool verboseInstall bool nocgoInstall bool + bootStrap string ) // possible installation sources @@ -74,6 +78,7 @@ type Install struct { DisplayAs int Verbose bool NoCGO bool + BootStrap string } // initialize the command @@ -83,6 +88,7 @@ func init() { cmdInstall.Flag.BoolVarP(&sourceInstall, "source", "s", false, "Download tarball") cmdInstall.Flag.BoolVarP(&verboseInstall, "verbose", "v", false, "verbose output") cmdInstall.Flag.BoolVarP(&nocgoInstall, "ncgo", "n", false, "CGO_ENABLE=0") + cmdInstall.Flag.StringVarP(&bootStrap, "bootstrap", "x", "", "booostrap cmd ") cmdInstall.register() } @@ -95,6 +101,7 @@ func runInstall(cmd *Command, args ...string) { i.Verbose = verboseInstall i.Force = forceInstall i.NoCGO = nocgoInstall + i.BootStrap = bootStrap if binaryInstall { i.Source = Binary } else { @@ -142,13 +149,13 @@ func (i *Install) Run() (string, error) { } } -// install from mercurial source +// install from github source func (i *Install) fromGit() (string, error) { if err := cache.CacheDownloadGit(i.Version, i.Force); err != nil { - return "error while installing from mercurial", err + return "error while installing from github", err } - if err := cache.Compile(i.Version, i.Verbose, i.NoCGO); err != nil { - return "error while compiling from mercurial", err + if err := cache.Compile(i.Version, i.Verbose, i.NoCGO, i.BootStrap); err != nil { + return "error while compiling from github", err } result := fmt.Sprintf( @@ -161,7 +168,7 @@ func (i *Install) fromSource() (string, error) { if err := cache.CacheDownload(i.Version, i.Force); err != nil { return "error while installing from tar.gz source", err } - if err := cache.Compile(i.Version, i.Verbose, i.NoCGO); err != nil { + if err := cache.Compile(i.Version, i.Verbose, i.NoCGO, i.BootStrap); err != nil { return "error while installing from tar.gz source", err } diff --git a/version.go b/version.go index 535b78c..52eea2f 100644 --- a/version.go +++ b/version.go @@ -20,4 +20,4 @@ package main -var vengo_version = "v1.1.0" +var vengo_version = "v1.1.1"