mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +00:00
cmd/tsconnect: find the build dir independently of -trimpath
trimmed builds don't have absolute path information in executable metadata, which leads the runtime.Caller approach failing mysteriously in yarn with complaints about relative package paths. So, instead of using embedded package metadata to find paths, expect that we're being invoked within the tailscale repo, and locate the tsconnect directory that way. Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
f9b746846f
commit
0b8f89c79c
@ -28,10 +28,13 @@ const (
|
||||
func commonSetup(dev bool) (*esbuild.BuildOptions, error) {
|
||||
// Change cwd to to where this file lives -- that's where all inputs for
|
||||
// esbuild and other build steps live.
|
||||
if _, filename, _, ok := runtime.Caller(0); ok {
|
||||
if err := os.Chdir(path.Dir(filename)); err != nil {
|
||||
return nil, fmt.Errorf("Cannot change cwd: %w", err)
|
||||
}
|
||||
root, err := findRepoRoot()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tsConnectDir := filepath.Join(root, "cmd", "tsconnect")
|
||||
if err := os.Chdir(tsConnectDir); err != nil {
|
||||
return nil, fmt.Errorf("Cannot change cwd: %w", err)
|
||||
}
|
||||
if err := installJSDeps(); err != nil {
|
||||
return nil, fmt.Errorf("Cannot install JS deps: %w", err)
|
||||
@ -67,6 +70,22 @@ func commonSetup(dev bool) (*esbuild.BuildOptions, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func findRepoRoot() (string, error) {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
for {
|
||||
if _, err := os.Stat(path.Join(cwd, "go.mod")); err == nil {
|
||||
return cwd, nil
|
||||
}
|
||||
if cwd == "/" {
|
||||
return "", fmt.Errorf("Cannot find repo root")
|
||||
}
|
||||
cwd = path.Dir(cwd)
|
||||
}
|
||||
}
|
||||
|
||||
func commonPkgSetup(dev bool) (*esbuild.BuildOptions, error) {
|
||||
buildOptions, err := commonSetup(dev)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user