예제 #1
0
파일: dep.go 프로젝트: uhoh-itsmaciek/godep
func LoadGodeps(a []*Package) (*Godeps, error) {
	var err error
	g := new(Godeps)
	g.ImportPath = a[0].ImportPath
	g.GoVersion, err = goVersion()
	if err != nil {
		return nil, err
	}
	deps := a[0].Deps
	for _, p := range a[1:] {
		deps = append(deps, p.ImportPath)
		deps = append(deps, p.Deps...)
	}
	sort.Strings(deps)
	pkgs, err := LoadPackages(deps)
	if err != nil {
		log.Fatalln(err)
	}
	seen := []string{a[0].ImportPath}
	var err1 error
	for _, pkg := range pkgs {
		name := pkg.ImportPath
		if pkg.Error.Err != "" {
			log.Println(pkg.Error.Err)
			err = errors.New("error loading dependencies")
			continue
		}
		if !pathPrefixIn(seen, name) && !pkg.Standard {
			vcs, _, err := VCSForImportPath(pkg.ImportPath)
			if err != nil {
				log.Println(err)
				err1 = errors.New("error loading dependencies")
				continue
			}
			seen = append(seen, name+"/")
			var id string
			id, err = vcs.identify(pkg.Dir)
			if err != nil {
				log.Println(err)
				err1 = errors.New("error loading dependencies")
				continue
			}
			if vcs.isDirty(pkg.Dir) {
				log.Println("dirty working tree:", pkg.Dir)
				err1 = errors.New("error loading dependencies")
				continue
			}
			comment := vcs.describe(pkg.Dir, id)
			g.Deps = append(g.Deps, Dependency{
				ImportPath: name,
				Rev:        id,
				Comment:    comment,
			})
		}
	}
	if err1 != nil {
		return nil, err1
	}
	return g, nil
}
예제 #2
0
파일: dep.go 프로젝트: samuelyao314/mygo
// pkgs is the list of packages to read dependencies
func (g *Godeps) Load(pkgs []*Package) error {
	var err1 error
	var path, seen []string
	for _, p := range pkgs {
		if p.Standard {
			log.Println("ignoring stdlib package:", p.ImportPath)
			continue
		}
		if p.Error.Err != "" {
			log.Println(p.Error.Err)
			err1 = errors.New("error loading packages")
			continue
		}
		_, reporoot, err := VCSFromDir(p.Dir, filepath.Join(p.Root, "src"))
		if err != nil {
			log.Println(err)
			err1 = errors.New("error loading packages")
			continue
		}
		seen = append(seen, filepath.ToSlash(reporoot))
		path = append(path, p.Deps...)
	}
	var testImports []string
	for _, p := range pkgs {
		testImports = append(testImports, p.TestImports...)
		testImports = append(testImports, p.XTestImports...)
	}
	ps, err := LoadPackages(testImports...)
	if err != nil {
		return err
	}
	for _, p := range ps {
		if p.Standard {
			continue
		}
		if p.Error.Err != "" {
			log.Println(p.Error.Err)
			err1 = errors.New("error loading packages")
			continue
		}
		path = append(path, p.ImportPath)
		path = append(path, p.Deps...)
	}
	for i, p := range path {
		path[i] = unqualify(p)
	}
	sort.Strings(path)
	path = uniq(path)
	ps, err = LoadPackages(path...)
	if err != nil {
		return err
	}
	for _, pkg := range ps {
		if pkg.Error.Err != "" {
			log.Println(pkg.Error.Err)
			err1 = errors.New("error loading dependencies")
			continue
		}
		if pkg.Standard {
			continue
		}
		vcs, reporoot, err := VCSFromDir(pkg.Dir, filepath.Join(pkg.Root, "src"))
		if err != nil {
			log.Println(err)
			err1 = errors.New("error loading dependencies")
			continue
		}
		if containsPathPrefix(seen, pkg.ImportPath) {
			continue
		}
		seen = append(seen, pkg.ImportPath)
		id, err := vcs.identify(pkg.Dir)
		if err != nil {
			log.Println(err)
			err1 = errors.New("error loading dependencies")
			continue
		}
		if vcs.isDirty(pkg.Dir, id) {
			log.Println("dirty working tree:", pkg.Dir)
			err1 = errors.New("error loading dependencies")
			continue
		}
		comment := vcs.describe(pkg.Dir, id)
		g.Deps = append(g.Deps, Dependency{
			ImportPath: pkg.ImportPath,
			Rev:        id,
			Comment:    comment,
			dir:        pkg.Dir,
			ws:         pkg.Root,
			root:       filepath.ToSlash(reporoot),
			vcs:        vcs,
		})
	}
	return err1
}
예제 #3
0
파일: dep.go 프로젝트: kevin-cantwell/godep
// pkgs is the list of packages to read dependencies
func (g *Godeps) Load(pkgs []*Package) error {
	var err1 error
	var path, seen []string
	for _, p := range pkgs {
		if p.Standard {
			log.Println("ignoring stdlib package:", p.ImportPath)
			continue
		}
		if p.Error.Err != "" {
			log.Println(p.Error.Err)
			err1 = errors.New("error loading packages")
			continue
		}
		_, reporoot, err := VCSFromDir(p.Dir, filepath.Join(p.Root, "src"))
		if err != nil {
			log.Println(err)
			err1 = errors.New("error loading packages")
			continue
		}
		seen = append(seen, filepath.ToSlash(reporoot))
		path = append(path, p.Deps...)
	}
	var testImports []string
	for _, p := range pkgs {
		testImports = append(testImports, p.TestImports...)
		testImports = append(testImports, p.XTestImports...)
	}
	ps, err := LoadPackages(testImports...)
	if err != nil {
		return err
	}
	for _, p := range ps {
		if p.Standard {
			continue
		}
		if p.Error.Err != "" {
			log.Println(p.Error.Err)
			err1 = errors.New("error loading packages")
			continue
		}
		path = append(path, p.ImportPath)
		path = append(path, p.Deps...)
	}
	sort.Strings(path)
	path = uniq(path)

	// Packages using 'godep save -r' contain rewritten
	// import statements that fool go list into omitting
	// further dependencies. In that case, the Godeps
	// manifest has the full list.
	for _, s := range path {
		deps, err := readGodepsForImportPath(s)
		if err != nil {
			log.Println(err)
			err1 = errors.New("error loading packages")
			continue
		}
		for _, dep := range deps {
			path = append(path, dep.ImportPath)
		}
	}
	if err1 != nil {
		return err1
	}
	sort.Strings(path)
	path = uniq(path)
	ps, err = LoadPackages(path...)
	if err != nil {
		return err
	}
	for _, pkg := range ps {
		if pkg.Error.Err != "" {
			log.Println(pkg.Error.Err)
			err1 = errors.New("error loading dependencies")
			continue
		}
		if pkg.Standard {
			continue
		}
		vcs, reporoot, err := VCSFromDir(pkg.Dir, filepath.Join(pkg.Root, "src"))
		if err != nil {
			log.Println(err)
			err1 = errors.New("error loading dependencies")
			continue
		}
		if containsPathPrefix(seen, pkg.ImportPath) {
			continue
		}
		seen = append(seen, pkg.ImportPath)
		id, err := vcs.identify(pkg.Dir)
		if err != nil {
			log.Println(err)
			err1 = errors.New("error loading dependencies")
			continue
		}
		if vcs.isDirty(pkg.Dir, id) {
			log.Println("dirty working tree:", pkg.Dir)
			err1 = errors.New("error loading dependencies")
			continue
		}
		comment := vcs.describe(pkg.Dir, id)
		g.Deps = append(g.Deps, Dependency{
			ImportPath: pkg.ImportPath,
			Rev:        id,
			Comment:    comment,
			dir:        pkg.Dir,
			ws:         pkg.Root,
			root:       filepath.ToSlash(reporoot),
			vcs:        vcs,
		})
	}
	return err1
}
예제 #4
0
// pkgs is the list of packages to read dependencies
func (g *Godeps) Load(pkgs []*Package) error {
	var err1 error
	var path, seen []string
	for _, p := range pkgs {
		if p.Standard {
			log.Println("ignoring stdlib package:", p.ImportPath)
			continue
		}
		if p.Error.Err != "" {
			log.Println(p.Error.Err)
			err1 = errors.New("error loading packages")
			continue
		}
		_, reporoot, err := VCSFromDir(p.Dir, p.Root)
		if err != nil {
			log.Println(err)
			err1 = errors.New("error loading packages")
			continue
		}
		importPath := strings.TrimPrefix(reporoot, "src"+string(os.PathSeparator))
		seen = append(seen, importPath+"/")
		path = append(path, p.Deps...)
	}

	var testImports []string
	for _, p := range pkgs {
		testImports = append(testImports, p.TestImports...)
		testImports = append(testImports, p.XTestImports...)
	}

	for _, p := range MustLoadPackages(testImports...) {
		if p.Standard {
			continue
		}
		if p.Error.Err != "" {
			log.Println(p.Error.Err)
			err1 = errors.New("error loading packages")
			continue
		}
		path = append(path, p.ImportPath)
		path = append(path, p.Deps...)
	}

	sort.Strings(path)
	path = uniq(path)
	for _, pkg := range MustLoadPackages(path...) {
		if pkg.Error.Err != "" {
			log.Println(pkg.Error.Err)
			err1 = errors.New("error loading dependencies")
			continue
		}
		if pkg.Standard {
			continue
		}
		vcs, _, err := VCSFromDir(pkg.Dir, pkg.Root)
		if err != nil {
			log.Println(err)
			err1 = errors.New("error loading dependencies")
			continue
		}
		if containsPrefix(seen, pkg.ImportPath) {
			continue
		}
		seen = append(seen, pkg.ImportPath+"/")
		id, err := vcs.identify(pkg.Dir)
		if err != nil {
			log.Println(err)
			err1 = errors.New("error loading dependencies")
			continue
		}
		if vcs.isDirty(pkg.Dir, id) {
			log.Println("dirty working tree:", pkg.Dir)
			err1 = errors.New("error loading dependencies")
			continue
		}
		comment := vcs.describe(pkg.Dir, id)
		g.Deps = append(g.Deps, Dependency{
			ImportPath: pkg.ImportPath,
			Rev:        id,
			Comment:    comment,
			dir:        pkg.Dir,
			ws:         pkg.Root,
			vcs:        vcs,
		})
	}
	return err1
}
예제 #5
0
파일: dep.go 프로젝트: pedantic-git/godep
// pkgs is the list of packages to read dependencies
func (g *Godeps) Load(pkgs []*Package, extonly bool) error {
	var err1 error
	var path, seen, home []string
	for _, p := range pkgs {
		if p.Standard {
			log.Println("ignoring stdlib package:", p.ImportPath)
			continue
		}
		if p.Error.Err != "" {
			log.Println(p.Error.Err)
			err1 = errors.New("error loading packages")
			continue
		}

		if extonly {
			// Keep track of all the "homes" of the specified
			// packages. The home is the Root if set, or the p.Dir if
			// the root cannot be determined (normally when saving
			// "main" for a golang project that doesn't follow the
			// directory naming conventions)
			if p.Root != "" {
				home = append(home, p.Root)
			} else {
				home = append(home, p.Dir)
			}
		} else {
			if p.Root == "" {
				log.Printf("Root dir cannot be determined for packages in %s.", p.Dir)
				log.Println("  If these are all under your control, you could try running with -extonly.")
				err1 = errors.New("error loading packages")
				continue
			}

			_, reporoot, err := VCSFromDir(p.Dir, p.Root)
			if err != nil {
				log.Println(err)
				err1 = errors.New("error loading packages")
				continue
			}
			importPath := strings.TrimPrefix(reporoot, "src"+string(os.PathSeparator))
			seen = append(seen, importPath+"/")
		}
		path = append(path, p.Deps...)
	}
	var testImports []string
	for _, p := range pkgs {
		testImports = append(testImports, p.TestImports...)
	}
	for _, p := range MustLoadPackages(testImports...) {
		if p.Standard {
			continue
		}
		if p.Error.Err != "" {
			log.Println(p.Error.Err)
			err1 = errors.New("error loading packages")
			continue
		}
		path = append(path, p.ImportPath)
		path = append(path, p.Deps...)
	}
	sort.Strings(path)
	path = uniq(path)
	for _, pkg := range MustLoadPackages(path...) {
		if pkg.Error.Err != "" {
			log.Println(pkg.Error.Err)
			err1 = errors.New("error loading dependencies")
			continue
		}
		if pkg.Standard {
			continue
		}
		// "home" contains the "homes" of the specified packages - in
		// extonly mode we want to skip those
		if extonly && containsPrefix(home, pkg.Dir) {
			continue
		}
		vcs, _, err := VCSFromDir(pkg.Dir, pkg.Root)
		if err != nil {
			log.Println(err)
			err1 = errors.New("error loading dependencies")
			continue
		}
		if containsPrefix(seen, pkg.ImportPath) {
			continue
		}
		seen = append(seen, pkg.ImportPath+"/")
		id, err := vcs.identify(pkg.Dir)
		if err != nil {
			log.Println(err)
			err1 = errors.New("error loading dependencies")
			continue
		}
		if vcs.isDirty(pkg.Dir, id) {
			log.Println("dirty working tree:", pkg.Dir)
			err1 = errors.New("error loading dependencies")
			continue
		}
		comment := vcs.describe(pkg.Dir, id)
		g.Deps = append(g.Deps, Dependency{
			ImportPath: pkg.ImportPath,
			Rev:        id,
			Comment:    comment,
			dir:        pkg.Dir,
			ws:         pkg.Root,
			vcs:        vcs,
		})
	}
	return err1
}