예제 #1
0
파일: env.go 프로젝트: jmartiuk5/VenGO
// 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
}
예제 #2
0
					debug.FreeOSMemory()
					os.RemoveAll(filepath.Join(cache.CacheDirectory(), "go1"))
				})
			})
		})

		Describe("AlreadyCompiled", func() {
			It("Shoudl return true if the source has been compiled", func() {
				os.MkdirAll(filepath.Join(cache.CacheDirectory(), "test1", "go", "bin"), 0755)
				filename := filepath.Join(cache.CacheDirectory(), "test1", "go", "bin", "go")

				Expect(ioutil.WriteFile(filename, []byte{}, 0644)).To(Succeed())
				filename = filepath.Join(cache.CacheDirectory(), "test1", ".vengo-manifest")

				Expect(ioutil.WriteFile(filename, []byte{}, 0644)).To(Succeed())
				Expect(cache.AlreadyCompiled("test1")).To(BeTrue())
				os.RemoveAll(filepath.Join(cache.CacheDirectory(), "test1"))

				Expect(cache.AlreadyCompiled("test1")).To(BeFalse())
			})
		})

		if RunSlowTests {
			Describe("CacheDownload works as expected", func() {
				Context("Passing a non valid Go version", func() {
					It("Should fail and give back a descriptive error", func() {
						err := cache.CacheDownload("1.0")
						Expect(err).To(HaveOccurred())
						Expect(err).To(Equal(fmt.Errorf(
							"1.0 is not a VenGO supported version you must donwload and compile it yourself"),
						))