Example #1
0
// install the given version into the environment creating a Symlink to it
func (e *Environment) Install(ver string) error {
	if !cache.AlreadyCompiled(ver) {
		if err := cache.Compile(ver, false, false); err != nil {
			fmt.Println("while installing:", err)
			return err
		}
	}

	path := filepath.Join(cache.CacheDirectory(), ver)
	if _, err := os.Stat(path); err != nil {
		path = filepath.Join(cache.CacheDirectory(), fmt.Sprintf("go%s", ver))
	}

	link := func() error {
		return os.Symlink(path, filepath.Join(e.VenGO_PATH, "lib"))
	}

	if err := link(); err != nil {
		if os.IsExist(err) {
			os.Remove(filepath.Join(e.VenGO_PATH, "lib"))
			if err := link(); err != nil {
				fmt.Println("while creating symlink:", err)
				return err
			}
		} else {
			fmt.Println("while creating symlink:", err)
			return err
		}
	}

	return nil
}
Example #2
0
// Generate an environment using it's manifest
func (em *envManifest) GenerateEnvironment(v bool, prompt string) error {
	// install go version if it's not installed yet
	if !LookupInstalledVersion(em.GoVersion) {
		if err := cache.CacheDownloadGit(em.GoVersion); err != nil {
			return err
		}
		if err := cache.Compile(em.GoVersion, v, false); err != nil {
			return err
		}
	}
	if prompt == "" {
		prompt = fmt.Sprintf("[%s]", em.Name)
	}
	impEnv := NewEnvironment(em.Name, prompt)
	if err := impEnv.Generate(); err != nil {
		os.RemoveAll(filepath.Join(os.Getenv("VENGO_HOME"), em.Name))
		return err
	}
	if err := impEnv.Install(em.GoVersion); err != nil {
		os.RemoveAll(filepath.Join(os.Getenv("VENGO_HOME"), em.Name))
		return err
	}
	impEnv.activate()
	defer impEnv.deactivate()
	if err := em.installPackages(v); err != nil {
		os.RemoveAll(filepath.Join(os.Getenv("VENGO_HOME"), em.Name))
		return err
	}
	return nil
}
Example #3
0
// install from tar.gz source
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, i.BootStrap); err != nil {
		return "error while installing from tar.gz source", err
	}

	result := fmt.Sprintf(
		"%s", utils.Ok(fmt.Sprintf("Go %s installed", i.Version)))
	return result, nil
}
Example #4
0
						binary := cache.GetBinaryVersion("1.2.1")
						_, err := os.Stat(
							filepath.Join(cache.CacheDirectory(), binary))
						Expect(err).NotTo(HaveOccurred())
						os.RemoveAll(
							filepath.Join(cache.CacheDirectory(), binary))
						debug.FreeOSMemory()
					})
				})
			})

			Describe("Compile works as expected", func() {
				Context("Giving a non existent version", func() {
					It("Shuld return an error", func() {
						err := cache.Compile("1.0", false, false)
						Expect(err).To(HaveOccurred())
						Expect(os.IsNotExist(err)).To(BeTrue())
					})
				})

				Context("Giving an existent version", func() {
					It("Shoudl recompile it", func() {
						err := cache.CacheDownloadGit("1.3.3")

						Expect(err).ToNot(HaveOccurred())
						Expect(cache.Compile("1.3.3", false, false)).To(Succeed())
					})
				})
			})
		}