From 061cf9aef8eba1e4b921b4ae083539dd2bd3c9d0 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 10 Dec 2013 17:18:07 +0800 Subject: [PATCH] supports local path for gopmfile deps package's value --- cmd/cmd.go | 6 ++++++ cmd/get.go | 4 ++++ cmd/gopath.go | 23 ++++++++++++++++++++--- doc/struct.go | 3 ++- gopm.go | 2 +- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index a7c2ac839..d2bff0c43 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -18,6 +18,7 @@ import ( "os" "strings" + "github.com/Unknwon/com" "github.com/codegangsta/cli" "github.com/gpmgo/gopm/doc" @@ -56,6 +57,11 @@ func validPath(info string) (string, string) { l := len(infos) switch { case l == 1: + // for local imports + if com.IsFile(infos[0]) { + return doc.LOCAL, infos[0] + } + return doc.BRANCH, "" case l == 2: switch infos[1] { diff --git a/cmd/get.go b/cmd/get.go index 31668fdd5..ab98da8e0 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -180,6 +180,10 @@ func copyToGopath(srcPath, destPath string) { func downloadPackages(ctx *cli.Context, nodes []*doc.Node) { // Check all packages, they may be raw packages path. for _, n := range nodes { + // Check if local reference + if n.Type == doc.LOCAL { + continue + } // Check if it is a valid remote path. if doc.IsValidRemotePath(n.ImportPath) { gopathDir := path.Join(installGopath, n.ImportPath) diff --git a/cmd/gopath.go b/cmd/gopath.go index 65a1d8fdd..305ab1eba 100644 --- a/cmd/gopath.go +++ b/cmd/gopath.go @@ -52,6 +52,13 @@ func getGopmPkgs(dirPath string, isTest bool) (pkgs map[string]*doc.Pkg, err err Value: info[i+1:], } continue + } else if com.IsDir(info) { + pkgs[name] = &doc.Pkg{ + ImportPath: name, + Type: doc.LOCAL, + Value: info, + } + continue } } } @@ -81,7 +88,7 @@ func getChildPkgs(ctx *cli.Context, cpath string, ppkg *doc.Pkg, cachePkgs map[s pkg.RootPath = doc.GetProjectPath(pkg.ImportPath) if !pkgInCache(pkg.RootPath, cachePkgs) { var newPath string - if !build.IsLocalImport(name) { + if !build.IsLocalImport(name) && pkg.Type != doc.LOCAL { suf := versionSuffix(pkg.Value) pkgPath := strings.Replace( pkg.ImportPath, pkg.RootPath, pkg.RootPath+suf, 1) @@ -102,7 +109,11 @@ func getChildPkgs(ctx *cli.Context, cpath string, ppkg *doc.Pkg, cachePkgs map[s } } } else { - newPath, err = filepath.Abs(name) + if pkg.Type == doc.LOCAL { + newPath, err = filepath.Abs(pkg.Value) + } else { + newPath, err = filepath.Abs(name) + } if err != nil { return err } @@ -216,7 +227,13 @@ func genNewGoPath(ctx *cli.Context, isTest bool) { for name, pkg := range cachePkgs { suf := versionSuffix(pkg.Value) - oldPath := filepath.Join(installRepoPath, name) + suf + var oldPath string + if pkg.Type == doc.LOCAL { + oldPath, _ = filepath.Abs(pkg.Value) + } else { + oldPath = filepath.Join(installRepoPath, name) + suf + } + newPath := filepath.Join(newGoPathSrc, name) paths := strings.Split(name, "/") var isExistP, isCurChild bool diff --git a/doc/struct.go b/doc/struct.go index f92151618..96c538503 100644 --- a/doc/struct.go +++ b/doc/struct.go @@ -32,13 +32,14 @@ const ( TAG = "tag" BRANCH = "branch" COMMIT = "commit" + LOCAL = "local" ) type Pkg struct { ImportPath string RootPath string Type string - Value string // Branch, tag or commit. + Value string // Branch, tag, commit or local. } func (pkg *Pkg) VerString() string { diff --git a/gopm.go b/gopm.go index c3d3a7893..9bf0c7d64 100644 --- a/gopm.go +++ b/gopm.go @@ -29,7 +29,7 @@ import ( // Test that go1.1 tag above is included in builds. main.go refers to this definition. const go11tag = true -const APP_VER = "0.6.0.1209" +const APP_VER = "0.6.0.1210" // //cmd.CmdSearch, // cmdClean,