本文整理汇总了Golang中github.com/constabulary/gb.GcToolchain函数的典型用法代码示例。如果您正苦于以下问题:Golang GcToolchain函数的具体用法?Golang GcToolchain怎么用?Golang GcToolchain使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GcToolchain函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
if projectroot == "" {
return fmt.Errorf("project root is blank")
}
root, err := FindProjectroot(projectroot)
if err != nil {
return fmt.Errorf("could not locate project root: %v", err)
}
project := gb.NewProject(root)
gb.Debugf("project root %q", project.Projectdir())
ctx, err := project.NewContext(
gb.GcToolchain(),
)
if err != nil {
return fmt.Errorf("unable to construct context: %v", err)
}
gb.Debugf("args: %v", args)
return cmd.Run(ctx, args)
}
开发者ID:acasajus,项目名称:gb,代码行数:32,代码来源:cmd.go
示例2: main
func main() {
args := os.Args[1:]
switch {
case len(args) < 1, args[0] == "-h", args[0] == "-help":
fs.Usage()
os.Exit(1)
case args[0] == "help":
help(args[1:])
return
case projectroot == "":
log.Fatalf("don't run this binary directly, it is meant to be run as 'gb vendor ...'")
default:
}
root, err := cmd.FindProjectroot(projectroot)
if err != nil {
log.Fatalf("could not locate project root: %v", err)
}
project := gb.NewProject(root,
gb.SourceDir(filepath.Join(root, "src")),
gb.SourceDir(filepath.Join(root, "vendor", "src")))
log.Debugf("project root %q", project.Projectdir())
for _, command := range commands {
if command.Name == args[0] && command.Runnable() {
// add extra flags if necessary
if command.AddFlags != nil {
command.AddFlags(fs)
}
if command.FlagParse != nil {
err = command.FlagParse(fs, args)
} else {
err = fs.Parse(args[1:])
}
if err != nil {
log.Fatalf("could not parse flags: %v", err)
}
args = fs.Args() // reset args to the leftovers from fs.Parse
log.Debugf("args: %v", args)
ctx, err := project.NewContext(
gb.GcToolchain(),
)
if err != nil {
log.Fatalf("unable to construct context: %v", err)
}
defer ctx.Destroy()
if err := command.Run(ctx, args); err != nil {
log.Fatalf("command %q failed: %v", command.Name, err)
}
return
}
}
log.Fatalf("unknown command %q ", args[0])
}
开发者ID:upworthy,项目名称:oauth2-proxy-buildpack,代码行数:59,代码来源:main.go
示例3: testContext
func testContext(t *testing.T, opts ...func(*gb.Context) error) *gb.Context {
prj := testProject(t)
opts = append([]func(*gb.Context) error{gb.GcToolchain()}, opts...)
ctx, err := prj.NewContext(opts...)
if err != nil {
t.Fatal(err)
}
ctx.Force = true
return ctx
}
开发者ID:torfuzx,项目名称:gb,代码行数:10,代码来源:test_test.go
示例4: main
func main() {
root, err := cmd.FindProjectroot(projectroot)
if err != nil {
gb.Fatalf("could not locate project root: %v", err)
}
project := gb.NewProject(root)
gb.Debugf("project root %q", project.Projectdir())
args := os.Args[1:]
if len(args) < 1 || args[0] == "-h" {
fs.Usage()
os.Exit(1)
}
if args[0] == "help" {
help(args[1:])
return
}
for _, command := range commands {
if command.Name == args[0] && command.Runnable() {
// add extra flags if necessary
if command.AddFlags != nil {
command.AddFlags(fs)
}
if command.FlagParse != nil {
err = command.FlagParse(fs, args)
} else {
err = fs.Parse(args[1:])
}
if err != nil {
gb.Fatalf("could not parse flags: %v", err)
}
args = fs.Args() // reset args to the leftovers from fs.Parse
gb.Debugf("args: %v", args)
ctx, err := project.NewContext(
gb.GcToolchain(),
)
if err != nil {
gb.Fatalf("unable to construct context: %v", err)
}
if err := command.Run(ctx, args); err != nil {
gb.Fatalf("command %q failed: %v", command.Name, err)
}
return
}
}
gb.Fatalf("unknown command %q ", args[0])
}
开发者ID:agonzalezro,项目名称:gb,代码行数:53,代码来源:main.go
示例5: 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)
}
gb.Debugf("args: %v", args)
return cmd.Run(ctx, args)
}
开发者ID:Luit,项目名称:gb,代码行数:19,代码来源:cmd.go
示例6: main
func main() {
fatalf := func(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "FATAL: "+format+"\n", args...)
os.Exit(1)
}
args := os.Args
if len(args) < 2 || args[1] == "-h" {
fs.Usage()
os.Exit(1)
}
name := args[1]
if name == "help" {
help(args[2:])
return
}
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()
os.Exit(1)
}
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
ParseArgs: func(_ *gb.Context, _ string, args []string) []string { return args },
}
}
// 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
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...),
)
if err != nil {
fatalf("unable to construct context: %v", err)
}
if !noDestroyContext {
defer ctx.Destroy()
}
if command.ParseArgs != nil {
args = command.ParseArgs(ctx, ctx.Projectdir(), args)
} else {
args = cmd.ImportPaths(ctx, cwd, args)
}
debug.Debugf("args: %v", args)
if err := command.Run(ctx, args); err != nil {
if !noDestroyContext {
ctx.Destroy()
}
//.........这里部分代码省略.........
开发者ID:kalafut,项目名称:gb,代码行数:101,代码来源:main.go
示例7: 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)
},
//.........这里部分代码省略.........
开发者ID:torfuzx,项目名称:gb,代码行数:101,代码来源:main.go
示例8: main
func main() {
args := os.Args
if len(args) < 2 || args[1] == "-h" {
fs.Usage()
os.Exit(1)
}
name := args[1]
if name == "help" {
help(args[2:])
return
}
command, ok := commands[name]
if (command != nil && !command.Runnable()) || !ok {
if _, err := lookupPlugin(name); err != nil {
gb.Errorf("unknown command %q", name)
fs.Usage()
os.Exit(1)
}
command = commands["plugin"]
}
// 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 {
gb.Fatalf("could not parse flags: %v", err)
}
args = fs.Args() // reset args to the leftovers from fs.Parse
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 {
gb.Fatalf("could not make project root absolute: %v", err)
}
ctx, err := cmd.NewContext(
cwd, // project root
gb.GcToolchain(),
gb.Gcflags(gcflags),
gb.Ldflags(ldflags),
)
if err != nil {
gb.Fatalf("unable to construct context: %v", err)
}
if !noDestroyContext {
defer ctx.Destroy()
}
if command.ParseArgs != nil {
args = command.ParseArgs(ctx, ctx.Projectdir(), args)
} else {
args = cmd.ImportPaths(ctx, cwd, args)
}
gb.Debugf("args: %v", args)
if err := command.Run(ctx, args); err != nil {
gb.Fatalf("command %q failed: %v", name, err)
}
}
开发者ID:Luit,项目名称:gb,代码行数:70,代码来源:main.go
注:本文中的github.com/constabulary/gb.GcToolchain函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论