assert_ts_toolchain_match.go 944 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (c) Tailscale Inc & contributors
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. //go:build tailscale_go
  4. package tailscaleroot
  5. import (
  6. "fmt"
  7. "os"
  8. "strings"
  9. )
  10. func init() {
  11. tsRev, ok := tailscaleToolchainRev()
  12. if !ok {
  13. panic("binary built with tailscale_go build tag but failed to read build info or find tailscale.toolchain.rev in build info")
  14. }
  15. want := strings.TrimSpace(GoToolchainRev)
  16. if os.Getenv("TS_GO_NEXT") == "1" {
  17. want = strings.TrimSpace(GoToolchainNextRev)
  18. }
  19. if tsRev != want {
  20. if os.Getenv("TS_PERMIT_TOOLCHAIN_MISMATCH") == "1" {
  21. fmt.Fprintf(os.Stderr, "tailscale.toolchain.rev = %q, want %q; but ignoring due to TS_PERMIT_TOOLCHAIN_MISMATCH=1\n", tsRev, want)
  22. return
  23. }
  24. panic(fmt.Sprintf("binary built with tailscale_go build tag but Go toolchain %q doesn't match github.com/tailscale/tailscale expected value %q; override this failure with TS_PERMIT_TOOLCHAIN_MISMATCH=1", tsRev, want))
  25. }
  26. }