Browse Source

Fixed bug for gopm build

pull/103/head
Unknown 11 years ago
parent
commit
5d36170b95
  1. 6
      cmd/build.go
  2. 47
      cmd/gopath.go
  3. 5
      cmd/install.go

6
cmd/build.go

@ -33,11 +33,13 @@ and execute 'go build'
gopm build <go build commands>`, gopm build <go build commands>`,
Action: runBuild, Action: runBuild,
Flags: []cli.Flag{
cli.BoolFlag{"verbose, v", "show process details"},
},
} }
func runBuild(ctx *cli.Context) { func runBuild(ctx *cli.Context) {
log.PureMode = ctx.GlobalBool("noterm") setup(ctx)
log.Verbose = ctx.GlobalBool("verbose")
if !ctx.Bool("remote") { if !ctx.Bool("remote") {
// Get GOPATH. // Get GOPATH.

47
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) imports := doc.GetAllImports([]string{dirPath}, ".", false)
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())
}
}
pkgs = make(map[string]*doc.Pkg) pkgs = make(map[string]*doc.Pkg)
var imports []string = pkg.Imports
if isTest {
imports = append(imports, pkg.TestImports...)
}
for _, name := range imports { for _, name := range imports {
if name == "C" { if name == "C" {
//panic("nonono")
continue continue
} }
if !doc.IsGoRepoPath(name) { 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 { func pkgInCache(name string, cachePkgs map[string]*doc.Pkg) bool {
//pkgs := strings.Split(name, "/")
_, ok := cachePkgs[name] _, ok := cachePkgs[name]
return ok 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 { func getChildPkgs(ctx *cli.Context, cpath string, ppkg *doc.Pkg, cachePkgs map[string]*doc.Pkg, isTest bool) error {
var suf string pkgs, err := getGopmPkgs(cpath, isTest)
if ppkg != nil {
suf = versionSuffix(ppkg.Value)
}
pkgs, err := getGopmPkgs(cpath+suf, isTest)
if err != nil { if err != nil {
return errors.New("Fail to get gopmfile deps: " + err.Error()) return errors.New("Fail to get gopmfile deps: " + err.Error())
} }
for name, pkg := range pkgs { for name, pkg := range pkgs {
if !pkgInCache(name, cachePkgs) { pkg.RootPath = doc.GetProjectPath(pkg.ImportPath)
if !pkgInCache(pkg.RootPath, cachePkgs) {
var newPath string var newPath string
if !build.IsLocalImport(name) { if !build.IsLocalImport(name) {
suf := versionSuffix(pkg.Value) suf := versionSuffix(pkg.Value)
newPath = filepath.Join(installRepoPath, pkg.ImportPath) pkgPath := strings.Replace(
if len(pkg.Value) == 0 && !ctx.Bool("remote") { pkg.ImportPath, pkg.RootPath, pkg.RootPath+suf, 1)
newPath = filepath.Join(installGopath, pkg.ImportPath) 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) { if pkgName != "" && strings.HasPrefix(pkg.ImportPath, pkgName) {
newPath = filepath.Join(curPath, pkg.ImportPath[len(pkgName)+1:]+suf) newPath = filepath.Join(curPath, pkgPath)
} else { } else {
if !com.IsExist(newPath + suf) { if !com.IsExist(newPath) {
node := doc.NewNode(pkg.ImportPath, pkg.ImportPath, node := doc.NewNode(pkg.ImportPath, pkg.ImportPath,
pkg.Type, pkg.Value, true) pkg.Type, pkg.Value, true)
nodes := []*doc.Node{node} nodes := []*doc.Node{node}
@ -121,15 +107,13 @@ func getChildPkgs(ctx *cli.Context, cpath string, ppkg *doc.Pkg, cachePkgs map[s
return err return err
} }
} }
cachePkgs[pkg.RootPath] = pkg
err = getChildPkgs(ctx, newPath, pkg, cachePkgs, false) err = getChildPkgs(ctx, newPath, pkg, cachePkgs, false)
if err != nil { if err != nil {
return err return err
} }
} }
} }
if ppkg != nil && !build.IsLocalImport(ppkg.ImportPath) {
cachePkgs[ppkg.ImportPath] = ppkg
}
return nil return nil
} }
@ -188,7 +172,7 @@ func execCmd(gopath, curPath string, args ...string) error {
err = cmd.Run() err = cmd.Run()
log.Log("\n====== application outputs end ======") log.Log("====== application outputs end ======")
return err return err
} }
@ -252,7 +236,8 @@ func genNewGoPath(ctx *cli.Context, isTest bool) {
continue 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) log.Log("Linking %s", name+suf)
err = autoLink(oldPath, newPath) err = autoLink(oldPath, newPath)
if err != nil { if err != nil {

5
cmd/install.go

@ -37,15 +37,14 @@ If no argument is supplied, then gopmfile must be present`,
Action: runInstall, Action: runInstall,
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.BoolFlag{"pkg, p", "only install non-main packages"}, cli.BoolFlag{"pkg, p", "only install non-main packages"},
cli.BoolFlag{"verbose, v", "show process details"},
}, },
} }
func runInstall(ctx *cli.Context) { func runInstall(ctx *cli.Context) {
log.PureMode = ctx.GlobalBool("noterm") setup(ctx)
log.Verbose = ctx.GlobalBool("verbose")
var target string var target string
switch len(ctx.Args()) { switch len(ctx.Args()) {
case 0: case 0:
if !com.IsFile(".gopmfile") { if !com.IsFile(".gopmfile") {

Loading…
Cancel
Save