]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: use a copy of platform.BuildModeSupported
authorIan Lance Taylor <iant@golang.org>
Fri, 10 Feb 2023 22:47:07 +0000 (14:47 -0800)
committerGopher Robot <gobot@golang.org>
Mon, 13 Feb 2023 19:16:13 +0000 (19:16 +0000)
The dist tool already includes a similar duplicate of BuildModeSupported.
Replace it with an exact copy, to make it easier to maintain going forward.

Change-Id: Id14a6c5a48f92d843e02218d87cc62c6b001923b
Reviewed-on: https://go-review.googlesource.com/c/go/+/467495
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>

src/cmd/dist/test.go
src/internal/platform/supported.go

index 4395d3a33bd05dad42e9c0bb4571666db9c0b581..bc58f0936bcea6f207074aafaa4554aaa75cf739 100644 (file)
@@ -1136,79 +1136,14 @@ func (t *tester) internalLinkPIE() bool {
 
 // supportedBuildMode reports whether the given build mode is supported.
 func (t *tester) supportedBuildmode(mode string) bool {
-       pair := goos + "-" + goarch
        switch mode {
-       case "c-archive":
-               if !t.extLink() {
-                       return false
-               }
-               switch goos {
-               case "aix", "darwin", "ios", "windows":
-                       return true
-               case "linux":
-                       switch goarch {
-                       case "386", "amd64", "arm", "armbe", "arm64", "arm64be", "ppc64", "ppc64le", "riscv64", "s390x":
-                               return true
-                       default:
-                               // Other targets do not support -shared,
-                               // per ParseFlags in
-                               // cmd/compile/internal/base/flag.go.
-                               // For c-archive the Go tool passes -shared,
-                               // so that the result is suitable for inclusion
-                               // in a PIE or shared library.
-                               return false
-                       }
-               case "freebsd":
-                       return goarch == "amd64"
-               }
-               return false
-       case "c-shared":
-               switch pair {
-               case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-riscv64", "linux-s390x",
-                       "darwin-amd64", "darwin-arm64",
-                       "freebsd-amd64",
-                       "android-arm", "android-arm64", "android-386", "android-amd64",
-                       "windows-amd64", "windows-386", "windows-arm64":
-                       return true
-               }
-               return false
-       case "shared":
-               switch pair {
-               case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-s390x":
-                       return true
-               }
-               return false
-       case "plugin":
-               switch pair {
-               case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-s390x", "linux-ppc64le":
-                       return true
-               case "android-386", "android-amd64":
-                       return true
-               case "darwin-amd64", "darwin-arm64":
-                       return true
-               case "freebsd-amd64":
-                       return true
-               }
-               return false
-       case "pie":
-               switch pair {
-               case "aix-ppc64",
-                       "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-riscv64", "linux-s390x",
-                       "android-amd64", "android-arm", "android-arm64", "android-386":
-                       return true
-               case "darwin-amd64", "darwin-arm64", "ios-amd64", "ios-arm64":
-                       return true
-               case "windows-amd64", "windows-386", "windows-arm", "windows-arm64":
-                       return true
-               case "freebsd-amd64":
-                       return true
-               }
-               return false
-
+       case "c-archive", "c-shared", "shared", "plugin", "pie":
        default:
                fatalf("internal error: unknown buildmode %s", mode)
                return false
        }
+
+       return buildModeSupported("gc", mode, goos, goarch)
 }
 
 func (t *tester) registerCgoTests() {
@@ -1737,6 +1672,96 @@ func raceDetectorSupported(goos, goarch string) bool {
        }
 }
 
+// buildModeSupports is a copy of the function
+// internal/platform.BuildModeSupported, which can't be used here
+// because cmd/dist can not import internal packages during bootstrap.
+func buildModeSupported(compiler, buildmode, goos, goarch string) bool {
+       if compiler == "gccgo" {
+               return true
+       }
+
+       platform := goos + "/" + goarch
+
+       switch buildmode {
+       case "archive":
+               return true
+
+       case "c-archive":
+               switch goos {
+               case "aix", "darwin", "ios", "windows":
+                       return true
+               case "linux":
+                       switch goarch {
+                       case "386", "amd64", "arm", "armbe", "arm64", "arm64be", "ppc64le", "riscv64", "s390x":
+                               // linux/ppc64 not supported because it does
+                               // not support external linking mode yet.
+                               return true
+                       default:
+                               // Other targets do not support -shared,
+                               // per ParseFlags in
+                               // cmd/compile/internal/base/flag.go.
+                               // For c-archive the Go tool passes -shared,
+                               // so that the result is suitable for inclusion
+                               // in a PIE or shared library.
+                               return false
+                       }
+               case "freebsd":
+                       return goarch == "amd64"
+               }
+               return false
+
+       case "c-shared":
+               switch platform {
+               case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/ppc64le", "linux/riscv64", "linux/s390x",
+                       "android/amd64", "android/arm", "android/arm64", "android/386",
+                       "freebsd/amd64",
+                       "darwin/amd64", "darwin/arm64",
+                       "windows/amd64", "windows/386", "windows/arm64":
+                       return true
+               }
+               return false
+
+       case "default":
+               return true
+
+       case "exe":
+               return true
+
+       case "pie":
+               switch platform {
+               case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x",
+                       "android/amd64", "android/arm", "android/arm64", "android/386",
+                       "freebsd/amd64",
+                       "darwin/amd64", "darwin/arm64",
+                       "ios/amd64", "ios/arm64",
+                       "aix/ppc64",
+                       "windows/386", "windows/amd64", "windows/arm", "windows/arm64":
+                       return true
+               }
+               return false
+
+       case "shared":
+               switch platform {
+               case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x":
+                       return true
+               }
+               return false
+
+       case "plugin":
+               switch platform {
+               case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",
+                       "android/amd64", "android/386",
+                       "darwin/amd64", "darwin/arm64",
+                       "freebsd/amd64":
+                       return true
+               }
+               return false
+
+       default:
+               return false
+       }
+}
+
 // isUnsupportedVMASize reports whether the failure is caused by an unsupported
 // VMA for the race detector (for example, running the race detector on an
 // arm64 machine configured with 39-bit VMA)
index 4c75b1d849b0c5eebcee0b85b6e21c041909bcce..71bf1c54771a3677738420f529dbfa056c63737b 100644 (file)
@@ -88,6 +88,7 @@ func MustLinkExternal(goos, goarch string) bool {
 
 // BuildModeSupported reports whether goos/goarch supports the given build mode
 // using the given compiler.
+// There is a copy of this function in cmd/dist/test.go.
 func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
        if compiler == "gccgo" {
                return true