Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
middle of refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
carolynvs committed May 10, 2017
1 parent 74a5822 commit 9705cf2
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 135 deletions.
97 changes: 8 additions & 89 deletions cmd/dep/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/golang/dep/internal"
"github.com/golang/dep/internal/gps"
"github.com/golang/dep/internal/gps/pkgtree"
"github.com/golang/dep/internal/importer"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -58,13 +57,6 @@ type initCommand struct {
skipTools bool
}

func trimPathPrefix(p1, p2 string) string {
if internal.HasFilepathPrefix(p1, p2) {
return p1[len(p2):]
}
return p1
}

func (cmd *initCommand) Run(ctx *dep.Ctx, loggers *Loggers, args []string) error {
if len(args) > 1 {
return errors.Errorf("too many args (%d)", len(args))
Expand Down Expand Up @@ -118,85 +110,37 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, loggers *Loggers, args []string) error
sm.UseDefaultSignalHandling()
defer sm.Release()

pd, err := getProjectData(ctx, loggers, pkgT, cpr, sm)
if err != nil {
return err
}

var rootAnalyzer internal.RootProjectAnalyzer
var analyzer gps.ProjectAnalyzer
if cmd.skipTools {
rootAnalyzer = internal.GopathAnalyzer{}
rootAnalyzer = internal.NewGopathAnalyzer(ctx, pkgtree, cpr, sm)
analyzer = dep.Analyzer{}
} else {
rootAnalyzer = internal.CompositeAnalyzer{
Analyzers: []internal.RootProjectAnalyzer{
internal.GopathAnalyzer{},
internal.NewGopathAnalyzer(ctx, pkgtree, cpr, sm),
internal.ImportAnalyzer{},
}}
analyzer = internal.ImportAnalyzer{}
}

// Analyze the root project to create an root manifest and lock
rootM, rootL, err := rootAnalyzer.DeriveRootManifestAndLock(root, gps.ProjectRoot(cpr))
m, l, err := rootAnalyzer.DeriveRootManifestAndLock(root, gps.ProjectRoot(cpr))
if err != nil {
return errors.Wrap(err, "Error initializing a manifest and lock")
}

if loggers.Verbose {
loggers.Err.Println("dep: Solving...")
}
params := gps.SolveParameters{
RootDir: root,
RootPackageTree: pkgT,
Manifest: rootM,
Lock: rootL,
Manifest: m,
Lock: l,
ProjectAnalyzer: analyzer,
}

// BEGIN
m := &dep.Manifest{
Dependencies: pd.constraints,
}

if !cmd.skipTools {
ipd, err := importer.Import(root, cpr)
if err != nil {
return errors.Wrap(err, "Error importing dependency management configuration")
}

if ipd != nil {
m.Ignored = ipd.Ignored
for pr, c := range ipd.Dependencies {
internal.Vlogf("Importing dependency on %s: %s", pr, c)
m.Dependencies[pr] = c
}
}
}

// Make an initial lock from what knowledge we've collected about the
// versions on disk
l := &dep.Lock{
P: make([]gps.LockedProject, 0, len(pd.ondisk)),
}

for pr, v := range pd.ondisk {
// That we have to chop off these path prefixes is a symptom of
// a problem in gps itself
pkgs := make([]string, 0, len(pd.dependencies[pr]))
prslash := string(pr) + "/"
for _, pkg := range pd.dependencies[pr] {
if pkg == string(pr) {
pkgs = append(pkgs, ".")
} else {
pkgs = append(pkgs, trimPathPrefix(pkg, prslash))
}
}

l.P = append(l.P, gps.NewLockedProject(
gps.ProjectIdentifier{ProjectRoot: pr}, v, pkgs),
)
}

// END

if *verbose {
params.Trace = true
params.TraceLogger = log.New(os.Stderr, "", 0)
Expand Down Expand Up @@ -249,30 +193,6 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, loggers *Loggers, args []string) error
return nil
}

// contains checks if a array of strings contains a value
func contains(a []string, b string) bool {
for _, v := range a {
if b == v {
return true
}
}
return false
}

// isStdLib reports whether $GOROOT/src/path should be considered
// part of the standard distribution. For historical reasons we allow people to add
// their own code to $GOROOT instead of using $GOPATH, but we assume that
// code will start with a domain name (dot in the first element).
// This was loving taken from src/cmd/go/pkg.go in Go's code (isStandardImportPath).
func isStdLib(path string) bool {
i := strings.Index(path, "/")
if i < 0 {
i = len(path)
}
elem := path[:i]
return !strings.Contains(elem, ".")
}

// TODO solve failures can be really creative - we need to be similarly creative
// in handling them and informing the user appropriately
func handleAllTheFailuresOfTheWorld(err error) {
Expand All @@ -284,7 +204,6 @@ func hasImportPathPrefix(s, prefix string) bool {
}
return strings.HasPrefix(s, prefix+"/")
}

// getProjectPropertiesFromVersion takes a gps.Version and returns a proper
// gps.ProjectProperties with Constraint value based on the provided version.
func getProjectPropertiesFromVersion(v gps.Version) gps.ProjectProperties {
Expand Down
Loading

0 comments on commit 9705cf2

Please sign in to comment.