mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-06 23:56:53 +00:00
tool/gocross: break circular dependency on tailcfg (#15829)
Instead of using the version package (which depends on tailcfg.CurrentCapabilityVersion) to get the git commit hash, do it directly using debug.BuildInfo. This way, when changing struct fields in tailcfg, we can successfully `go generate` it without compiler errors. Updates #9634 Updates https://github.com/tailscale/corp/issues/26717 Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
This commit is contained in:
parent
cc6f367520
commit
a9b3e09a1f
@ -15,9 +15,9 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
|
||||
"tailscale.com/atomicfile"
|
||||
"tailscale.com/version"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -28,8 +28,19 @@ func main() {
|
||||
// any time.
|
||||
switch os.Args[1] {
|
||||
case "gocross-version":
|
||||
fmt.Println(version.GetMeta().GitCommit)
|
||||
os.Exit(0)
|
||||
bi, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
fmt.Fprintln(os.Stderr, "failed getting build info")
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, s := range bi.Settings {
|
||||
if s.Key == "vcs.revision" {
|
||||
fmt.Println(s.Value)
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, "did not find vcs.revision in build info")
|
||||
os.Exit(1)
|
||||
case "is-gocross":
|
||||
// This subcommand exits with an error code when called on a
|
||||
// regular go binary, so it can be used to detect when `go` is
|
||||
@ -85,9 +96,9 @@ func main() {
|
||||
path := filepath.Join(toolchain, "bin") + string(os.PathListSeparator) + os.Getenv("PATH")
|
||||
env.Set("PATH", path)
|
||||
|
||||
debug("Input: %s\n", formatArgv(os.Args))
|
||||
debug("Command: %s\n", formatArgv(newArgv))
|
||||
debug("Set the following flags/envvars:\n%s\n", env.Diff())
|
||||
debugf("Input: %s\n", formatArgv(os.Args))
|
||||
debugf("Command: %s\n", formatArgv(newArgv))
|
||||
debugf("Set the following flags/envvars:\n%s\n", env.Diff())
|
||||
|
||||
args = newArgv
|
||||
if err := env.Apply(); err != nil {
|
||||
@ -103,7 +114,7 @@ func main() {
|
||||
//go:embed gocross-wrapper.sh
|
||||
var wrapperScript []byte
|
||||
|
||||
func debug(format string, args ...any) {
|
||||
func debugf(format string, args ...any) {
|
||||
debug := os.Getenv("GOCROSS_DEBUG")
|
||||
var (
|
||||
out *os.File
|
||||
|
19
tool/gocross/gocross_test.go
Normal file
19
tool/gocross/gocross_test.go
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"tailscale.com/tstest/deptest"
|
||||
)
|
||||
|
||||
func TestDeps(t *testing.T) {
|
||||
deptest.DepChecker{
|
||||
BadDeps: map[string]string{
|
||||
"tailscale.com/tailcfg": "circular dependency via go generate",
|
||||
"tailscale.com/version": "circular dependency via go generate",
|
||||
},
|
||||
}.Check(t)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user