Beispiel #1
0
func install(root string, recursive bool, exclude []string) {
	cartridge, err := set.LoadFrom(root)
	if err != nil {
		fatal(err)
	}

	runner := command_runner.New(false)

	fetcher, err := fetcher.New(runner)
	if err != nil {
		fatal(err)
	}

	err = installDependencies(fetcher, cartridge, recursive, exclude, 0)
	if err != nil {
		fatal(err)
	}

	err = cartridge.SaveTo(root)
	if err != nil {
		fatal(err)
	}

	fmt.Println(green("OK"))
}
Beispiel #2
0
func checkDependencies(deps *set.Set, depth int) bool {
	dirty := false

	for _, dep := range deps.Dependencies {
		err := checkForDirtyState(dep)
		if err != nil {
			dirty = true

			fmt.Println(indent(depth, bold(dep.Path)))
			fmt.Println(indent(depth+1, err.Error()))
		} else {
			fmt.Println(indent(depth, bold(dep.Path)), green("OK"))
		}

		nextDeps, err := set.LoadFrom(dep.FullPath(GOPATH))
		if err == set.NoCartridgeError {
			continue
		} else if err != nil {
			fatal(err)
		}

		if checkDependencies(nextDeps, depth+1) {
			dirty = true
		}
	}

	return dirty
}
Beispiel #3
0
func installDependencies(fetcher *fetcher.Fetcher, deps *set.Set, recursive bool, exclude []string, depth int) error {
	maxWidth := 0

	for _, dep := range deps.Dependencies {
		if len(dep.Path) > maxWidth {
			maxWidth = len(dep.Path)
		}
	}

	for _, dep := range deps.Dependencies {
		if tagsMatch(dep.Tags, exclude) {
			continue
		}

		versionDisplay := ""

		if dep.BleedingEdge {
			versionDisplay = "*"
		} else {
			versionDisplay = dep.Version
		}

		fmt.Println(
			indent(
				depth,
				bold(dep.Path)+padding(maxWidth-len(dep.Path)+2)+cyan(versionDisplay),
			),
		)

		lockedDependency, err := fetcher.Fetch(dep)
		if err != nil {
			return err
		}

		deps.Replace(lockedDependency)

		if recursive {
			nextDeps, err := set.LoadFrom(lockedDependency.FullPath(GOPATH))
			if err == set.NoCartridgeError {
				continue
			} else if err != nil {
				return err
			}

			err = installDependencies(fetcher, nextDeps, true, []string{"test"}, depth+1)
			if err != nil {
				return err
			}
		}
	}

	return nil
}
Beispiel #4
0
func check(root string) {
	cartridge, err := set.LoadFrom(root)
	if err != nil {
		fatal(err)
	}

	dirty := checkDependencies(cartridge, 0)

	if dirty {
		os.Exit(1)
	}
}
Beispiel #5
0
		It("checks out hg repos to the given ref", func() {
			installCmd.Dir = fakeHgRepoWithRevisionPath

			dependencyPath := path.Join(gopath, "src", "code.google.com", "p", "go.crypto", "ssh")

			install()

			Expect(hgRevision(dependencyPath)).To(Say("1e7a3e301825"))
		})

		It("generates a Cartridge.lock file", func() {
			installCmd.Dir = fakeDiverseRepoPath

			install()

			set, err := set.LoadFrom(installCmd.Dir)
			Expect(err).ToNot(HaveOccurred())

			dependency0Version := currentGitRevision(path.Join(gopath, "src", "github.com", "vito", "gocart"))
			dependency1Version := currentHgRevision(path.Join(gopath, "src", "code.google.com", "p", "go.crypto", "ssh"))

			Expect(set.Dependencies).To(HaveLen(2))
			Expect(set.Dependencies).To(Equal([]dependency.Dependency{
				{
					Path:    "github.com/vito/gocart",
					Version: dependency0Version,
				},
				{
					Path:    "code.google.com/p/go.crypto/ssh",
					Version: dependency1Version,
				},