Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buildmode argument #1

Open
wants to merge 2 commits into
base: fork
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions FORK
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changes
#
# 1. Panic when a Java class cannot be found.
#
# 2. Add Go constructor for generated Java wrappers of Go code to facilitate
# Java calling back into Go.
2 changes: 1 addition & 1 deletion bind/genclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func (g *ClassGen) genGo(cls *java.Class) {
g.Printf("C.free(unsafe.Pointer(cls))\n")
// Before Go 1.11 clazz was a pointer value, an uintptr after.
g.Printf("if uintptr(clazz) == 0 {\n")
g.Printf(" return\n")
g.Printf("\tpanic(`unable to find class %q`)\n", strings.Replace(cls.FindName, ".", "/", -1))
g.Printf("}\n")
g.Printf("class_%s = clazz\n", cls.JNIName)
for _, fs := range cls.Funcs {
Expand Down
5 changes: 5 additions & 0 deletions cmd/gomobile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ var (
buildO string // -o
buildGcflags string // -gcflags
buildLdflags string // -ldflags
buildBuildmode string // -buildmode
buildTarget string // -target
buildTrimpath bool // -trimpath
buildWork bool // -work
Expand All @@ -234,6 +235,7 @@ func addBuildFlags(cmd *command) {
cmd.flag.StringVar(&buildO, "o", "", "")
cmd.flag.StringVar(&buildGcflags, "gcflags", "", "")
cmd.flag.StringVar(&buildLdflags, "ldflags", "", "")
cmd.flag.StringVar(&buildBuildmode, "buildmode", "", "")
cmd.flag.StringVar(&buildTarget, "target", "android", "")
cmd.flag.StringVar(&buildBundleID, "bundleid", "", "")
cmd.flag.StringVar(&buildIOSVersion, "iosversion", "7.0", "")
Expand Down Expand Up @@ -316,6 +318,9 @@ func goCmdAt(at string, subcmd string, srcs []string, env []string, args ...stri
if buildLdflags != "" {
cmd.Args = append(cmd.Args, "-ldflags", buildLdflags)
}
if buildBuildmode != "" {
cmd.Args = append(cmd.Args, "-buildmode", buildBuildmode)
}
if buildTrimpath {
cmd.Args = append(cmd.Args, "-trimpath")
}
Expand Down
27 changes: 27 additions & 0 deletions internal/importers/java/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,33 @@ func (j *Importer) Import(refs *importers.References) ([]*Class, error) {
JNIName: JNIMangle(n),
PkgName: emb.Name,
HasNoArgCon: true,
Funcs: []*FuncSet{
{
Name: n,
GoName: "New",
Funcs: []*Func{{
FuncSig: FuncSig{
Name: "new", // or emb.Name
Desc: "()V",
},
JNIName: JNIMangle(emb.Name),
Public: true,
Final: true,
Constructor: true,
Ret: &Type{
Kind: Object,
Class: n,
},
}},
CommonSig: CommonSig{
HasRet: true,
Ret: &Type{
Kind: Object,
Class: n,
},
},
},
},
}
for _, ref := range emb.Refs {
jpkg := strings.Replace(ref.Pkg, "/", ".", -1)
Expand Down