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

Commit

Permalink
Merge pull request #459 from carolynvs/internal-logging
Browse files Browse the repository at this point in the history
Move logging functions into internal package
  • Loading branch information
sdboyer authored Apr 25, 2017
2 parents e025682 + 5361a50 commit 9e4c058
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 25 deletions.
3 changes: 2 additions & 1 deletion cmd/dep/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"strings"

"github.com/golang/dep"
"github.com/golang/dep/internal"
"github.com/pkg/errors"
"github.com/sdboyer/gps"
"github.com/sdboyer/gps/pkgtree"
Expand Down Expand Up @@ -205,7 +206,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 {
logf("No constraint or alternate source specified for %q, omitting from manifest", pc.Ident.ProjectRoot)
internal.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
19 changes: 10 additions & 9 deletions cmd/dep/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"

"github.com/golang/dep"
"github.com/golang/dep/internal"
"github.com/pkg/errors"
"github.com/sdboyer/gps"
"github.com/sdboyer/gps/pkgtree"
Expand Down Expand Up @@ -89,12 +90,12 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
if err != nil {
return errors.Wrap(err, "determineProjectRoot")
}
vlogf("Finding dependencies for %q...", cpr)
internal.Vlogf("Finding dependencies for %q...", cpr)
pkgT, err := pkgtree.ListPackages(root, cpr)
if err != nil {
return errors.Wrap(err, "gps.ListPackages")
}
vlogf("Found %d dependencies.", len(pkgT.Packages))
internal.Vlogf("Found %d dependencies.", len(pkgT.Packages))
sm, err := ctx.SourceManager()
if err != nil {
return errors.Wrap(err, "getSourceManager")
Expand Down Expand Up @@ -135,7 +136,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
}

if len(pd.notondisk) > 0 {
vlogf("Solving...")
internal.Vlogf("Solving...")
params := gps.SolveParameters{
RootDir: root,
RootPackageTree: pkgT,
Expand All @@ -161,7 +162,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
l = dep.LockFromInterface(soln)
}

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

var sw dep.SafeWriter
sw.Prepare(m, nil, l, dep.VendorAlways)
Expand Down Expand Up @@ -236,7 +237,7 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps.
return projectData{}, nil
}

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

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

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

Expand All @@ -275,7 +276,7 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps.
constraints[pr] = pp
}

vlogf("Analyzing transitive imports...")
internal.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 @@ -294,7 +295,7 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps.
dft = func(pkg string) error {
switch colors[pkg] {
case white:
vlogf("Analyzing %q...", pkg)
internal.Vlogf("Analyzing %q...", pkg)
colors[pkg] = grey

pr, err := sm.DeduceProjectRoot(pkg)
Expand Down
17 changes: 4 additions & 13 deletions cmd/dep/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"text/tabwriter"

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

var (
Expand Down Expand Up @@ -114,6 +115,8 @@ func main() {
os.Exit(1)
}

internal.Verbose = *verbose

// Set up the dep context.
ctx, err := dep.NewContext()
if err != nil {
Expand Down Expand Up @@ -167,7 +170,7 @@ func resetUsage(fs *flag.FlagSet, name, args, longHelp string) {
}
}

// parseArgs determines the name of the dep command and wether the user asked for
// parseArgs determines the name of the dep command and whether the user asked for
// help to be printed.
func parseArgs(args []string) (cmdName string, printCmdUsage bool, exit bool) {
isHelpArg := func() bool {
Expand All @@ -192,15 +195,3 @@ func parseArgs(args []string) (cmdName string, printCmdUsage bool, exit bool) {
}
return cmdName, printCmdUsage, exit
}

func logf(format string, args ...interface{}) {
// TODO: something else?
fmt.Fprintf(os.Stderr, "dep: "+format+"\n", args...)
}

func vlogf(format string, args ...interface{}) {
if !*verbose {
return
}
logf(format, args...)
}
5 changes: 3 additions & 2 deletions cmd/dep/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/golang/dep"
"github.com/golang/dep/internal"
"github.com/pkg/errors"
"github.com/sdboyer/gps"
"github.com/sdboyer/gps/pkgtree"
Expand Down Expand Up @@ -91,7 +92,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.
logf("could not infer root for %q", pr)
internal.Logf("could not infer root for %q", pr)
continue
}
otherroots[pr] = true
Expand All @@ -106,7 +107,7 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error {
}

if len(rm) == 0 {
logf("nothing to do")
internal.Logf("nothing to do")
return nil
}
} else {
Expand Down
25 changes: 25 additions & 0 deletions internal/internal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package internal

import (
"fmt"
"os"
)

// Verbose specifies if verbose logging is enabled.
var Verbose bool

func Logf(format string, args ...interface{}) {
// TODO: something else?
fmt.Fprintf(os.Stderr, "dep: "+format+"\n", args...)
}

func Vlogf(format string, args ...interface{}) {
if !Verbose {
return
}
Logf(format, args...)
}

0 comments on commit 9e4c058

Please sign in to comment.