github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/mobile/cmd/gobind/main.go (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "flag" 9 "fmt" 10 "go/importer" 11 "log" 12 "os" 13 "os/exec" 14 "strings" 15 ) 16 17 var ( 18 lang = flag.String("lang", "java", "target language for bindings, either java, go, or objc (experimental).") 19 outdir = flag.String("outdir", "", "result will be written to the directory instead of stdout.") 20 javaPkg = flag.String("javapkg", "", "custom Java package path used instead of the default 'go.<go package name>'. Valid only with -lang=java.") 21 prefix = flag.String("prefix", "", "custom Objective-C name prefix used instead of the default 'Go'. Valid only with -lang=objc.") 22 ) 23 24 var usage = `The Gobind tool generates Java language bindings for Go. 25 26 For usage details, see doc.go.` 27 28 func main() { 29 flag.Parse() 30 31 if *lang != "java" && *javaPkg != "" { 32 log.Fatalf("Invalid option -javapkg for gobind -lang=%s", *lang) 33 } else if *lang != "objc" && *prefix != "" { 34 log.Fatalf("Invalid option -prefix for gobind -lang=%s", *lang) 35 } 36 37 // Make sure the export data for the packages being compiled is up to 38 // date. Also use the go tool to provide good error messages for any 39 // type checking errors in the provided packages. 40 cmd := exec.Command("go", "install") 41 cmd.Stdout = os.Stdout 42 cmd.Stderr = os.Stderr 43 cmd.Args = append(cmd.Args, flag.Args()...) 44 if err := cmd.Run(); err != nil { 45 fmt.Fprintf(os.Stderr, "%s failed: %v", strings.Join(cmd.Args, " "), err) 46 os.Exit(1) 47 } 48 49 for _, arg := range flag.Args() { 50 pkg, err := importer.Default().Import(arg) 51 if err != nil { 52 fmt.Fprintf(os.Stderr, "could not import package %s: %v", arg, err) 53 os.Exit(1) 54 } 55 genPkg(pkg) 56 } 57 os.Exit(exitStatus) 58 } 59 60 var exitStatus = 0 61 62 func errorf(format string, args ...interface{}) { 63 fmt.Fprintf(os.Stderr, format, args...) 64 fmt.Fprintln(os.Stderr) 65 exitStatus = 1 66 }