diff --git a/cmd/build.go b/cmd/build.go index f1a595e7a..155e00880 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -33,11 +33,13 @@ and execute 'go build' gopm build `, Action: runBuild, + Flags: []cli.Flag{ + cli.BoolFlag{"verbose, v", "show process details"}, + }, } func runBuild(ctx *cli.Context) { - log.PureMode = ctx.GlobalBool("noterm") - log.Verbose = ctx.GlobalBool("verbose") + setup(ctx) if !ctx.Bool("remote") { // Get GOPATH. diff --git a/cmd/gopath.go b/cmd/gopath.go index 69204d8b8..659ec8be9 100644 --- a/cmd/gopath.go +++ b/cmd/gopath.go @@ -35,22 +35,10 @@ func getGopmPkgs(dirPath string, isTest bool) (pkgs map[string]*doc.Pkg, err err } } - pkg, err := build.ImportDir(dirPath, build.AllowBinary) - if err != nil { - pkg, err = build.ImportDir(newGoPath+dirPath[len(oldGoPath):], build.AllowBinary) - if err != nil { - return map[string]*doc.Pkg{}, errors.New("Fail to get imports: " + err.Error()) - } - } - + imports := doc.GetAllImports([]string{dirPath}, ".", false) pkgs = make(map[string]*doc.Pkg) - var imports []string = pkg.Imports - if isTest { - imports = append(imports, pkg.TestImports...) - } for _, name := range imports { if name == "C" { - //panic("nonono") continue } if !doc.IsGoRepoPath(name) { @@ -74,7 +62,6 @@ func getGopmPkgs(dirPath string, isTest bool) (pkgs map[string]*doc.Pkg, err err } func pkgInCache(name string, cachePkgs map[string]*doc.Pkg) bool { - //pkgs := strings.Split(name, "/") _, ok := cachePkgs[name] return ok } @@ -86,28 +73,27 @@ func autoLink(oldPath, newPath string) error { } func getChildPkgs(ctx *cli.Context, cpath string, ppkg *doc.Pkg, cachePkgs map[string]*doc.Pkg, isTest bool) error { - var suf string - if ppkg != nil { - suf = versionSuffix(ppkg.Value) - } - pkgs, err := getGopmPkgs(cpath+suf, isTest) + pkgs, err := getGopmPkgs(cpath, isTest) if err != nil { return errors.New("Fail to get gopmfile deps: " + err.Error()) } for name, pkg := range pkgs { - if !pkgInCache(name, cachePkgs) { + pkg.RootPath = doc.GetProjectPath(pkg.ImportPath) + if !pkgInCache(pkg.RootPath, cachePkgs) { var newPath string if !build.IsLocalImport(name) { - suf := versionSuffix(pkg.Value) - newPath = filepath.Join(installRepoPath, pkg.ImportPath) - if len(pkg.Value) == 0 && !ctx.Bool("remote") { - newPath = filepath.Join(installGopath, pkg.ImportPath) + pkgPath := strings.Replace( + pkg.ImportPath, pkg.RootPath, pkg.RootPath+suf, 1) + newPath = filepath.Join(installRepoPath, pkgPath) + if len(suf) == 0 && !ctx.Bool("remote") && + com.IsDir(filepath.Join(installGopath, pkgPath)) { + newPath = filepath.Join(installGopath, pkgPath) } if pkgName != "" && strings.HasPrefix(pkg.ImportPath, pkgName) { - newPath = filepath.Join(curPath, pkg.ImportPath[len(pkgName)+1:]+suf) + newPath = filepath.Join(curPath, pkgPath) } else { - if !com.IsExist(newPath + suf) { + if !com.IsExist(newPath) { node := doc.NewNode(pkg.ImportPath, pkg.ImportPath, pkg.Type, pkg.Value, true) nodes := []*doc.Node{node} @@ -121,15 +107,13 @@ func getChildPkgs(ctx *cli.Context, cpath string, ppkg *doc.Pkg, cachePkgs map[s return err } } + cachePkgs[pkg.RootPath] = pkg err = getChildPkgs(ctx, newPath, pkg, cachePkgs, false) if err != nil { return err } } } - if ppkg != nil && !build.IsLocalImport(ppkg.ImportPath) { - cachePkgs[ppkg.ImportPath] = ppkg - } return nil } @@ -188,7 +172,7 @@ func execCmd(gopath, curPath string, args ...string) error { err = cmd.Run() - log.Log("\n====== application outputs end ======") + log.Log("====== application outputs end ======") return err } @@ -252,7 +236,8 @@ func genNewGoPath(ctx *cli.Context, isTest bool) { continue } - if !isExistP && (len(pkg.Value) > 0 || ctx.Bool("remote")) { + if (!isExistP && (len(pkg.Value) > 0 || ctx.Bool("remote"))) || + !com.IsDir(filepath.Join(installGopath, pkg.ImportPath)) { log.Log("Linking %s", name+suf) err = autoLink(oldPath, newPath) if err != nil { diff --git a/cmd/install.go b/cmd/install.go index 9182c5e32..4670fe387 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -37,15 +37,14 @@ If no argument is supplied, then gopmfile must be present`, Action: runInstall, Flags: []cli.Flag{ cli.BoolFlag{"pkg, p", "only install non-main packages"}, + cli.BoolFlag{"verbose, v", "show process details"}, }, } func runInstall(ctx *cli.Context) { - log.PureMode = ctx.GlobalBool("noterm") - log.Verbose = ctx.GlobalBool("verbose") + setup(ctx) var target string - switch len(ctx.Args()) { case 0: if !com.IsFile(".gopmfile") {