Skip to content

Commit

Permalink
dep/cmd/dep: Update init.go to use dep.Project
Browse files Browse the repository at this point in the history
Signed-off-by: Ibrahim AshShohail <[email protected]>
  • Loading branch information
ibrasho committed Jun 14, 2017
1 parent 71a2607 commit 929ef28
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions cmd/dep/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
}
}

// The root path may lie within a symlinked directory, resolve the path
// before moving forward
var err error
root, ctx.GOPATH, err = ctx.ResolveProjectRootAndGOPATH(root)
p, err := dep.NewProject(root)
if err != nil {
return errors.Wrapf(err, "resolve project root")
} else if ctx.GOPATH == "" {
Expand Down Expand Up @@ -108,11 +105,13 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
return errors.Errorf("invalid state: manifest %q does not exist, but lock %q does", mf, lf)
}

cpr, err := ctx.SplitAbsoluteProjectRoot(root)
ip, err := ctx.SplitAbsoluteProjectRoot(root)
if err != nil {
return errors.Wrap(err, "determineProjectRoot")
}
pkgT, directDeps, err := getDirectDependencies(root, cpr)
p.ImportRoot = gps.ProjectRoot(ip)

pkgT, directDeps, err := getDirectDependencies(p)
if err != nil {
return err
}
Expand All @@ -125,12 +124,12 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {

// Initialize with imported data, then fill in the gaps using the GOPATH
rootAnalyzer := newRootAnalyzer(cmd.skipTools, ctx, directDeps, sm)
m, l, err := rootAnalyzer.InitializeRootManifestAndLock(root, gps.ProjectRoot(cpr))
p.Manifest, p.Lock, err = rootAnalyzer.InitializeRootManifestAndLock(root, p.ImportRoot)
if err != nil {
return err
}
gs := newGopathScanner(ctx, directDeps, sm)
err = gs.InitializeRootManifestAndLock(m, l)
err = gs.InitializeRootManifestAndLock(p.Manifest, p.Lock)
if err != nil {
return err
}
Expand All @@ -140,8 +139,8 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
params := gps.SolveParameters{
RootDir: root,
RootPackageTree: pkgT,
Manifest: m,
Lock: l,
Manifest: p.Manifest,
Lock: p.Lock,
ProjectAnalyzer: rootAnalyzer,
}

Expand All @@ -159,10 +158,10 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
handleAllTheFailuresOfTheWorld(err)
return err
}
l = dep.LockFromSolution(soln)
p.Lock = dep.LockFromSolution(soln)

rootAnalyzer.FinalizeRootManifestAndLock(m, l)
gs.FinalizeRootManifestAndLock(m, l)
rootAnalyzer.FinalizeRootManifestAndLock(p.Manifest, p.Lock)
gs.FinalizeRootManifestAndLock(p.Manifest, p.Lock)

// Run gps.Prepare with appropriate constraint solutions from solve run
// to generate the final lock memo.
Expand All @@ -171,7 +170,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
return errors.Wrap(err, "prepare solver")
}

l.SolveMeta.InputsDigest = s.HashInputs()
p.Lock.SolveMeta.InputsDigest = s.HashInputs()

// Pass timestamp (yyyyMMddHHmmss format) as suffix to backup name.
vendorbak, err := dep.BackupVendor(vpath, time.Now().Format("20060102150405"))
Expand All @@ -182,7 +181,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
ctx.Err.Printf("Old vendor backed up to %v", vendorbak)
}

sw, err := dep.NewSafeWriter(m, nil, l, dep.VendorAlways)
sw, err := dep.NewSafeWriter(p.Manifest, nil, p.Lock, dep.VendorAlways)
if err != nil {
return err
}
Expand All @@ -194,13 +193,8 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
return nil
}

func getDirectDependencies(root, cpr string) (pkgtree.PackageTree, map[string]bool, error) {
resolved, err := filepath.EvalSymlinks(root)
if err != nil {
return pkgtree.PackageTree{}, nil, errors.Wrap(err, "filepath.EvalSymlinks")
}

pkgT, err := pkgtree.ListPackages(resolved, cpr)
func getDirectDependencies(p *dep.Project) (pkgtree.PackageTree, map[string]bool, error) {
pkgT, err := pkgtree.ListPackages(p.ResolvedAbsRoot, string(p.ImportRoot))
if err != nil {
return pkgtree.PackageTree{}, nil, errors.Wrap(err, "gps.ListPackages")
}
Expand Down

0 comments on commit 929ef28

Please sign in to comment.