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>
This commit is contained in:
Elias Naur 2018-04-28 14:11:45 +02:00
parent 58fd324ce7
commit c909788f99
3 changed files with 36 additions and 8 deletions

21
bind/objc/SeqCustom.m Normal file
View File

@ -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

View File

@ -29,35 +29,39 @@ import (
// 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 @@ func runTest(t *testing.T, pkgNames []string, testfile, framework string, uitest
}
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()

View File

@ -368,7 +368,7 @@ func defaultFileName(lang string, pkg *types.Package) string {
}
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)