Ejemplo n.º 1
0
func restore(ctx *gb.Context) error {
	m, err := vendor.ReadManifest(manifestFile(ctx))
	if err != nil {
		return fmt.Errorf("could not load manifest: %v", err)
	}

	for _, dep := range m.Dependencies {
		fmt.Printf("Getting %s\n", dep.Importpath)
		repo, _, err := vendor.DeduceRemoteRepo(dep.Importpath, insecure)
		if err != nil {
			return fmt.Errorf("Could not process dependency: %s", err)
		}
		wc, err := repo.Checkout("", "", dep.Revision)
		if err != nil {
			return fmt.Errorf("Could not retrieve dependency: %s", err)
		}
		dst := filepath.Join(ctx.Projectdir(), "vendor", "src", dep.Importpath)
		src := filepath.Join(wc.Dir(), dep.Path)

		if err := vendor.Copypath(dst, src); err != nil {
			return err
		}

		if err := wc.Destroy(); err != nil {
			return err
		}

	}
	return nil
}
Ejemplo n.º 2
0
Archivo: depset.go Proyecto: URXtech/gb
func depset(ctx *gb.Context, args []string) error {
	paths := []struct {
		Root, Prefix string
	}{
		{filepath.Join(runtime.GOROOT(), "src"), ""},
		{filepath.Join(ctx.Projectdir(), "src"), ""},
	}
	m, err := vendor.ReadManifest(filepath.Join("vendor", "manifest"))
	if err != nil {
		return err
	}
	for _, d := range m.Dependencies {
		paths = append(paths, struct{ Root, Prefix string }{filepath.Join(ctx.Projectdir(), "vendor", "src", filepath.FromSlash(d.Importpath)), filepath.FromSlash(d.Importpath)})
	}

	dsm, err := vendor.LoadPaths(paths...)
	if err != nil {
		return err
	}
	for _, set := range dsm {
		fmt.Printf("%s (%s)\n", set.Root, set.Prefix)
		for _, p := range set.Pkgs {
			fmt.Printf("\t%s (%s)\n", p.ImportPath, p.Name)
			fmt.Printf("\t\timports: %s\n", p.Imports)
		}
	}

	root := paths[1] // $PROJECT/src
	rs := dsm[root.Root].Pkgs

	fmt.Println("missing:")
	for missing := range findMissing(pkgs(rs), dsm) {
		fmt.Printf("\t%s\n", missing)
	}

	fmt.Println("orphaned:")
	for orphan := range findOrphaned(pkgs(rs), dsm) {
		fmt.Printf("\t%s\n", orphan)
	}

	return nil
}
Ejemplo n.º 3
0
Archivo: list.go Proyecto: URXtech/gb
var cmdList = &cmd.Command{
	Name:      "list",
	UsageLine: "list [-f format]",
	Short:     "lists dependencies, one per line",
	Long: `gb vendor list formats lists the contents of the manifest file.

The output

Flags:
	-f
		controls the template used for printing each manifest entry. If not supplied
		the default value is "{{.Importpath}}\t{{.Repository}}{{.Path}}\t{{.Branch}}\t{{.Revision}}"

`,
	Run: func(ctx *gb.Context, args []string) error {
		m, err := vendor.ReadManifest(manifestFile(ctx))
		if err != nil {
			return fmt.Errorf("could not load manifest: %v", err)
		}
		tmpl, err := template.New("list").Parse(format)
		if err != nil {
			return fmt.Errorf("unable to parse template %q: %v", format, err)
		}
		w := tabwriter.NewWriter(os.Stdout, 1, 2, 1, ' ', 0)
		for _, dep := range m.Dependencies {
			if err := tmpl.Execute(w, dep); err != nil {
				return fmt.Errorf("unable to execute template: %v", err)
			}
			fmt.Fprintln(w)
		}
		return w.Flush()
Ejemplo n.º 4
0
Archivo: fetch.go Proyecto: URXtech/gb
func fetch(ctx *gb.Context, path string, recurse bool) error {
	m, err := vendor.ReadManifest(manifestFile(ctx))
	if err != nil {
		return fmt.Errorf("could not load manifest: %v", err)
	}

	repo, extra, err := vendor.DeduceRemoteRepo(path, insecure)
	if err != nil {
		return err
	}

	// strip of any scheme portion from the path, it is already
	// encoded in the repo.
	path = stripscheme(path)

	if m.HasImportpath(path) {
		return fmt.Errorf("%s is already vendored", path)
	}

	var wc vendor.WorkingCopy

	// if we are not recursing, then always fetch the HEAD of the master
	if recurse {
		wc, err = repo.Checkout(branch, tag, revision)
	} else {
		wc, err = repo.Checkout("", "", "")
	}

	if err != nil {
		return err
	}

	rev, err := wc.Revision()
	if err != nil {
		return err
	}

	branch, err := wc.Branch()
	if err != nil {
		return err
	}

	dep := vendor.Dependency{
		Importpath: path,
		Repository: repo.URL(),
		Revision:   rev,
		Branch:     branch,
		Path:       extra,
	}

	if err := m.AddDependency(dep); err != nil {
		return err
	}

	dst := filepath.Join(ctx.Projectdir(), "vendor", "src", dep.Importpath)
	src := filepath.Join(wc.Dir(), dep.Path)

	if err := vendor.Copypath(dst, src); err != nil {
		return err
	}

	if err := vendor.WriteManifest(manifestFile(ctx), m); err != nil {
		return err
	}

	if err := wc.Destroy(); err != nil {
		return err
	}

	if !recurse {
		return nil
	}

	for done := false; !done; {

		paths := []struct {
			Root, Prefix string
		}{
			{filepath.Join(runtime.GOROOT(), "src"), ""},
			{filepath.Join(ctx.Projectdir(), "src"), ""},
		}
		m, err := vendor.ReadManifest(manifestFile(ctx))
		if err != nil {
			return err
		}
		for _, d := range m.Dependencies {
			paths = append(paths, struct{ Root, Prefix string }{filepath.Join(ctx.Projectdir(), "vendor", "src", filepath.FromSlash(d.Importpath)), filepath.FromSlash(d.Importpath)})
		}

		dsm, err := vendor.LoadPaths(paths...)
		if err != nil {
			return err
		}

		is, ok := dsm[filepath.Join(ctx.Projectdir(), "vendor", "src", path)]
		if !ok {
			return fmt.Errorf("unable to locate depset for %q", path)
		}

		missing := findMissing(pkgs(is.Pkgs), dsm)
		switch len(missing) {
		case 0:
			done = true
		default:

			// sort keys in ascending order, so the shortest missing import path
			// with be fetched first.
			keys := keys(missing)
			sort.Strings(keys)
			pkg := keys[0]
			gb.Infof("fetching recursive dependency %s", pkg)
			if err := fetch(ctx, pkg, false); err != nil {
				return err
			}
		}
	}

	return nil
}