From 658060851d8c865ae76f46a5a7158909d83d344c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 12 Feb 2023 21:35:01 +0000 Subject: [PATCH] drop bits of code to support Go 1.19 --- main.go | 11 ++--------- main_test.go | 6 ++---- shared.go | 16 ---------------- testdata/script/reverse.txtar | 10 ++-------- 4 files changed, 6 insertions(+), 37 deletions(-) diff --git a/main.go b/main.go index a45e542..fe52e38 100644 --- a/main.go +++ b/main.go @@ -354,7 +354,7 @@ func mainErr(args []string) error { // Until https://github.com/golang/go/issues/50603 is implemented, // manually construct something like a pseudo-version. - // TODO: remove when this code is dead, hopefully in Go 1.20. + // TODO: remove when this code is dead, hopefully in Go 1.21. if mod.Version == "(devel)" { var vcsTime time.Time var vcsRevision string @@ -794,15 +794,8 @@ func replaceAsmNames(buf *bytes.Buffer, remaining []byte) { // If the name was qualified, fetch the package, and write the // obfuscated import path if needed. // Note that we don't obfuscate the package path "main". - // - // Note that runtime/internal/startlinetest refers to runtime_test in - // one of its assembly files, and we currently do not always collect - // test packages in appendListedPackages for the sake of performance. - // We don't care about testing the runtime just yet, so work around it. - // TODO(mvdan): this runtime_test reference was removed in Go 1.20 per - // https://github.com/golang/go/issues/57334; remove at a later time. lpkg := curPkg - if asmPkgPath != "" && asmPkgPath != "main" && asmPkgPath != "runtime_test" { + if asmPkgPath != "" && asmPkgPath != "main" { if asmPkgPath != curPkg.Name { goPkgPath := asmPkgPath goPkgPath = strings.ReplaceAll(goPkgPath, string(asmPeriod), string(goPeriod)) diff --git a/main_test.go b/main_test.go index aa49c9b..6200521 100644 --- a/main_test.go +++ b/main_test.go @@ -315,8 +315,6 @@ func grepfiles(ts *testscript.TestScript, neg bool, args []string) { anyFound := false path, pattern := args[0], args[1] rx := regexp.MustCompile(pattern) - // TODO: use fs.SkipAll in Go 1.20 and later. - errSkipAll := fmt.Errorf("sentinel error: stop walking") if err := filepath.WalkDir(path, func(path string, d fs.DirEntry, err error) error { if err != nil { return err @@ -326,11 +324,11 @@ func grepfiles(ts *testscript.TestScript, neg bool, args []string) { return fmt.Errorf("%q matches %q", path, pattern) } else { anyFound = true - return errSkipAll + return fs.SkipAll } } return nil - }); err != nil && err != errSkipAll { + }); err != nil { ts.Fatalf("%s", err) } if !neg && !anyFound { diff --git a/shared.go b/shared.go index b97317c..87fa08f 100644 --- a/shared.go +++ b/shared.go @@ -278,22 +278,6 @@ func appendListedPackages(packages []string, withDeps bool) error { pkg.GarbleActionID = addGarbleToHash(actionID) } - // Work around https://go.dev/issue/28749: - // cmd/go puts assembly, C, and C++ files in CompiledGoFiles. - // - // TODO: Fixed in Go 1.20; remove once we drop support for Go 1.19. - out := pkg.CompiledGoFiles[:0] - for _, path := range pkg.CompiledGoFiles { - switch filepath.Ext(path) { - case "": // e.g. a generated Go file inside the build cache - case ".go": - default: // e.g. an assembly file - continue - } - out = append(out, path) - } - pkg.CompiledGoFiles = out - cache.ListedPackages[pkg.ImportPath] = &pkg } diff --git a/testdata/script/reverse.txtar b/testdata/script/reverse.txtar index 1180ad0..2b83ccd 100644 --- a/testdata/script/reverse.txtar +++ b/testdata/script/reverse.txtar @@ -28,8 +28,7 @@ cp stderr build-error.stderr stdin build-error.stderr garble reverse ./build-error -[!go1.20] cmp stdout build-error-reverse.stdout-go1.19 -[go1.20] cmp stdout build-error-reverse.stdout-go1.20 +cmp stdout build-error-reverse.stdout [short] stop # no need to verify this with -short @@ -157,12 +156,7 @@ main.main(...) test/main/long_main.go:11 +0x?? main filename: test/main/long_main.go --- build-error-reverse.stdout-go1.19 -- -# test/main/build-error -test/main/build-error/error.go:18: cannot convert UnobfuscatedStruct{} (value of type UnobfuscatedStruct) to type struct{SomeField int} -exit status 2 -exit status 2 --- build-error-reverse.stdout-go1.20 -- +-- build-error-reverse.stdout -- # test/main/build-error test/main/build-error/error.go:18: cannot convert UnobfuscatedStruct{} (value of type UnobfuscatedStruct) to type struct{SomeField int} exit status 2