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

Hide dep guts under internal/ #527

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/dep/dep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"path/filepath"
"testing"

"github.com/golang/dep/test"
"github.com/golang/dep/internal/test"
)

// The TestMain function creates a dep command for testing purposes and
Expand Down
13 changes: 7 additions & 6 deletions cmd/dep/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import (
"strconv"
"strings"

"github.com/golang/dep"
"github.com/golang/dep/gps"
"github.com/golang/dep/gps/pkgtree"
"github.com/golang/dep/internal"
"github.com/golang/dep/internal/cfg"
"github.com/golang/dep/internal/dep"
"github.com/golang/dep/internal/util"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -105,7 +106,7 @@ type ensureCommand struct {

func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
if cmd.examples {
internal.Logln(strings.TrimSpace(ensureExamples))
util.Logln(strings.TrimSpace(ensureExamples))
return nil
}

Expand Down Expand Up @@ -156,7 +157,7 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {

// check if vendor exists, because if the locks are the same but
// vendor does not exist we should write vendor
vendorExists, err := dep.IsNonEmptyDir(filepath.Join(p.AbsRoot, "vendor"))
vendorExists, err := util.IsNonEmptyDir(filepath.Join(p.AbsRoot, "vendor"))
if err != nil {
return errors.Wrap(err, "ensure vendor is a directory")
}
Expand All @@ -165,7 +166,7 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
writeV = dep.VendorAlways
}

newLock := dep.LockFromInterface(solution)
newLock := cfg.LockFromInterface(solution)
sw, err := dep.NewSafeWriter(nil, p.Lock, newLock, writeV)
if err != nil {
return err
Expand Down Expand Up @@ -208,7 +209,7 @@ func applyEnsureArgs(args []string, overrides stringSlice, p *dep.Project, sm *g
// TODO(sdboyer): for this case - or just in general - do we want to
// add project args to the requires list temporarily for this run?
if _, has := p.Manifest.Dependencies[pc.Ident.ProjectRoot]; !has {
internal.Logf("No constraint or alternate source specified for %q, omitting from manifest", pc.Ident.ProjectRoot)
util.Logf("No constraint or alternate source specified for %q, omitting from manifest", pc.Ident.ProjectRoot)
}
// If it's already in the manifest, no need to log
continue
Expand Down
2 changes: 1 addition & 1 deletion cmd/dep/graphviz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package main
import (
"testing"

"github.com/golang/dep/test"
"github.com/golang/dep/internal/test"
)

func TestEmptyProject(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/dep/hash_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"flag"
"fmt"

"github.com/golang/dep"
"github.com/golang/dep/gps"
"github.com/golang/dep/gps/pkgtree"
"github.com/golang/dep/internal/dep"
"github.com/pkg/errors"
)

Expand Down
39 changes: 20 additions & 19 deletions cmd/dep/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
"path/filepath"
"strings"

"github.com/golang/dep"
"github.com/golang/dep/gps"
"github.com/golang/dep/gps/pkgtree"
"github.com/golang/dep/internal"
"github.com/golang/dep/internal/cfg"
"github.com/golang/dep/internal/dep"
"github.com/golang/dep/internal/util"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -53,7 +54,7 @@ type initCommand struct {
}

func trimPathPrefix(p1, p2 string) string {
if internal.HasFilepathPrefix(p1, p2) {
if util.HasFilepathPrefix(p1, p2) {
return p1[len(p2):]
}
return p1
Expand All @@ -75,10 +76,10 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
root = args[0]
}

mf := filepath.Join(root, dep.ManifestName)
lf := filepath.Join(root, dep.LockName)
mf := filepath.Join(root, cfg.ManifestName)
lf := filepath.Join(root, cfg.LockName)

mok, err := dep.IsRegular(mf)
mok, err := util.IsRegular(mf)
if err != nil {
return err
}
Expand All @@ -87,7 +88,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
}
// Manifest file does not exist.

lok, err := dep.IsRegular(lf)
lok, err := util.IsRegular(lf)
if err != nil {
return err
}
Expand All @@ -99,12 +100,12 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
if err != nil {
return errors.Wrap(err, "determineProjectRoot")
}
internal.Vlogf("Finding dependencies for %q...", cpr)
util.Vlogf("Finding dependencies for %q...", cpr)
pkgT, err := pkgtree.ListPackages(root, cpr)
if err != nil {
return errors.Wrap(err, "gps.ListPackages")
}
internal.Vlogf("Found %d dependencies.", len(pkgT.Packages))
util.Vlogf("Found %d dependencies.", len(pkgT.Packages))
sm, err := ctx.SourceManager()
if err != nil {
return errors.Wrap(err, "getSourceManager")
Expand All @@ -116,13 +117,13 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
if err != nil {
return err
}
m := &dep.Manifest{
m := &cfg.Manifest{
Dependencies: pd.constraints,
}

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

Expand All @@ -145,7 +146,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
}

// Run solver with project versions found on disk
internal.Vlogf("Solving...")
util.Vlogf("Solving...")
params := gps.SolveParameters{
RootDir: root,
RootPackageTree: pkgT,
Expand All @@ -168,7 +169,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
handleAllTheFailuresOfTheWorld(err)
return err
}
l = dep.LockFromInterface(soln)
l = cfg.LockFromInterface(soln)

// Pick notondisk project constraints from solution and add to manifest
for k, _ := range pd.notondisk {
Expand All @@ -189,7 +190,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {

l.Memo = s.HashInputs()

internal.Vlogf("Writing manifest and lock files.")
util.Vlogf("Writing manifest and lock files.")

sw, err := dep.NewSafeWriter(m, nil, l, dep.VendorAlways)
if err != nil {
Expand Down Expand Up @@ -294,7 +295,7 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps.
return projectData{}, nil
}

internal.Vlogf("Building dependency graph...")
util.Vlogf("Building dependency graph...")
// Exclude stdlib imports from the list returned from Flatten().
const omitStdlib = false
for _, ip := range rm.Flatten(omitStdlib) {
Expand All @@ -310,21 +311,21 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps.
}
go syncDep(pr, sm)

internal.Vlogf("Found import of %q, analyzing...", ip)
util.Vlogf("Found import of %q, analyzing...", ip)

dependencies[pr] = []string{ip}
v, err := ctx.VersionInWorkspace(pr)
if err != nil {
notondisk[pr] = true
internal.Vlogf("Could not determine version for %q, omitting from generated manifest", pr)
util.Vlogf("Could not determine version for %q, omitting from generated manifest", pr)
continue
}

ondisk[pr] = v
constraints[pr] = getProjectPropertiesFromVersion(v)
}

internal.Vlogf("Analyzing transitive imports...")
util.Vlogf("Analyzing transitive imports...")
// Explore the packages we've found for transitive deps, either
// completing the lock or identifying (more) missing projects that we'll
// need to ask gps to solve for us.
Expand All @@ -343,7 +344,7 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps.
dft = func(pkg string) error {
switch colors[pkg] {
case white:
internal.Vlogf("Analyzing %q...", pkg)
util.Vlogf("Analyzing %q...", pkg)
colors[pkg] = grey

pr, err := sm.DeduceProjectRoot(pkg)
Expand Down
8 changes: 4 additions & 4 deletions cmd/dep/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"strings"
"testing"

"github.com/golang/dep"
"github.com/golang/dep/test"
"github.com/golang/dep/internal/cfg"
"github.com/golang/dep/internal/test"
)

func TestIntegration(t *testing.T) {
Expand Down Expand Up @@ -68,8 +68,8 @@ func TestIntegration(t *testing.T) {
testCase.CompareError(err, testProj.GetStderr())

// Check final manifest and lock
testCase.CompareFile(dep.ManifestName, testProj.ProjPath(dep.ManifestName))
testCase.CompareFile(dep.LockName, testProj.ProjPath(dep.LockName))
testCase.CompareFile(cfg.ManifestName, testProj.ProjPath(cfg.ManifestName))
testCase.CompareFile(cfg.LockName, testProj.ProjPath(cfg.LockName))

// Check vendor paths
testProj.CompareImportPaths()
Expand Down
42 changes: 21 additions & 21 deletions cmd/dep/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"strings"
"text/tabwriter"

"github.com/golang/dep"
"github.com/golang/dep/internal"
"github.com/golang/dep/internal/dep"
"github.com/golang/dep/internal/util"
)

var (
Expand Down Expand Up @@ -62,27 +62,27 @@ func main() {
}

usage := func() {
internal.Logln("dep is a tool for managing dependencies for Go projects")
internal.Logln()
internal.Logln("Usage: dep <command>")
internal.Logln()
internal.Logln("Commands:")
internal.Logln()
util.Logln("dep is a tool for managing dependencies for Go projects")
util.Logln()
util.Logln("Usage: dep <command>")
util.Logln()
util.Logln("Commands:")
util.Logln()
w := tabwriter.NewWriter(os.Stderr, 0, 4, 2, ' ', 0)
for _, cmd := range commands {
if !cmd.Hidden() {
fmt.Fprintf(w, "\t%s\t%s\n", cmd.Name(), cmd.ShortHelp())
}
}
w.Flush()
internal.Logln()
internal.Logln("Examples:")
util.Logln()
util.Logln("Examples:")
for _, example := range examples {
fmt.Fprintf(w, "\t%s\t%s\n", example[0], example[1])
}
w.Flush()
internal.Logln()
internal.Logln("Use \"dep help [command]\" for more information about a command.")
util.Logln()
util.Logln("Use \"dep help [command]\" for more information about a command.")
}

cmdName, printCommandHelp, exit := parseArgs(os.Args)
Expand Down Expand Up @@ -115,12 +115,12 @@ func main() {
os.Exit(1)
}

internal.Verbose = *verbose
util.Verbose = *verbose

// Set up the dep context.
ctx, err := dep.NewContext()
if err != nil {
internal.Logln(err)
util.Logln(err)
os.Exit(1)
}

Expand All @@ -135,7 +135,7 @@ func main() {
}
}

internal.Logf("%s: no such command", cmdName)
util.Logf("%s: no such command", cmdName)
usage()
os.Exit(1)
}
Expand All @@ -159,13 +159,13 @@ func resetUsage(fs *flag.FlagSet, name, args, longHelp string) {
flagWriter.Flush()
fs.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: dep %s %s\n", name, args)
internal.Logln()
internal.Logln(strings.TrimSpace(longHelp))
internal.Logln()
util.Logln()
util.Logln(strings.TrimSpace(longHelp))
util.Logln()
if hasFlags {
internal.Logln("Flags:")
internal.Logln()
internal.Logln(flagBlock.String())
util.Logln("Flags:")
util.Logln()
util.Logln(flagBlock.String())
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/dep/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import (
"log"
"os"

"github.com/golang/dep"
"github.com/golang/dep/gps"
"github.com/golang/dep/gps/pkgtree"

"github.com/golang/dep/internal/dep"
"github.com/pkg/errors"
)

Expand Down
11 changes: 6 additions & 5 deletions cmd/dep/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"os"
"strings"

"github.com/golang/dep"
"github.com/golang/dep/gps"
"github.com/golang/dep/gps/pkgtree"
"github.com/golang/dep/internal"
"github.com/golang/dep/internal/cfg"
"github.com/golang/dep/internal/dep"
"github.com/golang/dep/internal/util"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -92,7 +93,7 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error {
// not being able to detect the root for an import path that's
// actually in the import list is a deeper problem. However,
// it's not our direct concern here, so we just warn.
internal.Logf("could not infer root for %q", pr)
util.Logf("could not infer root for %q", pr)
continue
}
otherroots[pr] = true
Expand All @@ -107,7 +108,7 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error {
}

if len(rm) == 0 {
internal.Logf("nothing to do")
util.Logf("nothing to do")
return nil
}
} else {
Expand Down Expand Up @@ -180,7 +181,7 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error {
return err
}

newLock := dep.LockFromInterface(soln)
newLock := cfg.LockFromInterface(soln)

sw, err := dep.NewSafeWriter(nil, p.Lock, newLock, dep.VendorOnChanged)
if err != nil {
Expand Down
Loading