Skip to content

Commit

Permalink
dev: symlink build --short result to cockroach
Browse files Browse the repository at this point in the history
This is what the Makefile does, and what folks expect.

Release note: None
  • Loading branch information
irfansharif committed Feb 11, 2022
1 parent 5c5d12f commit 9f90e98
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
36 changes: 21 additions & 15 deletions pkg/cmd/dev/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pkg/cmd/dev/testdata/datadriven/dev-build
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand All @@ -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
----
Expand All @@ -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
----
Expand All @@ -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
----
Expand Down

0 comments on commit 9f90e98

Please sign in to comment.