Exemplo n.º 1
0
//just a basic wrapper to give goutil.Import the same signature as ImportTree
func imports(ctx *build.Context, ip string) (pkgs goutil.Packages, err error) {
	pkg, err := goutil.Import(ctx, ip)
	if err != nil {
		return nil, err
	}
	return append(pkgs, pkg), nil
}
Exemplo n.º 2
0
func readGodeps(d *DepLog) error {
	bs, err := ioutil.ReadFile(d.godepPath())
	if err != nil {
		//no old dep info, nothing to do
		return nil
	}

	var godep Godeps
	err = json.Unmarshal(bs, &godep)
	if err != nil {
		return err
	}

	d.fromGodep = true
	d.oldGo = godep.GoVersion
	for _, rev := range godep.Deps {
		//XXX below nil may cause problems if we ever include -tags
		pkg, err := goutil.Import(nil, rev.ImportPath)
		if err != nil {
			return err
		}
		root, err := repoRoot(pkg)
		if err != nil {
			return err
		}
		p := root.path
		d.Revs[p] = &Entry{repo: p, old: rev.Rev}
	}
	return nil
}
Exemplo n.º 3
0
//Import finds all the repo roots of all the dependencies of every
//package in the root of path, excluding standard library.
func Import(ctx *build.Context, path string) (*Root, []*Root, error) {
	pkg, err := goutil.Import(nil, path)
	if err != nil {
		return nil, nil, err
	}

	root, err := repoRoot(pkg)
	if err != nil {
		return nil, nil, err
	}

	tree := filepath.Join(pkg.Build.Root, "src", root.path)
	pkgs, err := goutil.ImportTree(ctx, tree)
	if err != nil {
		return nil, nil, err
	}

	var deps goutil.Packages
	for _, pkg := range pkgs {
		ps, err := pkg.ImportDeps()
		if err != nil {
			return nil, nil, err
		}
		deps = append(deps, ps...)
	}
	deps = deps.NoStdlib().Uniq()

	var roots []*Root
	seen := map[string]bool{root.path: true}
	for _, dep := range deps {
		root, err := repoRoot(dep)
		if err != nil {
			return nil, nil, err
		}
		if !seen[root.path] {
			seen[root.path] = true
			roots = append(roots, root)
		}
	}

	return root, roots, nil
}
Exemplo n.º 4
0
//Usage: %name %flags regexp [package|directory]
func main() {
	log.SetFlags(0)
	fatal := log.Fatalln

	flag.Usage = Usage
	flag.Parse()
	args := flag.Args()
	if len(args) == 0 || len(args) > 2 {
		Usage()
		os.Exit(2)
	}

	re, err := regexp.Compile(args[0])
	if err != nil {
		fatal(err)
	}
	if *l {
		re.Longest()
	}

	var m goutil.StringMatcher = re
	if *v {
		m = negmatcher{re}
	}

	tree := false
	imp := "."
	if len(args) > 1 {
		imp = args[1]
		if d, f := filepath.Split(imp); f == "..." {
			tree = true
			imp = d
		}
	}

	var pkgs goutil.Packages
	switch {
	case tree && *r:
		pkgs, err := goutil.ImportTree(nil, imp)
		if err != nil {
			log.Println(err)
		}
		var ps goutil.Packages
		for _, p := range pkgs {
			t, err := p.ImportDeps()
			if err != nil {
				fatal(err)
			}
			ps = append(ps, t...)
		}
		pkgs = append(pkgs, ps...).Uniq()
	case tree:
		pkgs, err = goutil.ImportTree(nil, imp)
		if err != nil {
			log.Println(err)
		}
	case *r:
		pkgs, err = goutil.ImportRec(nil, imp)
		if err != nil {
			fatal(err)
		}
	default:
		p, err := goutil.Import(nil, imp)
		if err != nil {
			fatal(err)
		}
		pkgs = goutil.Packages{p}
	}

	if *nostdlib {
		pkgs = pkgs.NoStdlib()
	}

	err = pkgs.Parse(false)
	if err != nil {
		fatal(err)
	}

	multiples := len(pkgs) > 1
	for _, pkg := range pkgs {
		for _, d := range pkg.Decls().SplitSpecs().Named(m) {
			print(multiples, pkg, d)
		}
	}
}