Skip to content

Commit

Permalink
added bootstrap option to compile go1.5 or superior
Browse files Browse the repository at this point in the history
  • Loading branch information
DamnWidget committed Feb 24, 2015
1 parent 313d8a8 commit 3bd8baa
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 1 @@
1.1.0
1.1.1
14 changes: 9 additions & 5 deletions cache/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
11 changes: 10 additions & 1 deletion cache/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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
}
Expand Down
19 changes: 13 additions & 6 deletions commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
`,
Expand All @@ -57,6 60,7 @@ var (
sourceInstall bool
verboseInstall bool
nocgoInstall bool
bootStrap string
)

// possible installation sources
Expand All @@ -74,6 78,7 @@ type Install struct {
DisplayAs int
Verbose bool
NoCGO bool
BootStrap string
}

// initialize the command
Expand All @@ -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()
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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(
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 20,4 @@

package main

var vengo_version = "v1.1.0"
var vengo_version = "v1.1.1"

0 comments on commit 3bd8baa

Please sign in to comment.