bind: error for packages with no exported names.
For error message improvement mentioned in golang/go#12842
Change-Id: I066ae9dc9415b34bf93128098199bbb935b7dedc
Reviewed-on: https://go-review.googlesource.com/15410
Reviewed-by: David Crawshaw <crawshaw@golang.org>
diff --git a/bind/gengo.go b/bind/gengo.go
index da3c574..d5e863b 100644
--- a/bind/gengo.go
+++ b/bind/gengo.go
@@ -401,11 +401,14 @@
scope := g.pkg.Scope()
names := scope.Names()
+
+ hasExported := false
for _, name := range names {
obj := scope.Lookup(name)
if !obj.Exported() {
continue
}
+ hasExported = true
switch obj := obj.(type) {
// TODO(crawshaw): case *types.Var:
@@ -433,6 +436,9 @@
continue
}
}
+ if !hasExported {
+ g.errorf("no exported names in the package %q", g.pkg.Path())
+ }
if len(funcs) > 0 {
g.Printf("func init() {\n")
diff --git a/bind/genjava.go b/bind/genjava.go
index 4b14860..632153a 100644
--- a/bind/genjava.go
+++ b/bind/genjava.go
@@ -668,11 +668,13 @@
scope := g.pkg.Scope()
names := scope.Names()
+ hasExported := false
for _, name := range names {
obj := scope.Lookup(name)
if !obj.Exported() {
continue
}
+ hasExported = true
switch o := obj.(type) {
// TODO(crawshaw): case *types.Var:
@@ -700,6 +702,9 @@
g.errorf("unsupported exported type: %T", obj)
}
}
+ if !hasExported {
+ g.errorf("no exported names in the package %q", g.pkg.Path())
+ }
for i, name := range funcs {
g.Printf("private static final int CALL_%s = %d;\n", name, i+1)
diff --git a/bind/genobjc.go b/bind/genobjc.go
index 25bc35c..441d355 100644
--- a/bind/genobjc.go
+++ b/bind/genobjc.go
@@ -39,11 +39,13 @@
g.names = nil
scope := g.pkg.Scope()
+ hasExported := false
for _, name := range scope.Names() {
obj := scope.Lookup(name)
if !obj.Exported() {
continue
}
+ hasExported = true
switch obj := obj.(type) {
case *types.Func:
if isCallable(obj) {
@@ -63,6 +65,9 @@
g.errorf("unsupported exported type for %s: %T", obj.Name(), obj)
}
}
+ if !hasExported {
+ g.errorf("no exported names in the package %q", g.pkg.Path())
+ }
}
const objcPreamble = `// Objective-C API for talking to %[1]s Go package.