示例#1
0
文件: source.go 项目: jmartiuk5/VenGO
// compile a given version of go in the cache
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"))
	if err != nil {
		if !strings.HasPrefix(ver, "go") && ver != "tip" {
			ver = fmt.Sprintf("go%s", ver)
		}
		prefixed = true
		if err := os.Chdir(
			filepath.Join(CacheDirectory(), ver, "src")); err != nil {
			if !verbose {
				fmt.Fprintln(Output, utils.Fail("✖"))
			}
			return err
		}
	}
	defer func() { os.Chdir(currdir) }()

	cmd := "./make.bash"
	if runtime.GOOS == "windows" {
		cmd = "./make.bat"
	}
	if nocgo {
		os.Setenv("CGO_ENABLED", "0")
	}
	if bs != "" {
		os.Setenv("GOROOT_BOOTSTRAP", bs)
	}
	if err := utils.Exec(verbose, cmd); err != nil {
		return err
	}
	goBin := filepath.Join(CacheDirectory(), ver, "go", "bin", "go")
	if prefixed {
		goBin = filepath.Join(CacheDirectory(), ver, "bin", "go")
	}
	if _, err := os.Stat(goBin); err != nil {
		if !verbose {
			fmt.Fprintln(Output, utils.Fail("✖"))
		}
		fmt.Fprintln(Output, err)
		return fmt.Errorf("Go %s wasn't compiled properly! %v", ver, err)
	}
	if !verbose {
		fmt.Fprintln(Output, utils.Ok("✔"))
	}
	fmt.Fprintf(Output, "Generating manifest... ")
	if err := generateManifest(ver); err != nil {
		os.RemoveAll(filepath.Join(CacheDirectory(), ver))
		fmt.Fprintln(Output, utils.Fail("✖"))
		return err
	}
	fmt.Fprintln(Output, utils.Ok("✔"))

	return nil
}
示例#2
0
文件: vcs.go 项目: jmartiuk5/VenGO
// vcs type structure
type vcsType struct {
	name      string
	refCmd    string
	updateCmd string
	cloneCmd  func(string, string, bool) error
	schemeCmd func(string, bool) (string, error)
}

// Git
var gitVcs = &vcsType{
	name:      "git",
	refCmd:    "git rev-parse --verify HEAD",
	updateCmd: "git checkout {tag}",
	cloneCmd: func(repo, tag string, verbose bool) error {
		if err := utils.Exec(verbose, "git", "clone", repo); err != nil {
			return err
		}
		curr, err := os.Getwd()
		if err != nil {
			return err
		}
		os.Chdir(path.Base(repo))
		err = utils.Exec(verbose, "git", "checkout", tag)
		os.Chdir(curr)
		return err
	},
	schemeCmd: func(repo string, verbose bool) (string, error) {
		for _, scheme := range []string{"git", "https", "http", "git+ssh"} {
			tmp := fmt.Sprintf("%s://%s", scheme, repo)
			if err := utils.Exec(verbose, "git", "ls-remote", tmp); err == nil {