diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 571ebee..493b3e0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -71,8 +71,7 @@ jobs: steps: - name: Install Go env: - # Note that newer tip versions from May break due to the boringtls merge. - GO_COMMIT: e6dfdbd11d5dcc9f918150552f50ca6cd524b89b # 2022-04-23 + GO_COMMIT: 016d7552138077741a9c3fdadc73c0179f5d3ff7 # 2022-05-12 run: | cd $HOME mkdir $HOME/gotip diff --git a/shared.go b/shared.go index 578ee0f..187fce6 100644 --- a/shared.go +++ b/shared.go @@ -139,9 +139,10 @@ type listedPackage struct { ImportMap map[string]string Standard bool - Dir string - GoFiles []string - Imports []string + Dir string + GoFiles []string + Imports []string + Incomplete bool // The fields below are not part of 'go list', but are still reused // between garble processes. Use "Garble" as a prefix to ensure no @@ -149,10 +150,10 @@ type listedPackage struct { // TODO(mvdan): consider filling this iff ToObfuscate==true, // which will help ensure we don't obfuscate any of their names otherwise. - GarbleActionID []byte + GarbleActionID []byte `json:"-"` // ToObfuscate records whether the package should be obfuscated. - ToObfuscate bool + ToObfuscate bool `json:"-"` } func (p *listedPackage) obfuscatedImportPath() string { @@ -176,7 +177,7 @@ func appendListedPackages(packages []string, withDeps bool) error { // TODO: perhaps include all top-level build flags set by garble, // including -buildvcs=false. // They shouldn't affect "go list" here, but might as well be consistent. - args := []string{"list", "-json", "-export", "-trimpath"} + args := []string{"list", "-json", "-export", "-trimpath", "-e"} if withDeps { args = append(args, "-deps") } @@ -209,6 +210,13 @@ func appendListedPackages(packages []string, withDeps bool) error { if err := dec.Decode(&pkg); err != nil { return err } + + // Note that we use the `-e` flag above with `go list`. + // If a package fails to load, the Incomplete and Error fields will be set. + // We still record failed packages in the ListedPackages map, + // because some like crypto/internal/boring/fipstls simply fall under + // "build constraints exclude all Go files" and can be ignored. + // Real build errors will still be surfaced by `go build -toolexec` later. if cache.ListedPackages[pkg.ImportPath] != nil { return fmt.Errorf("duplicate package: %q", pkg.ImportPath) } @@ -235,6 +243,9 @@ func appendListedPackages(packages []string, withDeps bool) error { case cannotObfuscate[path], runtimeAndDeps[path]: // We don't support obfuscating these yet. + case pkg.Incomplete: + // We can't obfuscate packages which weren't loaded. + case pkg.Name == "main" && strings.HasSuffix(path, ".test"), path == "command-line-arguments", strings.HasPrefix(path, "plugin/unnamed"), @@ -335,6 +346,8 @@ func listPackage(path string) (*listedPackage, error) { startTime := time.Now() // Obtained via scripts/runtime-linknamed-nodeps.sh as of Go 1.18beta1. runtimeLinknamed := []string{ + "crypto/internal/boring", + "crypto/internal/boring/fipstls", "crypto/x509/internal/macos", "internal/poll", "internal/reflectlite", diff --git a/testdata/scripts/help.txt b/testdata/scripts/help.txt index 783c05e..0de09b5 100644 --- a/testdata/scripts/help.txt +++ b/testdata/scripts/help.txt @@ -1,3 +1,5 @@ +env GOGARBLE=* + ! garble stderr 'Garble obfuscates Go code' stderr 'garble \[garble flags\] command' @@ -77,6 +79,14 @@ stderr 'must precede command, like: garble -seed=random build \./pkg' [windows] ! garble C:\does\not\exist\compile stderr 'run "garble \[command\]"' +! garble build badpackage +stderr 'package badpackage is not in GOROOT' +! stdout . + +! garble build ./badpackage +stderr 'directory not found' +! stdout . + # Test the version command. Note that test binaries exclude VCS build info, # and we reuse the test binary for garble itself, so that's missing. # To avoid building another garble binary, diff --git a/testdata/scripts/reflect.txt b/testdata/scripts/reflect.txt index 385b093..adac6f6 100644 --- a/testdata/scripts/reflect.txt +++ b/testdata/scripts/reflect.txt @@ -229,7 +229,7 @@ type ReflectEmbeddedAlias = ReflectEmbeddingNamed type ReflectEmbeddingNamed struct{} -func VariadicReflect(x interface{}, ys ...interface{}) int { +func VariadicReflect(x any, ys ...any) int { _ = reflect.TypeOf(x) _ = reflect.TypeOf(ys)