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 <dmitshur@golang.org>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
Changkun Ou 2021-08-31 11:47:56 +02:00 committed by Hajime Hoshi
parent 9cba7bc03c
commit f7a629369e
2 changed files with 2 additions and 1 deletions

View File

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

View File

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