本文整理汇总了Golang中github.com/constabulary/gb/debug.Debugf函数的典型用法代码示例。如果您正苦于以下问题:Golang Debugf函数的具体用法?Golang Debugf怎么用?Golang Debugf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debugf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestFlags
// TestFlags appends "-test." for flags that are passed to the test binary.
func TestFlags(testArgs []string) []string {
debug.Debugf("TestFlags: args: %s", testArgs)
var targs []string
for _, arg := range testArgs {
var nArg, nVal, fArg string
fArg = arg
if !strings.Contains(arg, "-test.") {
nArg = strings.TrimPrefix(arg, "-")
if strings.Contains(nArg, "=") {
nArgVal := strings.Split(nArg, "=")
nArg, nVal = nArgVal[0], nArgVal[1]
}
if val, ok := testFlagDefn[nArg]; ok {
// Special handling for -q, needs to be -test.v when passed to the test
if nArg == "q" {
nArg = "v"
}
if val.passToTest || val.passToAll {
fArg = "-test." + nArg
if nVal != "" {
fArg = fArg + "=" + nVal
}
}
}
}
targs = append(targs, fArg)
}
debug.Debugf("testFlags: targs: %s", targs)
return targs
}
示例2: importPathsNoDotExpansion
// importPathsNoDotExpansion returns the import paths to use for the given
// command line, but it does no ... expansion.
func importPathsNoDotExpansion(ctx Context, cwd string, args []string) []string {
srcdir, _ := filepath.Rel(filepath.Join(ctx.Projectdir(), "src"), cwd)
debug.Debugf("%s %s", cwd, srcdir)
if srcdir == ".." {
srcdir = "."
}
if len(args) == 0 {
args = []string{"..."}
}
var out []string
for _, a := range args {
// Arguments are supposed to be import paths, but
// as a courtesy to Windows developers, rewrite \ to /
// in command-line arguments. Handles .\... and so on.
if filepath.Separator == '\\' {
a = strings.Replace(a, `\`, `/`, -1)
}
if a == "all" || a == "std" {
pkgs, err := ctx.AllPackages(a)
if err != nil {
fatalf("could not load all packages: %v", err)
}
out = append(out, pkgs...)
continue
}
a = path.Join(srcdir, path.Clean(a))
out = append(out, a)
}
return out
}
示例3: runOut
func runOut(output io.Writer, dir string, env []string, command string, args ...string) error {
cmd := exec.Command(command, args...)
cmd.Dir = dir
cmd.Stdout = output
cmd.Stderr = os.Stderr
cmd.Env = mergeEnvLists(env, envForDir(cmd.Dir))
debug.Debugf("cd %s; %s", cmd.Dir, cmd.Args)
err := cmd.Run()
return err
}
示例4: BuildPackages
// BuildPackages produces a tree of *Actions that can be executed to build
// a *Package.
// BuildPackages walks the tree of *Packages and returns a corresponding
// tree of *Actions representing the steps required to build *Package
// and any of its dependencies
func BuildPackages(pkgs ...*Package) (*Action, error) {
if len(pkgs) < 1 {
return nil, fmt.Errorf("no packages supplied")
}
targets := make(map[string]*Action) // maps package importpath to build action
names := func(pkgs []*Package) []string {
var names []string
for _, pkg := range pkgs {
names = append(names, pkg.ImportPath)
}
return names
}
// create top level build action to unify all packages
t0 := time.Now()
build := Action{
Name: fmt.Sprintf("build: %s", strings.Join(names(pkgs), ",")),
Run: func() error {
debug.Debugf("build duration: %v %v", time.Since(t0), pkgs[0].Statistics.String())
return nil
},
}
for _, pkg := range pkgs {
if len(pkg.GoFiles)+len(pkg.CgoFiles) == 0 {
debug.Debugf("skipping %v: no go files", pkg.ImportPath)
continue
}
a, err := BuildPackage(targets, pkg)
if err != nil {
return nil, err
}
if a == nil {
// nothing to do
continue
}
build.Deps = append(build.Deps, a)
}
return &build, nil
}
示例5: matchPackages
func matchPackages(c *Context, pattern string) []string {
debug.Debugf("matchPackages: %v %v", c.srcdirs[0].Root, pattern)
match := func(string) bool { return true }
treeCanMatch := func(string) bool { return true }
if pattern != "all" && pattern != "std" {
match = matchPattern(pattern)
treeCanMatch = treeCanMatchPattern(pattern)
}
var pkgs []string
for _, dir := range c.srcdirs[:1] {
src := filepath.Clean(dir.Root) + string(filepath.Separator)
filepath.Walk(src, func(path string, fi os.FileInfo, err error) error {
if err != nil || !fi.IsDir() || path == src {
return nil
}
// Avoid .foo, _foo, and testdata directory trees.
_, elem := filepath.Split(path)
if strings.HasPrefix(elem, ".") || strings.HasPrefix(elem, "_") || elem == "testdata" {
return filepath.SkipDir
}
name := filepath.ToSlash(path[len(src):])
if pattern == "std" && strings.Contains(name, ".") {
return filepath.SkipDir
}
if !treeCanMatch(name) {
return filepath.SkipDir
}
if !match(name) {
return nil
}
_, err = c.ResolvePackage(name)
switch err.(type) {
case nil:
pkgs = append(pkgs, name)
return nil
case *importer.NoGoError:
return nil // skip
default:
return err
}
})
}
return pkgs
}
示例6: NewContext
// NewContext creates a gb.Context for the project root.
func NewContext(projectroot string, options ...func(*gb.Context) error) (*gb.Context, error) {
if projectroot == "" {
return nil, fmt.Errorf("project root is blank")
}
root, err := FindProjectroot(projectroot)
if err != nil {
return nil, fmt.Errorf("could not locate project root: %v", err)
}
project := gb.NewProject(root,
gb.SourceDir(filepath.Join(root, "src")),
gb.SourceDir(filepath.Join(root, "vendor", "src")),
)
debug.Debugf("project root %q", project.Projectdir())
return project.NewContext(options...)
}
示例7: loadTestFuncs
// loadTestFuncs returns the testFuncs describing the tests that will be run.
func loadTestFuncs(ptest *importer.Package) (*testFuncs, error) {
t := &testFuncs{
Package: ptest,
}
debug.Debugf("loadTestFuncs: %v, %v", ptest.TestGoFiles, ptest.XTestGoFiles)
for _, file := range ptest.TestGoFiles {
if err := t.load(filepath.Join(ptest.Dir, file), "_test", &t.ImportTest, &t.NeedTest); err != nil {
return nil, err
}
}
for _, file := range ptest.XTestGoFiles {
if err := t.load(filepath.Join(ptest.Dir, file), "_xtest", &t.ImportXtest, &t.NeedXtest); err != nil {
return nil, err
}
}
return t, nil
}
示例8: matchPackages
func matchPackages(c *Context, pattern string) ([]string, error) {
debug.Debugf("matchPackages: %v", pattern)
match := func(string) bool { return true }
treeCanMatch := func(string) bool { return true }
if pattern != "all" && pattern != "std" {
match = matchPattern(pattern)
treeCanMatch = treeCanMatchPattern(pattern)
}
var pkgs []string
src := filepath.Join(c.Projectdir(), "src") + string(filepath.Separator)
err := filepath.Walk(src, func(path string, fi os.FileInfo, err error) error {
if err != nil || !fi.IsDir() || path == src {
return nil
}
// Avoid .foo, _foo, and testdata directory trees.
elem := fi.Name()
if strings.HasPrefix(elem, ".") || strings.HasPrefix(elem, "_") || elem == "testdata" {
return filepath.SkipDir
}
name := filepath.ToSlash(path[len(src):])
if pattern == "std" && strings.Contains(name, ".") {
return filepath.SkipDir
}
if !treeCanMatch(name) {
return filepath.SkipDir
}
if !match(name) {
return nil
}
_, err = c.importers[1].Import(name)
switch err.(type) {
case nil:
pkgs = append(pkgs, name)
return nil
case *importer.NoGoError:
return nil // skip
default:
return err
}
})
return pkgs, err
}
示例9: RunCommand
// RunCommand detects the project root, parses flags and runs the Command.
func RunCommand(fs *flag.FlagSet, cmd *Command, projectroot, goroot string, args []string) error {
if cmd.AddFlags != nil {
cmd.AddFlags(fs)
}
if err := fs.Parse(args); err != nil {
fs.Usage()
os.Exit(1)
}
args = fs.Args() // reset to the remaining arguments
ctx, err := NewContext(projectroot, gb.GcToolchain())
if err != nil {
return fmt.Errorf("unable to construct context: %v", err)
}
defer ctx.Destroy()
debug.Debugf("args: %v", args)
return cmd.Run(ctx, args)
}
示例10: copyfile
func copyfile(dst, src string) error {
err := mkdir(filepath.Dir(dst))
if err != nil {
return fmt.Errorf("copyfile: mkdirall: %v", err)
}
r, err := os.Open(src)
if err != nil {
return fmt.Errorf("copyfile: open(%q): %v", src, err)
}
defer r.Close()
w, err := os.Create(dst)
if err != nil {
return fmt.Errorf("copyfile: create(%q): %v", dst, err)
}
defer w.Close()
debug.Debugf("copyfile(dst: %v, src: %v)", dst, src)
_, err = io.Copy(w, r)
return err
}
示例11: TestPackages
// TestPackages produces a graph of Actions that when executed build
// and test the supplied packages.
func TestPackages(flags []string, pkgs ...*gb.Package) (*gb.Action, error) {
if len(pkgs) < 1 {
return nil, fmt.Errorf("no test packages provided")
}
targets := make(map[string]*gb.Action) // maps package import paths to their test run action
names := func(pkgs []*gb.Package) []string {
var names []string
for _, pkg := range pkgs {
names = append(names, pkg.ImportPath)
}
return names
}
// create top level test action to root all test actions
t0 := time.Now()
test := gb.Action{
Name: fmt.Sprintf("test: %s", strings.Join(names(pkgs), ",")),
Run: func() error {
debug.Debugf("test duration: %v %v", time.Since(t0), pkgs[0].Statistics.String())
return nil
},
}
for _, pkg := range pkgs {
a, err := TestPackage(targets, pkg, flags)
if err != nil {
return nil, err
}
if a == nil {
// nothing to do ?? not even a test action ?
continue
}
test.Deps = append(test.Deps, a)
}
return &test, nil
}
示例12: Destroy
// Destroy removes the temporary working files of this context.
func (c *Context) Destroy() error {
debug.Debugf("removing work directory: %v", c.workdir)
return os.RemoveAll(c.workdir)
}
示例13: main
func main() {
args := os.Args
if len(args) < 2 || args[1] == "-h" {
fs.Usage() // usage calles exit(2)
}
name := args[1]
if name == "help" {
help(args[2:])
exit(0)
}
command, ok := commands[name]
if (command != nil && !command.Runnable()) || !ok {
plugin, err := lookupPlugin(name)
if err != nil {
fmt.Fprintf(os.Stderr, "FATAL: unknown command %q\n", name)
fs.Usage() // usage calles exit(2)
}
command = &cmd.Command{
Run: func(ctx *gb.Context, args []string) error {
args = append([]string{plugin}, args...)
env := cmd.MergeEnv(os.Environ(), map[string]string{
"GB_PROJECT_DIR": ctx.Projectdir(),
})
cmd := exec.Cmd{
Path: plugin,
Args: args,
Env: env,
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
}
return cmd.Run()
},
// plugin should not interpret arguments
SkipParseArgs: true,
}
}
// add extra flags if necessary
if command.AddFlags != nil {
command.AddFlags(fs)
}
var err error
if command.FlagParse != nil {
err = command.FlagParse(fs, args)
} else {
err = fs.Parse(args[2:])
}
if err != nil {
fatalf("could not parse flags: %v", err)
}
args = fs.Args() // reset args to the leftovers from fs.Parse
debug.Debugf("args: %v", args)
if command == commands["plugin"] {
args = append([]string{name}, args...)
}
cwd, err := filepath.Abs(cwd) // if cwd was passed in via -R, make sure it is absolute
if err != nil {
fatalf("could not make project root absolute: %v", err)
}
ctx, err := cmd.NewContext(
cwd, // project root
gb.GcToolchain(),
gb.Gcflags(gcflags...),
gb.Ldflags(ldflags...),
gb.Tags(buildtags...),
func(c *gb.Context) error {
if !race {
return nil
}
// check this is a supported platform
if runtime.GOARCH != "amd64" {
fatalf("race detector not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
switch runtime.GOOS {
case "linux", "windows", "darwin", "freebsd":
// supported
default:
fatalf("race detector not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
// check the race runtime is built
_, err := os.Stat(filepath.Join(runtime.GOROOT(), "pkg", fmt.Sprintf("%s_%s_race", runtime.GOOS, runtime.GOARCH), "runtime.a"))
if os.IsNotExist(err) || err != nil {
fatalf("go installation at %s is missing race support. See https://getgb.io/faq/#missing-race-support", runtime.GOROOT())
}
return gb.WithRace(c)
},
//.........这里部分代码省略.........
示例14:
if err != nil {
return err
}
if dotfile != "" {
f, err := os.Create(dotfile)
if err != nil {
return err
}
defer f.Close()
printActions(f, test)
}
startSigHandlers()
return gb.ExecuteConcurrent(test, P, interrupted)
},
AddFlags: addTestFlags,
FlagParse: func(flags *flag.FlagSet, args []string) error {
var err error
debug.Debugf("%s", args)
args, tfs, err = TestFlagsExtraParse(args[2:])
debug.Debugf("%s %s", args, tfs)
if err != nil {
fmt.Fprintf(os.Stderr, "gb test: %s\n", err)
fmt.Fprintf(os.Stderr, `run "go help test" or "go help testflag" for more information`+"\n")
exit(2)
}
return flags.Parse(args)
},
}
示例15: TestPackage
// TestPackage returns an Action representing the steps required to build
// and test this Package.
func TestPackage(targets map[string]*gb.Action, pkg *gb.Package, flags []string) (*gb.Action, error) {
debug.Debugf("TestPackage: %s, flags: %s", pkg.ImportPath, flags)
var gofiles []string
gofiles = append(gofiles, pkg.GoFiles...)
gofiles = append(gofiles, pkg.TestGoFiles...)
var cgofiles []string
cgofiles = append(cgofiles, pkg.CgoFiles...)
var imports []string
imports = append(imports, pkg.Package.Imports...)
imports = append(imports, pkg.Package.TestImports...)
name := pkg.Name
if name == "main" {
// rename the main package to its package name for testing.
name = filepath.Base(filepath.FromSlash(pkg.ImportPath))
}
// internal tests
testpkg := gb.NewPackage(pkg.Context, &importer.Package{
Name: name,
ImportPath: pkg.ImportPath,
Dir: pkg.Dir,
SrcRoot: pkg.SrcRoot,
GoFiles: gofiles,
CFiles: pkg.CFiles,
CgoFiles: cgofiles,
TestGoFiles: pkg.TestGoFiles, // passed directly to buildTestMain
XTestGoFiles: pkg.XTestGoFiles, // passed directly to buildTestMain
CgoCFLAGS: pkg.CgoCFLAGS,
CgoCPPFLAGS: pkg.CgoCPPFLAGS,
CgoCXXFLAGS: pkg.CgoCXXFLAGS,
CgoLDFLAGS: pkg.CgoLDFLAGS,
CgoPkgConfig: pkg.CgoPkgConfig,
Imports: imports,
})
testpkg.TestScope = true
testpkg.Stale = true
// only build the internal test if there is Go source or
// internal test files.
var testobj *gb.Action
if len(testpkg.GoFiles)+len(testpkg.CgoFiles)+len(testpkg.TestGoFiles) > 0 {
// build internal testpkg dependencies
deps, err := gb.BuildDependencies(targets, testpkg)
if err != nil {
return nil, err
}
testobj, err = gb.Compile(testpkg, deps...)
if err != nil {
return nil, err
}
}
// external tests
if len(pkg.XTestGoFiles) > 0 {
xtestpkg := gb.NewPackage(pkg.Context, &importer.Package{
Name: name,
ImportPath: pkg.ImportPath + "_test",
Dir: pkg.Dir,
GoFiles: pkg.XTestGoFiles,
Imports: pkg.XTestImports,
})
// build external test dependencies
deps, err := gb.BuildDependencies(targets, xtestpkg)
if err != nil {
return nil, err
}
xtestpkg.TestScope = true
xtestpkg.Stale = true
xtestpkg.ExtraIncludes = filepath.Join(pkg.Workdir(), filepath.FromSlash(pkg.ImportPath), "_test")
// if there is an internal test object, add it as a dependency.
if testobj != nil {
deps = append(deps, testobj)
}
testobj, err = gb.Compile(xtestpkg, deps...)
if err != nil {
return nil, err
}
}
testmainpkg, err := buildTestMain(testpkg)
if err != nil {
return nil, err
}
testmain, err := gb.Compile(testmainpkg, testobj)
if err != nil {
return nil, err
}
return &gb.Action{
//.........这里部分代码省略.........