From 1d3b1e5c533f3e2b92f8cdde1921d96b618eb361 Mon Sep 17 00:00:00 2001 From: baizon Date: Sun, 21 Jul 2024 09:16:41 +0200 Subject: [PATCH 1/2] feat: added glflags --- cmd/gomobile/bind.go | 5 +++-- cmd/gomobile/build.go | 32 +++++++++++++++++--------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/cmd/gomobile/bind.go b/cmd/gomobile/bind.go index fc9f75631..ea412d0b5 100644 --- a/cmd/gomobile/bind.go +++ b/cmd/gomobile/bind.go @@ -65,7 +65,7 @@ classes. The -v flag provides verbose output, including the list of packages built. -The build flags -a, -n, -x, -gcflags, -ldflags, -tags, -trimpath, and -work +The build flags -a, -n, -x, -gcflags, -ldflags, -tags, -glflags, -trimpath, and -work are shared with the build command. For documentation, see 'go help build'. `, } @@ -231,9 +231,10 @@ func getModuleVersions(targetPlatform string, targetArch string, src string) (*m cmd.Env = append(os.Environ(), "GOOS="+platformOS(targetPlatform), "GOARCH="+targetArch) tags := append(buildTags[:], platformTags(targetPlatform)...) + glflags := buildGoListFlags // TODO(hyangah): probably we don't need to add all the dependencies. - cmd.Args = append(cmd.Args, "-m", "-json", "-tags="+strings.Join(tags, ","), "all") + cmd.Args = append(cmd.Args, glflags, "-m", "-json", "-tags="+strings.Join(tags, ","), "all") cmd.Dir = src output, err := cmd.Output() diff --git a/cmd/gomobile/build.go b/cmd/gomobile/build.go index f8895eb31..dae3642c8 100644 --- a/cmd/gomobile/build.go +++ b/cmd/gomobile/build.go @@ -233,27 +233,29 @@ func printcmd(format string, args ...interface{}) { // "Build flags", used by multiple commands. var ( - buildA bool // -a - buildI bool // -i - buildN bool // -n - buildV bool // -v - buildX bool // -x - buildO string // -o - buildGcflags string // -gcflags - buildLdflags string // -ldflags - buildTarget string // -target - buildTrimpath bool // -trimpath - buildWork bool // -work - buildBundleID string // -bundleid - buildIOSVersion string // -iosversion - buildAndroidAPI int // -androidapi - buildTags stringsFlag // -tags + buildA bool // -a + buildI bool // -i + buildN bool // -n + buildV bool // -v + buildX bool // -x + buildO string // -o + buildGcflags string // -gcflags + buildLdflags string // -ldflags + buildTarget string // -target + buildTrimpath bool // -trimpath + buildWork bool // -work + buildBundleID string // -bundleid + buildIOSVersion string // -iosversion + buildAndroidAPI int // -androidapi + buildTags stringsFlag // -tags + buildGoListFlags string // -glflags ) func addBuildFlags(cmd *command) { cmd.flag.StringVar(&buildO, "o", "", "") cmd.flag.StringVar(&buildGcflags, "gcflags", "", "") cmd.flag.StringVar(&buildLdflags, "ldflags", "", "") + cmd.flag.StringVar(&buildGoListFlags, "glflags", "", "") cmd.flag.StringVar(&buildTarget, "target", "android", "") cmd.flag.StringVar(&buildBundleID, "bundleid", "", "") cmd.flag.StringVar(&buildIOSVersion, "iosversion", "13.0", "") From de3284d1a4abc021a9e8e94ef2851c98c017c54a Mon Sep 17 00:00:00 2001 From: baizon Date: Tue, 3 Sep 2024 07:43:45 +0200 Subject: [PATCH 2/2] refactor: changed glflag to golistflags --- cmd/gomobile/bind.go | 12 ++++++++---- cmd/gomobile/build.go | 34 +++++++++++++++++----------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/cmd/gomobile/bind.go b/cmd/gomobile/bind.go index ea412d0b5..7d51a0fcb 100644 --- a/cmd/gomobile/bind.go +++ b/cmd/gomobile/bind.go @@ -63,10 +63,14 @@ For -target android, the -bootclasspath and -classpath flags are used to control the bootstrap classpath and the classpath for Go wrappers to Java classes. +The -golistflags flag passes args to the go list command. +Example: -golistflags="-mod=readonly" + The -v flag provides verbose output, including the list of packages built. -The build flags -a, -n, -x, -gcflags, -ldflags, -tags, -glflags, -trimpath, and -work -are shared with the build command. For documentation, see 'go help build'. +The build flags -a, -n, -x, -gcflags, -ldflags, -tags, +-trimpath, and -work are shared with the build command. For documentation, +see 'go help build'. `, } @@ -231,10 +235,10 @@ func getModuleVersions(targetPlatform string, targetArch string, src string) (*m cmd.Env = append(os.Environ(), "GOOS="+platformOS(targetPlatform), "GOARCH="+targetArch) tags := append(buildTags[:], platformTags(targetPlatform)...) - glflags := buildGoListFlags + golistflags := buildGoListFlags // TODO(hyangah): probably we don't need to add all the dependencies. - cmd.Args = append(cmd.Args, glflags, "-m", "-json", "-tags="+strings.Join(tags, ","), "all") + cmd.Args = append(cmd.Args, golistflags, "-m", "-json", "-tags="+strings.Join(tags, ","), "all") cmd.Dir = src output, err := cmd.Output() diff --git a/cmd/gomobile/build.go b/cmd/gomobile/build.go index dae3642c8..cc5e43d4c 100644 --- a/cmd/gomobile/build.go +++ b/cmd/gomobile/build.go @@ -233,29 +233,29 @@ func printcmd(format string, args ...interface{}) { // "Build flags", used by multiple commands. var ( - buildA bool // -a - buildI bool // -i - buildN bool // -n - buildV bool // -v - buildX bool // -x - buildO string // -o - buildGcflags string // -gcflags - buildLdflags string // -ldflags - buildTarget string // -target - buildTrimpath bool // -trimpath - buildWork bool // -work - buildBundleID string // -bundleid - buildIOSVersion string // -iosversion - buildAndroidAPI int // -androidapi - buildTags stringsFlag // -tags - buildGoListFlags string // -glflags + buildA bool // -a + buildI bool // -i + buildN bool // -n + buildV bool // -v + buildX bool // -x + buildO string // -o + buildGcflags string // -gcflags + buildLdflags string // -ldflags + buildTarget string // -target + buildTrimpath bool // -trimpath + buildWork bool // -work + buildBundleID string // -bundleid + buildIOSVersion string // -iosversion + buildAndroidAPI int // -androidapi + buildTags stringsFlag // -tags + buildGoListFlags string // -golistflags ) func addBuildFlags(cmd *command) { cmd.flag.StringVar(&buildO, "o", "", "") cmd.flag.StringVar(&buildGcflags, "gcflags", "", "") cmd.flag.StringVar(&buildLdflags, "ldflags", "", "") - cmd.flag.StringVar(&buildGoListFlags, "glflags", "", "") + cmd.flag.StringVar(&buildGoListFlags, "golistflags", "", "") cmd.flag.StringVar(&buildTarget, "target", "android", "") cmd.flag.StringVar(&buildBundleID, "bundleid", "", "") cmd.flag.StringVar(&buildIOSVersion, "iosversion", "13.0", "")