cmd/gobind: fix build of ObjC bindings with a custom prefix

Also add a test. The corresponding Java custom package option
already have one.

Fixes golang/go#24986

Change-Id: I095d97022beb0a57df784fe0a12bc42a66bb8a07
Reviewed-on: https://go-review.googlesource.com/110058
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/bind/objc/SeqCustom.m b/bind/objc/SeqCustom.m
new file mode 100644
index 0000000..c365737
--- /dev/null
+++ b/bind/objc/SeqCustom.m
@@ -0,0 +1,21 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build ignore
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+@import Testpkg;
+
+@interface tests : XCTestCase
+
+@end
+
+@implementation tests
+
+- (void)testBasics {
+	CustomTestpkgHi();
+}
+
+@end
diff --git a/bind/objc/seq_test.go b/bind/objc/seq_test.go
index d0d7aa9..5d88914 100644
--- a/bind/objc/seq_test.go
+++ b/bind/objc/seq_test.go
@@ -29,35 +29,39 @@
 //   Project => Schemes => Manage Schemes from the Xcode menu and selecting "Shared".
 // - Remove files not needed for xcodebuild (determined empirically). In particular, the empty
 //   tests Xcode creates can be removed and the unused user scheme.
+//
+// All tests here require the Xcode command line tools.
 
 var destination = flag.String("device", "platform=iOS Simulator,name=iPhone 6s Plus", "Specify the -destination flag to xcodebuild")
 
 // TestObjcSeqTest runs ObjC test SeqTest.m.
-// This requires the xcode command lines tools.
 func TestObjcSeqTest(t *testing.T) {
 	runTest(t, []string{
 		"golang.org/x/mobile/bind/testdata/testpkg",
 		"golang.org/x/mobile/bind/testdata/testpkg/secondpkg",
 		"golang.org/x/mobile/bind/testdata/testpkg/simplepkg",
-	}, "SeqTest.m", "Testpkg.framework", false, false)
+	}, "", "SeqTest.m", "Testpkg.framework", false, false)
 }
 
 // TestObjcSeqBench runs ObjC test SeqBench.m.
-// This requires the xcode command lines tools.
 func TestObjcSeqBench(t *testing.T) {
 	if testing.Short() {
 		t.Skip("skipping benchmark in short mode.")
 	}
-	runTest(t, []string{"golang.org/x/mobile/bind/testdata/benchmark"}, "SeqBench.m", "Benchmark.framework", true, true)
+	runTest(t, []string{"golang.org/x/mobile/bind/testdata/benchmark"}, "", "SeqBench.m", "Benchmark.framework", true, true)
 }
 
 // TestObjcSeqWrappers runs ObjC test SeqWrappers.m.
-// This requires the xcode command lines tools.
 func TestObjcSeqWrappers(t *testing.T) {
-	runTest(t, []string{"golang.org/x/mobile/bind/testdata/testpkg/objcpkg"}, "SeqWrappers.m", "Objcpkg.framework", false, false)
+	runTest(t, []string{"golang.org/x/mobile/bind/testdata/testpkg/objcpkg"}, "", "SeqWrappers.m", "Objcpkg.framework", false, false)
 }
 
-func runTest(t *testing.T, pkgNames []string, testfile, framework string, uitest, dumpOutput bool) {
+// TestObjcCustomPkg runs the ObjC test SeqCustom.m.
+func TestObjcCustomPkg(t *testing.T) {
+	runTest(t, []string{"golang.org/x/mobile/bind/testdata/testpkg"}, "Custom", "SeqCustom.m", "Testpkg.framework", false, false)
+}
+
+func runTest(t *testing.T, pkgNames []string, prefix, testfile, framework string, uitest, dumpOutput bool) {
 	if _, err := run("which xcodebuild"); err != nil {
 		t.Skip("command xcodebuild not found, skipping")
 	}
@@ -84,6 +88,9 @@
 	}
 
 	cmd := exec.Command("gomobile", "bind", "-target", "ios", "-tags", "aaa bbb")
+	if prefix != "" {
+		cmd.Args = append(cmd.Args, "-prefix", prefix)
+	}
 	cmd.Args = append(cmd.Args, pkgNames...)
 	cmd.Dir = filepath.Join(tmpdir, "xcodetest")
 	buf, err := cmd.CombinedOutput()
diff --git a/cmd/gobind/gen.go b/cmd/gobind/gen.go
index cb2d3cc..f1fc7b4 100644
--- a/cmd/gobind/gen.go
+++ b/cmd/gobind/gen.go
@@ -368,7 +368,7 @@
 		}
 		firstRune, size := utf8.DecodeRuneInString(pkg.Name())
 		className := string(unicode.ToUpper(firstRune)) + pkg.Name()[size:]
-		return className + ".m"
+		return *prefix + className + ".m"
 	}
 	errorf("unknown target language: %q", lang)
 	os.Exit(exitStatus)