diff --git a/bind/gen.go b/bind/gen.go index beef4b473..0bc839fd2 100644 --- a/bind/gen.go +++ b/bind/gen.go @@ -43,6 +43,10 @@ const ( modeRetained ) +type Reporter interface { + Message(s string) +} + func (list ErrorList) Error() string { buf := new(bytes.Buffer) for i, err := range list { @@ -85,6 +89,8 @@ type Generator struct { Pkg *types.Package err ErrorList + Reporter Reporter + // fields set by init. pkgName string pkgPrefix string diff --git a/bind/gengo.go b/bind/gengo.go index 82aa4fc0c..18da604b7 100644 --- a/bind/gengo.go +++ b/bind/gengo.go @@ -7,6 +7,7 @@ package bind import ( "bytes" "fmt" + "go/token" "go/types" "strings" ) @@ -189,7 +190,7 @@ func (g *goGen) paramName(params *types.Tuple, pos int) string { func (g *goGen) genFunc(o *types.Func) { if !g.isSigSupported(o.Type()) { - g.Printf("// skipped function %s with unsupported parameter or result types\n", o.Name()) + g.warnf(o.Pos(), "skipped function %s with unsupported parameter or result types", o.Name()) return } g.genFuncSignature(o, "") @@ -205,7 +206,7 @@ func (g *goGen) genStruct(obj *types.TypeName, T *types.Struct) { for _, f := range fields { if t := f.Type(); !g.isSupported(t) { - g.Printf("// skipped field %s.%s with unsupported type: %s\n\n", obj.Name(), f.Name(), t) + g.warnf(f.Pos(), "skipped field %s.%s with unsupported type: %s", obj.Name(), f.Name(), t) continue } g.Printf("//export proxy%s_%s_%s_Set\n", g.pkgPrefix, obj.Name(), f.Name()) @@ -230,7 +231,7 @@ func (g *goGen) genStruct(obj *types.TypeName, T *types.Struct) { for _, m := range methods { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", obj.Name(), m.Name()) continue } g.genFuncSignature(m, obj.Name()) @@ -252,7 +253,7 @@ func (g *goGen) genStruct(obj *types.TypeName, T *types.Struct) { func (g *goGen) genVar(o *types.Var) { if t := o.Type(); !g.isSupported(t) { - g.Printf("// skipped variable %s with unsupported type %s\n\n", o.Name(), t) + g.warnf(o.Pos(), "skipped variable %s with unsupported type %s", o.Name(), t) return } // TODO(hyangah): non-struct pointer types (*int), struct type. @@ -289,7 +290,7 @@ func (g *goGen) genInterface(obj *types.TypeName) { // Define the entry points. for _, m := range summary.callable { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", obj.Name(), m.Name()) continue } g.genFuncSignature(m, obj.Name()) @@ -318,7 +319,7 @@ func (g *goGen) genInterface(obj *types.TypeName) { for _, m := range summary.callable { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or result types\n", obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or result types", obj.Name(), m.Name()) continue } sig := m.Type().(*types.Signature) @@ -591,3 +592,11 @@ func (g *goGen) pkgName(pkg *types.Package) string { g.importMap[pkg] = name return name + "." } + +func (g *goGen) warnf(pos token.Pos, format string, args ...interface{}) { + if g.Reporter != nil { + fpos := g.Fset.Position(pos) + g.Reporter.Message(fmt.Sprintf(fpos.String()+": "+format, args...)) + } + g.Printf("// "+format+"\n\n", args...) +} diff --git a/bind/genjava.go b/bind/genjava.go index e31bebaae..3fb508762 100644 --- a/bind/genjava.go +++ b/bind/genjava.go @@ -7,6 +7,7 @@ package bind import ( "fmt" "go/constant" + "go/token" "go/types" "html" "math" @@ -295,7 +296,7 @@ func (g *JavaGen) genStruct(s structInfo) { cons := g.constructors[s.obj] for _, f := range cons { if !g.isConsSigSupported(f.Type()) { - g.Printf("// skipped constructor %s.%s with unsupported parameter or return types\n\n", n, f.Name()) + g.warnf(f.Pos(), "skipped constructor %s.%s with unsupported parameter or return types", n, f.Name()) continue } g.genConstructor(f, n, jinf != nil) @@ -312,7 +313,7 @@ func (g *JavaGen) genStruct(s structInfo) { for _, f := range fields { if t := f.Type(); !g.isSupported(t) { - g.Printf("// skipped field %s.%s with unsupported type: %s\n\n", n, f.Name(), t) + g.warnf(f.Pos(), "skipped field %s.%s with unsupported type: %s", n, f.Name(), t) continue } @@ -326,7 +327,7 @@ func (g *JavaGen) genStruct(s structInfo) { var isStringer bool for _, m := range methods { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", n, m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", n, m.Name()) continue } g.javadoc(doc.Member(m.Name())) @@ -487,7 +488,7 @@ func (g *JavaGen) genObjectMethods(n string, fields []*types.Var, isStringer boo g.Printf("%s that = (%s)o;\n", n, n) for _, f := range fields { if t := f.Type(); !g.isSupported(t) { - g.Printf("// skipped field %s.%s with unsupported type: %s\n\n", n, f.Name(), t) + g.warnf(f.Pos(), "skipped field %s.%s with unsupported type: %s", n, f.Name(), t) continue } nf := f.Name() @@ -581,7 +582,7 @@ func (g *JavaGen) genInterface(iface interfaceInfo) { for _, m := range iface.summary.callable { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", iface.obj.Name(), m.Name()) continue } g.javadoc(doc.Member(m.Name())) @@ -862,7 +863,7 @@ func (g *JavaGen) genFuncSignature(o *types.Func, jm *java.Func, hasThis bool) { func (g *JavaGen) genVar(o *types.Var) { if t := o.Type(); !g.isSupported(t) { - g.Printf("// skipped variable %s with unsupported type: %s\n\n", o.Name(), t) + g.warnf(o.Pos(), "skipped variable %s with unsupported type: %s", o.Name(), t) return } jType := g.javaType(o.Type()) @@ -1043,7 +1044,7 @@ func JavaClassName(pkg *types.Package) string { func (g *JavaGen) genConst(o *types.Const) { if _, ok := o.Type().(*types.Basic); !ok || !g.isSupported(o.Type()) { - g.Printf("// skipped const %s with unsupported type: %s\n\n", o.Name(), o.Type()) + g.warnf(o.Pos(), "skipped const %s with unsupported type: %s", o.Name(), o.Type()) return } // TODO(hyangah): should const names use upper cases + "_"? @@ -1077,7 +1078,7 @@ func (g *JavaGen) genConst(o *types.Const) { func (g *JavaGen) genJNIField(o *types.TypeName, f *types.Var) { if t := f.Type(); !g.isSupported(t) { - g.Printf("// skipped field %s with unsupported type: %s\n\n", o.Name(), t) + g.warnf(f.Pos(), "skipped field %s with unsupported type: %s", o.Name(), t) return } n := java.JNIMangle(g.javaTypeName(o.Name())) @@ -1107,7 +1108,7 @@ func (g *JavaGen) genJNIField(o *types.TypeName, f *types.Var) { func (g *JavaGen) genJNIVar(o *types.Var) { if t := o.Type(); !g.isSupported(t) { - g.Printf("// skipped variable %s with unsupported type: %s\n\n", o.Name(), t) + g.warnf(o.Pos(), "skipped variable %s with unsupported type: %s", o.Name(), t) return } n := java.JNIMangle(g.javaTypeName(o.Name())) @@ -1187,7 +1188,7 @@ func (g *JavaGen) genJNIFunc(o *types.Func, sName string, jm *java.Func, proxy, if sName != "" { n = sName + "." + n } - g.Printf("// skipped function %s with unsupported parameter or return types\n\n", n) + g.warnf(o.Pos(), "skipped function %s with unsupported parameter or return types", n) return } g.genJNIFuncSignature(o, sName, jm, proxy, isjava) @@ -1276,7 +1277,7 @@ func (g *JavaGen) genRelease(varName string, t types.Type, mode varMode) { func (g *JavaGen) genMethodInterfaceProxy(oName string, m *types.Func) { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s with unsupported parameter or return types\n\n", oName) + g.warnf(m.Pos(), "skipped method %s with unsupported parameter or return types", oName) return } sig := m.Type().(*types.Signature) @@ -1345,7 +1346,7 @@ func (g *JavaGen) GenH() error { g.Printf("\n") for _, m := range iface.summary.callable { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", iface.obj.Name(), m.Name()) continue } g.genInterfaceMethodSignature(m, iface.obj.Name(), true, g.paramName) @@ -1477,7 +1478,7 @@ func (g *JavaGen) GenC() error { g.Printf("jmethodID proxy_class_%s_%s_cons;\n", g.pkgPrefix, iface.obj.Name()) for _, m := range iface.summary.callable { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", iface.obj.Name(), m.Name()) continue } g.Printf("static jmethodID mid_%s_%s;\n", iface.obj.Name(), m.Name()) @@ -1519,7 +1520,7 @@ func (g *JavaGen) GenC() error { g.Printf("clazz = (*env)->FindClass(env, %q);\n", g.jniClassSigPrefix(pkg)+g.javaTypeName(iface.obj.Name())) for _, m := range iface.summary.callable { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", iface.obj.Name(), m.Name()) continue } sig := m.Type().(*types.Signature) @@ -1630,7 +1631,7 @@ func (g *JavaGen) GenJava() error { } for _, m := range iface.summary.callable { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", n, m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", n, m.Name()) continue } g.Printf("public native ") @@ -1652,7 +1653,7 @@ func (g *JavaGen) GenJava() error { } for _, f := range g.funcs { if !g.isSigSupported(f.Type()) { - g.Printf("// skipped function %s with unsupported parameter or return types\n\n", f.Name()) + g.warnf(f.Pos(), "skipped function %s with unsupported parameter or return types", f.Name()) continue } g.javadoc(g.docs[f.Name()].Doc()) @@ -1669,6 +1670,14 @@ func (g *JavaGen) GenJava() error { return nil } +func (g *JavaGen) warnf(pos token.Pos, format string, args ...interface{}) { + if g.Reporter != nil { + fpos := g.Fset.Position(pos) + g.Reporter.Message(fmt.Sprintf(fpos.String()+": "+format, args...)) + } + g.Printf("// "+format+"\n\n", args...) +} + // embeddedJavaClasses returns the possible empty list of Java types embedded // in the given struct type. func embeddedJavaClasses(t *types.Struct) []string { diff --git a/bind/genobjc.go b/bind/genobjc.go index 7595fa0ff..1188975f3 100644 --- a/bind/genobjc.go +++ b/bind/genobjc.go @@ -7,6 +7,7 @@ package bind import ( "fmt" "go/constant" + "go/token" "go/types" "math" "strings" @@ -121,7 +122,7 @@ func (g *ObjcGen) GenGoH() error { } for _, m := range i.summary.callable { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", i.obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", i.obj.Name(), m.Name()) continue } g.genInterfaceMethodSignature(m, i.obj.Name(), true, g.paramName) @@ -192,7 +193,7 @@ func (g *ObjcGen) GenH() error { // TODO: prefix with k?, or use a class method? for _, obj := range g.constants { if _, ok := obj.Type().(*types.Basic); !ok || !g.isSupported(obj.Type()) { - g.Printf("// skipped const %s with unsupported type: %s\n\n", obj.Name(), obj.Type()) + g.warnf(obj.Pos(), "skipped const %s with unsupported type: %s", obj.Name(), obj.Type()) continue } g.objcdoc(g.docs[obj.Name()].Doc()) @@ -212,7 +213,7 @@ func (g *ObjcGen) GenH() error { g.Printf("@interface %s : NSObject\n", g.namePrefix) for _, obj := range g.vars { if t := obj.Type(); !g.isSupported(t) { - g.Printf("// skipped variable %s with unsupported type: %s\n\n", obj.Name(), t) + g.warnf(obj.Pos(), "skipped variable %s with unsupported type: %s", obj.Name(), t) continue } objcType := g.objcType(obj.Type()) @@ -307,7 +308,7 @@ func (g *ObjcGen) GenM() error { for _, obj := range g.funcs { if !g.isSigSupported(obj.Type()) { - g.Printf("// skipped function %s with unsupported parameter or return types\n\n", obj.Name()) + g.warnf(obj.Pos(), "skipped function %s with unsupported parameter or return types", obj.Name()) continue } g.genFuncM(obj) @@ -317,7 +318,7 @@ func (g *ObjcGen) GenM() error { for _, i := range g.interfaces { for _, m := range i.summary.callable { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", i.obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", i.obj.Name(), m.Name()) continue } g.genInterfaceMethodProxy(i.obj, m) @@ -339,7 +340,7 @@ func (g *ObjcGen) GenM() error { func (g *ObjcGen) genVarM(o *types.Var) { if t := o.Type(); !g.isSupported(t) { - g.Printf("// skipped variable %s with unsupported type: %s\n\n", o.Name(), t) + g.warnf(o.Pos(), "skipped variable %s with unsupported type: %s", o.Name(), t) return } objcType := g.objcType(o.Type()) @@ -366,7 +367,7 @@ func (g *ObjcGen) genVarM(o *types.Var) { func (g *ObjcGen) genConstM(o *types.Const) { if _, ok := o.Type().(*types.Basic); !ok || !g.isSupported(o.Type()) { - g.Printf("// skipped const %s with unsupported type: %s\n\n", o.Name(), o.Type()) + g.warnf(o.Pos(), "skipped const %s with unsupported type: %s", o.Name(), o.Type()) return } cName := fmt.Sprintf("%s%s", g.namePrefix, o.Name()) @@ -631,7 +632,7 @@ func (g *ObjcGen) paramName(params *types.Tuple, pos int) string { func (g *ObjcGen) genFuncH(obj *types.Func) { if !g.isSigSupported(obj.Type()) { - g.Printf("// skipped function %s with unsupported parameter or return types\n\n", obj.Name()) + g.warnf(obj.Pos(), "skipped function %s with unsupported parameter or return types", obj.Name()) return } if s := g.funcSummary(nil, obj); s != nil { @@ -883,7 +884,7 @@ func (g *ObjcGen) genInterfaceInterface(obj *types.TypeName, summary ifaceSummar g.Printf("- (nonnull instancetype)initWithRef:(_Nonnull id)ref;\n") for _, m := range summary.callable { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", obj.Name(), m.Name()) continue } s := g.funcSummary(nil, m) @@ -902,7 +903,7 @@ func (g *ObjcGen) genInterfaceH(obj *types.TypeName, t *types.Interface) { g.Printf("@protocol %s%s \n", g.namePrefix, obj.Name()) for _, m := range makeIfaceSummary(t).callable { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", obj.Name(), m.Name()) continue } s := g.funcSummary(nil, m) @@ -936,7 +937,7 @@ func (g *ObjcGen) genInterfaceM(obj *types.TypeName, t *types.Interface) bool { for _, m := range summary.callable { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", obj.Name(), m.Name()) continue } s := g.funcSummary(nil, m) @@ -1104,7 +1105,7 @@ func (g *ObjcGen) genStructH(obj *types.TypeName, t *types.Struct) { if oinf == nil { for _, f := range cons { if !g.isSigSupported(f.Type()) { - g.Printf("// skipped constructor %s.%s with unsupported parameter or return types\n\n", obj.Name(), f.Name()) + g.warnf(f.Pos(), "skipped constructor %s.%s with unsupported parameter or return types", obj.Name(), f.Name()) continue } g.genInitH(obj, f) @@ -1118,7 +1119,7 @@ func (g *ObjcGen) genStructH(obj *types.TypeName, t *types.Struct) { // accessors to exported fields. for _, f := range exportedFields(t) { if t := f.Type(); !g.isSupported(t) { - g.Printf("// skipped field %s.%s with unsupported type: %s\n\n", obj.Name(), f.Name(), t) + g.warnf(f.Pos(), "skipped field %s.%s with unsupported type: %s", obj.Name(), f.Name(), t) continue } name, typ := f.Name(), g.objcType(f.Type()) @@ -1131,7 +1132,7 @@ func (g *ObjcGen) genStructH(obj *types.TypeName, t *types.Struct) { // exported methods for _, m := range exportedMethodSet(types.NewPointer(obj.Type())) { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", obj.Name(), m.Name()) continue } s := g.funcSummary(obj, m) @@ -1167,7 +1168,7 @@ func (g *ObjcGen) genStructM(obj *types.TypeName, t *types.Struct) { if oinf == nil { for _, f := range cons { if !g.isSigSupported(f.Type()) { - g.Printf("// skipped constructor %s.%s with unsupported parameter or return types\n\n", obj, f.Name()) + g.warnf(f.Pos(), "skipped constructor %s.%s with unsupported parameter or return types", obj, f.Name()) continue } g.genInitM(obj, f) @@ -1189,7 +1190,7 @@ func (g *ObjcGen) genStructM(obj *types.TypeName, t *types.Struct) { for _, f := range fields { if !g.isSupported(f.Type()) { - g.Printf("// skipped unsupported field %s with type %s\n\n", f.Name(), f.Type()) + g.warnf(f.Pos(), "skipped unsupported field %s with type %s", f.Name(), f.Type()) continue } g.genGetter(obj.Name(), f) @@ -1198,7 +1199,7 @@ func (g *ObjcGen) genStructM(obj *types.TypeName, t *types.Struct) { for _, m := range methods { if !g.isSigSupported(m.Type()) { - g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name()) + g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", obj.Name(), m.Name()) continue } s := g.funcSummary(obj, m) @@ -1260,6 +1261,14 @@ func (g *ObjcGen) genInitM(obj *types.TypeName, f *types.Func) { g.Printf("}\n\n") } +func (g *ObjcGen) warnf(pos token.Pos, format string, args ...interface{}) { + if g.Reporter != nil { + fpos := g.Fset.Position(pos) + g.Reporter.Message(fmt.Sprintf(fpos.String()+": "+format, args...)) + } + g.Printf("// "+format+"\n\n", args...) +} + func (g *ObjcGen) errorf(format string, args ...interface{}) { g.err = append(g.err, fmt.Errorf(format, args...)) } diff --git a/bind/testdata/ignore.go.golden b/bind/testdata/ignore.go.golden index 486db372c..0474724df 100644 --- a/bind/testdata/ignore.go.golden +++ b/bind/testdata/ignore.go.golden @@ -44,7 +44,9 @@ func (p *proxyignore_I) Bind_proxy_refnum__() int32 { } // skipped method I.Argument with unsupported parameter or result types + // skipped method I.Result with unsupported parameter or result types + // skipped variable C128 with unsupported type complex128 // skipped variable C64 with unsupported type complex64 @@ -60,4 +62,5 @@ func (p *proxyignore_I) Bind_proxy_refnum__() int32 { // skipped variable Var with unsupported type interface{} // skipped function Argument with unsupported parameter or result types + // skipped function Result with unsupported parameter or result types diff --git a/cmd/gobind/gen.go b/cmd/gobind/gen.go index ce2bc5d22..c725c8db3 100644 --- a/cmd/gobind/gen.go +++ b/cmd/gobind/gen.go @@ -25,7 +25,21 @@ import ( "golang.org/x/tools/go/packages" ) -func genPkg(lang string, p *types.Package, astFiles []*ast.File, allPkg []*types.Package, classes []*java.Class, otypes []*objc.Named) { +type consoleReporter struct { + msgs []string +} + +func (r *consoleReporter) Message(s string) { + r.msgs = append(r.msgs, s) +} + +func (r *consoleReporter) PrintMessages() { + if len(r.msgs) > 0 { + fmt.Fprintln(os.Stderr, strings.Join(r.msgs, "\n")) + } +} + +func genPkg(lang string, fset *token.FileSet, p *types.Package, astFiles []*ast.File, allPkg []*types.Package, classes []*java.Class, otypes []*objc.Named) { fname := defaultFileName(lang, p) conf := &bind.GeneratorConfig{ Fset: fset, @@ -39,12 +53,14 @@ func genPkg(lang string, p *types.Package, astFiles []*ast.File, allPkg []*types pname = "universe" } var buf bytes.Buffer + var reporter consoleReporter generator := &bind.Generator{ - Printer: &bind.Printer{Buf: &buf, IndentEach: []byte("\t")}, - Fset: conf.Fset, - AllPkg: conf.AllPkg, - Pkg: conf.Pkg, - Files: astFiles, + Printer: &bind.Printer{Buf: &buf, IndentEach: []byte("\t")}, + Fset: conf.Fset, + AllPkg: conf.AllPkg, + Pkg: conf.Pkg, + Files: astFiles, + Reporter: &reporter, } switch lang { case "java": @@ -169,6 +185,7 @@ func genPkg(lang string, p *types.Package, astFiles []*ast.File, allPkg []*types default: errorf("unknown target language: %q", lang) } + reporter.PrintMessages() } func genPkgH(w io.Writer, pname string) { @@ -303,8 +320,6 @@ func processErr(err error) { } } -var fset = token.NewFileSet() - func writer(fname string) (w io.Writer, closer func()) { if *outdir == "" { return os.Stdout, func() { return } diff --git a/cmd/gobind/main.go b/cmd/gobind/main.go index 8ccb9951e..ab4970a04 100644 --- a/cmd/gobind/main.go +++ b/cmd/gobind/main.go @@ -9,6 +9,7 @@ import ( "flag" "fmt" "go/ast" + "go/token" "go/types" "io/ioutil" "log" @@ -145,18 +146,20 @@ func run() { typePkgs := make([]*types.Package, len(allPkg)) astPkgs := make([][]*ast.File, len(allPkg)) + fSets := make([]*token.FileSet, len(allPkg)) for i, pkg := range allPkg { // Ignore pkg.Errors. pkg.Errors can exist when Cgo is used, but this should not affect the result. // See the discussion at golang/go#36547. typePkgs[i] = pkg.Types astPkgs[i] = pkg.Syntax + fSets[i] = pkg.Fset } for _, l := range langs { for i, pkg := range typePkgs { - genPkg(l, pkg, astPkgs[i], typePkgs, classes, otypes) + genPkg(l, fSets[i], pkg, astPkgs[i], typePkgs, classes, otypes) } // Generate the error package and support files - genPkg(l, nil, nil, typePkgs, classes, otypes) + genPkg(l, token.NewFileSet(), nil, nil, typePkgs, classes, otypes) } } diff --git a/cmd/gomobile/bind_androidapp.go b/cmd/gomobile/bind_androidapp.go index 8fe91793d..f7c809744 100644 --- a/cmd/gomobile/bind_androidapp.go +++ b/cmd/gomobile/bind_androidapp.go @@ -29,6 +29,8 @@ func goAndroidBind(gobind string, pkgs []*packages.Package, androidArchs []strin "-lang=go,java", "-outdir="+tmpdir, ) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr cmd.Env = append(cmd.Env, "GOOS=android") cmd.Env = append(cmd.Env, "CGO_ENABLED=1") if len(buildTags) > 0 { diff --git a/cmd/gomobile/bind_iosapp.go b/cmd/gomobile/bind_iosapp.go index 91d0de3ae..90f537597 100644 --- a/cmd/gomobile/bind_iosapp.go +++ b/cmd/gomobile/bind_iosapp.go @@ -7,6 +7,7 @@ package main import ( "fmt" "io" + "os" "os/exec" "path/filepath" "strings" @@ -22,6 +23,8 @@ func goIOSBind(gobind string, pkgs []*packages.Package, archs []string) error { "-lang=go,objc", "-outdir="+tmpdir, ) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr cmd.Env = append(cmd.Env, "GOOS=darwin") cmd.Env = append(cmd.Env, "CGO_ENABLED=1") tags := append(buildTags, "ios")