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

Commit 9705cf2

Browse files
committed
middle of refactoring
1 parent 74a5822 commit 9705cf2

File tree

4 files changed

+354
-135
lines changed

4 files changed

+354
-135
lines changed

cmd/dep/init.go

Lines changed: 8 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/golang/dep/internal"
1616
"github.com/golang/dep/internal/gps"
1717
"github.com/golang/dep/internal/gps/pkgtree"
18-
"github.com/golang/dep/internal/importer"
1918
"github.com/pkg/errors"
2019
)
2120

@@ -58,13 +57,6 @@ type initCommand struct {
5857
skipTools bool
5958
}
6059

61-
func trimPathPrefix(p1, p2 string) string {
62-
if internal.HasFilepathPrefix(p1, p2) {
63-
return p1[len(p2):]
64-
}
65-
return p1
66-
}
67-
6860
func (cmd *initCommand) Run(ctx *dep.Ctx, loggers *Loggers, args []string) error {
6961
if len(args) > 1 {
7062
return errors.Errorf("too many args (%d)", len(args))
@@ -118,85 +110,37 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, loggers *Loggers, args []string) error
118110
sm.UseDefaultSignalHandling()
119111
defer sm.Release()
120112

121-
pd, err := getProjectData(ctx, loggers, pkgT, cpr, sm)
122-
if err != nil {
123-
return err
124-
}
125-
126113
var rootAnalyzer internal.RootProjectAnalyzer
127114
var analyzer gps.ProjectAnalyzer
128115
if cmd.skipTools {
129-
rootAnalyzer = internal.GopathAnalyzer{}
116+
rootAnalyzer = internal.NewGopathAnalyzer(ctx, pkgtree, cpr, sm)
130117
analyzer = dep.Analyzer{}
131118
} else {
132119
rootAnalyzer = internal.CompositeAnalyzer{
133120
Analyzers: []internal.RootProjectAnalyzer{
134-
internal.GopathAnalyzer{},
121+
internal.NewGopathAnalyzer(ctx, pkgtree, cpr, sm),
135122
internal.ImportAnalyzer{},
136123
}}
137124
analyzer = internal.ImportAnalyzer{}
138125
}
139126

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

143133
if loggers.Verbose {
144134
loggers.Err.Println("dep: Solving...")
145135
}
146136
params := gps.SolveParameters{
147137
RootDir: root,
148138
RootPackageTree: pkgT,
149-
Manifest: rootM,
150-
Lock: rootL,
139+
Manifest: m,
140+
Lock: l,
151141
ProjectAnalyzer: analyzer,
152142
}
153143

154-
// BEGIN
155-
m := &dep.Manifest{
156-
Dependencies: pd.constraints,
157-
}
158-
159-
if !cmd.skipTools {
160-
ipd, err := importer.Import(root, cpr)
161-
if err != nil {
162-
return errors.Wrap(err, "Error importing dependency management configuration")
163-
}
164-
165-
if ipd != nil {
166-
m.Ignored = ipd.Ignored
167-
for pr, c := range ipd.Dependencies {
168-
internal.Vlogf("Importing dependency on %s: %s", pr, c)
169-
m.Dependencies[pr] = c
170-
}
171-
}
172-
}
173-
174-
// Make an initial lock from what knowledge we've collected about the
175-
// versions on disk
176-
l := &dep.Lock{
177-
P: make([]gps.LockedProject, 0, len(pd.ondisk)),
178-
}
179-
180-
for pr, v := range pd.ondisk {
181-
// That we have to chop off these path prefixes is a symptom of
182-
// a problem in gps itself
183-
pkgs := make([]string, 0, len(pd.dependencies[pr]))
184-
prslash := string(pr) + "/"
185-
for _, pkg := range pd.dependencies[pr] {
186-
if pkg == string(pr) {
187-
pkgs = append(pkgs, ".")
188-
} else {
189-
pkgs = append(pkgs, trimPathPrefix(pkg, prslash))
190-
}
191-
}
192-
193-
l.P = append(l.P, gps.NewLockedProject(
194-
gps.ProjectIdentifier{ProjectRoot: pr}, v, pkgs),
195-
)
196-
}
197-
198-
// END
199-
200144
if *verbose {
201145
params.Trace = true
202146
params.TraceLogger = log.New(os.Stderr, "", 0)
@@ -249,30 +193,6 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, loggers *Loggers, args []string) error
249193
return nil
250194
}
251195

252-
// contains checks if a array of strings contains a value
253-
func contains(a []string, b string) bool {
254-
for _, v := range a {
255-
if b == v {
256-
return true
257-
}
258-
}
259-
return false
260-
}
261-
262-
// isStdLib reports whether $GOROOT/src/path should be considered
263-
// part of the standard distribution. For historical reasons we allow people to add
264-
// their own code to $GOROOT instead of using $GOPATH, but we assume that
265-
// code will start with a domain name (dot in the first element).
266-
// This was loving taken from src/cmd/go/pkg.go in Go's code (isStandardImportPath).
267-
func isStdLib(path string) bool {
268-
i := strings.Index(path, "/")
269-
if i < 0 {
270-
i = len(path)
271-
}
272-
elem := path[:i]
273-
return !strings.Contains(elem, ".")
274-
}
275-
276196
// TODO solve failures can be really creative - we need to be similarly creative
277197
// in handling them and informing the user appropriately
278198
func handleAllTheFailuresOfTheWorld(err error) {
@@ -284,7 +204,6 @@ func hasImportPathPrefix(s, prefix string) bool {
284204
}
285205
return strings.HasPrefix(s, prefix+"/")
286206
}
287-
288207
// getProjectPropertiesFromVersion takes a gps.Version and returns a proper
289208
// gps.ProjectProperties with Constraint value based on the provided version.
290209
func getProjectPropertiesFromVersion(v gps.Version) gps.ProjectProperties {

0 commit comments

Comments
 (0)