From 9f90e98995ab740bfceb1e7b261738fdf4950506 Mon Sep 17 00:00:00 2001 From: irfan sharif Date: Thu, 10 Feb 2022 18:02:07 -0500 Subject: [PATCH] dev: symlink build --short result to `cockroach` This is what the Makefile does, and what folks expect. Release note: None --- pkg/cmd/dev/build.go | 36 +++++++++++++---------- pkg/cmd/dev/testdata/datadriven/dev-build | 8 +++++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/pkg/cmd/dev/build.go b/pkg/cmd/dev/build.go index cb36b7eb2cf5..9fa3f2b381dd 100644 --- a/pkg/cmd/dev/build.go +++ b/pkg/cmd/dev/build.go @@ -202,11 +202,14 @@ func (d *dev) stageArtifacts(ctx context.Context, targets []buildTarget) error { } binaryPath := filepath.Join(bazelBin, bazelutil.OutputOfBinaryRule(target.fullName, runtime.GOOS == "windows")) base := targetToBinBasename(target.fullName) - var symlinkPath string + var symlinkPaths []string // Binaries beginning with the string "cockroach" go right at // the top of the workspace; others go in the `bin` directory. if strings.HasPrefix(base, "cockroach") { - symlinkPath = filepath.Join(workspace, base) + symlinkPaths = append(symlinkPaths, filepath.Join(workspace, base)) + if strings.HasPrefix(base, "cockroach-short") { + symlinkPaths = append(symlinkPaths, filepath.Join(workspace, "cockroach")) + } } else if base == "dev" { buf, err := d.os.ReadFile(filepath.Join(workspace, "dev")) if err != nil { @@ -222,23 +225,26 @@ func (d *dev) stageArtifacts(ctx context.Context, targets []buildTarget) error { return errors.New("could not find DEV_VERSION in top-level `dev` script") } - symlinkPath = filepath.Join(workspace, "bin", "dev-versions", fmt.Sprintf("dev.%s", devVersion)) + symlinkPaths = append(symlinkPaths, + filepath.Join(workspace, "bin", "dev-versions", fmt.Sprintf("dev.%s", devVersion))) } else { - symlinkPath = filepath.Join(workspace, "bin", base) + symlinkPaths = append(symlinkPaths, filepath.Join(workspace, "bin", base)) } - // Symlink from binaryPath -> symlinkPath - if err := d.os.Remove(symlinkPath); err != nil && !os.IsNotExist(err) { - return err - } - if err := d.os.Symlink(binaryPath, symlinkPath); err != nil { - return err - } - rel, err := filepath.Rel(workspace, symlinkPath) - if err != nil { - rel = symlinkPath + // Symlink from binaryPath -> symlinkPath, clear out detritus, if any. + for _, symlinkPath := range symlinkPaths { + if err := d.os.Remove(symlinkPath); err != nil && !os.IsNotExist(err) { + return err + } + if err := d.os.Symlink(binaryPath, symlinkPath); err != nil { + return err + } + rel, err := filepath.Rel(workspace, symlinkPath) + if err != nil { + rel = symlinkPath + } + log.Printf("Successfully built binary for target %s at %s", target.fullName, rel) } - log.Printf("Successfully built binary for target %s at %s", target.fullName, rel) } shouldHoist := false diff --git a/pkg/cmd/dev/testdata/datadriven/dev-build b/pkg/cmd/dev/testdata/datadriven/dev-build index ab478ffe4598..93fb584f3510 100644 --- a/pkg/cmd/dev/testdata/datadriven/dev-build +++ b/pkg/cmd/dev/testdata/datadriven/dev-build @@ -6,6 +6,8 @@ mkdir bin bazel info bazel-bin --color=no rm cockroach-short ln -s pkg/cmd/cockroach-short/cockroach-short_/cockroach-short cockroach-short +rm cockroach +ln -s pkg/cmd/cockroach-short/cockroach-short_/cockroach-short cockroach dev build cockroach-short --cpus=12 --skip-generate ---- @@ -15,6 +17,8 @@ mkdir bin bazel info bazel-bin --color=no rm cockroach-short ln -s pkg/cmd/cockroach-short/cockroach-short_/cockroach-short cockroach-short +rm cockroach +ln -s pkg/cmd/cockroach-short/cockroach-short_/cockroach-short cockroach dev build --debug short --skip-generate ---- @@ -24,6 +28,8 @@ mkdir bin bazel info bazel-bin --color=no rm cockroach-short ln -s pkg/cmd/cockroach-short/cockroach-short_/cockroach-short cockroach-short +rm cockroach +ln -s pkg/cmd/cockroach-short/cockroach-short_/cockroach-short cockroach dev build short --skip-generate -- -s ---- @@ -33,6 +39,8 @@ mkdir bin bazel info bazel-bin --color=no rm cockroach-short ln -s pkg/cmd/cockroach-short/cockroach-short_/cockroach-short cockroach-short +rm cockroach +ln -s pkg/cmd/cockroach-short/cockroach-short_/cockroach-short cockroach dev build --skip-generate -- --verbose_failures --sandbox_debug ----