From f7a629369e7a136ff93bf44726628eb2afe551a2 Mon Sep 17 00:00:00 2001 From: Changkun Ou Date: Tue, 31 Aug 2021 11:47:56 +0200 Subject: [PATCH] cmd/gomobile: extract import packages more robust In darwin/arm64, with Xcode13 toolchain, the nm shows a prefix `_` in the import path, which was previously not handled. Such as: 000000010009cd70 t _golang.org/x/mobile/app.(*app).Events 000000010009ce70 t _golang.org/x/mobile/app.(*app).Filter 000000010009cdf0 t _golang.org/x/mobile/app.(*app).Publish 000000010009cd80 t _golang.org/x/mobile/app.(*app).Send 000000010009d870 t _golang.org/x/mobile/app.(*app).loop 000000010009d7f0 t _golang.org/x/mobile/app.(*app).loop.func1 This change fixes the regexp for import package extraction and permits TestRegexImportGolangXPackage to pass. Change-Id: I5f8b02177c8b022283276f2ddffaa8bb277aa255 Reviewed-on: https://go-review.googlesource.com/c/mobile/+/346154 Reviewed-by: Dmitri Shuralyov Reviewed-by: Hajime Hoshi Trust: Dmitri Shuralyov Run-TryBot: Dmitri Shuralyov TryBot-Result: Go Bot --- cmd/gomobile/build.go | 2 +- cmd/gomobile/build_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/gomobile/build.go b/cmd/gomobile/build.go index 072af00..83571fd 100644 --- a/cmd/gomobile/build.go +++ b/cmd/gomobile/build.go @@ -155,7 +155,7 @@ func runBuildImpl(cmd *command) (*packages.Package, error) { return pkg, nil } -var nmRE = regexp.MustCompile(`[0-9a-f]{8} t (?:.*/vendor/)?(golang.org/x.*/[^.]*)`) +var nmRE = regexp.MustCompile(`[0-9a-f]{8} t _?(?:.*/vendor/)?(golang.org/x.*/[^.]*)`) func extractPkgs(nm string, path string) (map[string]bool, error) { if buildN { diff --git a/cmd/gomobile/build_test.go b/cmd/gomobile/build_test.go index 7a55603..9a34f75 100644 --- a/cmd/gomobile/build_test.go +++ b/cmd/gomobile/build_test.go @@ -168,6 +168,7 @@ func TestRegexImportGolangXPackage(t *testing.T) { {"ffffffff t github.com/example/golang.org/x/mobile", "", 0}, {"ffffffff t github.com/example/repo", "", 0}, {"ffffffff t github.com/example/repo/vendor", "", 0}, + {"ffffffff t _golang.org/x/mobile/app", "golang.org/x/mobile/app", 2}, } for _, tc := range tests {