Browse Source

supports local path for gopmfile deps package's value

pull/103/head
Lunny Xiao 11 years ago
parent
commit
061cf9aef8
  1. 6
      cmd/cmd.go
  2. 4
      cmd/get.go
  3. 23
      cmd/gopath.go
  4. 3
      doc/struct.go
  5. 2
      gopm.go

6
cmd/cmd.go

@ -18,6 +18,7 @@ import (
"os" "os"
"strings" "strings"
"github.com/Unknwon/com"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/gpmgo/gopm/doc" "github.com/gpmgo/gopm/doc"
@ -56,6 +57,11 @@ func validPath(info string) (string, string) {
l := len(infos) l := len(infos)
switch { switch {
case l == 1: case l == 1:
// for local imports
if com.IsFile(infos[0]) {
return doc.LOCAL, infos[0]
}
return doc.BRANCH, "" return doc.BRANCH, ""
case l == 2: case l == 2:
switch infos[1] { switch infos[1] {

4
cmd/get.go

@ -180,6 +180,10 @@ func copyToGopath(srcPath, destPath string) {
func downloadPackages(ctx *cli.Context, nodes []*doc.Node) { func downloadPackages(ctx *cli.Context, nodes []*doc.Node) {
// Check all packages, they may be raw packages path. // Check all packages, they may be raw packages path.
for _, n := range nodes { for _, n := range nodes {
// Check if local reference
if n.Type == doc.LOCAL {
continue
}
// Check if it is a valid remote path. // Check if it is a valid remote path.
if doc.IsValidRemotePath(n.ImportPath) { if doc.IsValidRemotePath(n.ImportPath) {
gopathDir := path.Join(installGopath, n.ImportPath) gopathDir := path.Join(installGopath, n.ImportPath)

23
cmd/gopath.go

@ -52,6 +52,13 @@ func getGopmPkgs(dirPath string, isTest bool) (pkgs map[string]*doc.Pkg, err err
Value: info[i+1:], Value: info[i+1:],
} }
continue 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) pkg.RootPath = doc.GetProjectPath(pkg.ImportPath)
if !pkgInCache(pkg.RootPath, cachePkgs) { if !pkgInCache(pkg.RootPath, cachePkgs) {
var newPath string var newPath string
if !build.IsLocalImport(name) { if !build.IsLocalImport(name) && pkg.Type != doc.LOCAL {
suf := versionSuffix(pkg.Value) suf := versionSuffix(pkg.Value)
pkgPath := strings.Replace( pkgPath := strings.Replace(
pkg.ImportPath, pkg.RootPath, pkg.RootPath+suf, 1) 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 { } 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 { if err != nil {
return err return err
} }
@ -216,7 +227,13 @@ func genNewGoPath(ctx *cli.Context, isTest bool) {
for name, pkg := range cachePkgs { for name, pkg := range cachePkgs {
suf := versionSuffix(pkg.Value) 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) newPath := filepath.Join(newGoPathSrc, name)
paths := strings.Split(name, "/") paths := strings.Split(name, "/")
var isExistP, isCurChild bool var isExistP, isCurChild bool

3
doc/struct.go

@ -32,13 +32,14 @@ const (
TAG = "tag" TAG = "tag"
BRANCH = "branch" BRANCH = "branch"
COMMIT = "commit" COMMIT = "commit"
LOCAL = "local"
) )
type Pkg struct { type Pkg struct {
ImportPath string ImportPath string
RootPath string RootPath string
Type string Type string
Value string // Branch, tag or commit. Value string // Branch, tag, commit or local.
} }
func (pkg *Pkg) VerString() string { func (pkg *Pkg) VerString() string {

2
gopm.go

@ -29,7 +29,7 @@ import (
// Test that go1.1 tag above is included in builds. main.go refers to this definition. // Test that go1.1 tag above is included in builds. main.go refers to this definition.
const go11tag = true const go11tag = true
const APP_VER = "0.6.0.1209" const APP_VER = "0.6.0.1210"
// //cmd.CmdSearch, // //cmd.CmdSearch,
// cmdClean, // cmdClean,

Loading…
Cancel
Save