Skip to content

Commit

Permalink
dev: fix cross builds running in git worktrees
Browse files Browse the repository at this point in the history
Beforehand, running a cross build inside a git worktree
would always fail. This PR adds code to also mount the
main git repo into docker when in a git worktree, so that
running cross builds will succeed.

Fixes: cockroachdb#110735
Release note: None
  • Loading branch information
Liam Gillies committed Sep 19, 2023
1 parent defdd31 commit fe1c131
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/cmd/dev/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,26 @@ func (d *dev) getDockerRunArgs(
} else {
args = append(args, "-i")
}
args = append(args, "-v", workspace+":/cockroach")
gitDir, err := d.exec.CommandContextSilent(ctx, "git", "rev-parse", "--git-dir")
if err != nil {
return nil, err
}
gitCommonDir, err := d.exec.CommandContextSilent(ctx, "git", "rev-parse", "--git-common-dir")
if err != nil {
return nil, err
}
// If run from inside a git worktree
if string(gitDir) != string(gitCommonDir) {
mainRepo, err := d.exec.CommandContextSilent(ctx, "cat", ".git")
if err != nil {
return nil, err
}
mountPath := strings.Split(strings.Split(string(mainRepo), ": ")[1], "/.git/")[0]
args = append(args, "-v", mountPath+":/cockroach")
args = append(args, "-v", workspace)
} else {
args = append(args, "-v", workspace+":/cockroach")
}
args = append(args, "--workdir=/cockroach")
args = append(args, "-v", filepath.Join(workspace, "build", "bazelutil", "empty.bazelrc")+":/cockroach/.bazelrc.user")
// Create the artifacts directory.
Expand Down

0 comments on commit fe1c131

Please sign in to comment.