本文整理汇总了Golang中github.com/mailgun/godebug/Godeps/_workspace/src/golang.org/x/tools/go/loader.Config.SourceImports方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.SourceImports方法的具体用法?Golang Config.SourceImports怎么用?Golang Config.SourceImports使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/mailgun/godebug/Godeps/_workspace/src/golang.org/x/tools/go/loader.Config
的用法示例。
在下文中一共展示了Config.SourceImports方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: doOutput
func doOutput(args []string) {
exitIfErr(outputFlags.Parse(args))
var conf loader.Config
rest, err := conf.FromArgs(outputFlags.Args(), true)
if len(rest) > 0 {
fmt.Fprintf(os.Stderr, "Unrecognized arguments:\n%v\n\n", strings.Join(rest, "\n"))
}
if err != nil {
fmt.Fprintf(os.Stderr, "Error identifying packages: %v\n\n", err)
}
if len(rest) > 0 || err != nil {
usage()
}
conf.SourceImports = true
prog, err := conf.Load()
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading packages: %v\n\n", err)
usage()
}
gen.Generate(prog, ioutil.ReadFile, func(importPath, filename string) io.WriteCloser {
if *w {
return createFileHook(filename, "")
}
return nopCloser{os.Stdout}
})
}
示例2: generateSourceFiles
func generateSourceFiles(conf *loader.Config, subcommand string) (tmpDirPath string) {
// Make a temp directory.
tmpDir := makeTmpDir()
if *work {
// Print the name of the directory and don't clean it up on exit.
fmt.Println(tmpDir)
} else {
// Clean up the directory on exit.
atexit.Run(func() {
removeDir(tmpDir)
})
}
// Load the whole program from source files. This almost certainly causes more work than we need to do,
// but it's an easy fix for a few problems I've encountered. Deleting this may be a good target for
// future optimization work.
conf.SourceImports = true
// Mark the extra packages we want to instrument.
var pkgs []string
*instrument = strings.Trim(*instrument, ", ")
if *instrument != "" {
pkgs = strings.Split(*instrument, ",")
}
all := false
for _, pkg := range pkgs {
// check for the special reserved package names: "main", "all", and "std"
// see 'go help packages'
switch pkg {
case "main":
switch subcommand {
case "run": // The main package is always instrumented anyway. Carry on.
case "test":
logFatal(`godebug test: can't pass reserved name "main" in the -instrument flag.`)
}
case "all":
if !all {
all = true
fmt.Println(`godebug run: heads up: "all" means "all except std". godebug can't step into the standard library yet.` + "\n")
}
case "std":
logFatalf("godebug %s: reserved name \"std\" cannot be passed in the -instrument flag."+
"\ngodebug cannot currently instrument packages in the standard library."+
"\nDo you wish it could? Chime in at https://github.com/mailgun/godebug/issues/12",
subcommand)
default:
for _, path := range gotool.ImportPaths([]string{pkg}) { // wildcard "..." expansion
conf.Import(path)
}
}
}
// Load the program.
prog, err := conf.Load()
exitIfErr(err)
// If we're in "all" mode, mark all but the standard library packages and godebug itself for instrumenting.
stdLib := getStdLibPkgs()
if all {
markAlmostAllPackages(prog, stdLib)
}
// Warn the user if they have breakpoints set in files that we are not instrumenting.
checkForUnusedBreakpoints(subcommand, prog, stdLib)
// Generate debugging-enabled source files.
wd := getwd()
gen.Generate(prog, ioutil.ReadFile, func(importPath, filename string) io.WriteCloser {
if importPath == "main" {
filename = filepath.Join(tmpDir, filepath.Base(filename))
} else {
importPath, _ = findUnderGopath(wd, importPath)
exitIfErr(os.MkdirAll(filepath.Join(tmpDir, "src", importPath), 0770))
filename = filepath.Join(tmpDir, "src", importPath, filepath.Base(filename))
}
return createFileHook(filename, tmpDir)
})
return tmpDir
}