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 20, 2023
1 parent defdd31 commit bc0aa27
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion build/bazelutil/stamp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ else
shift 1
fi

BUILD_REV=$(git describe --match="" --always --abbrev=40 --dirty)
BUILD_REV=$(git describe --match="" --always --abbrev=40)
if [[ -n "$(git status -s --ignore-submodules --untracked-files=no)" ]]; then
BUILD_REV=$BUILD_REV-dirty
fi

BUILD_UTCTIME=$(date -u '+%Y/%m/%d %H:%M:%S')


Expand Down
13 changes: 13 additions & 0 deletions pkg/cmd/dev/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ func (d *dev) getDockerRunArgs(
} else {
args = append(args, "-i")
}
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) {
mountPath := strings.TrimSpace(string(gitCommonDir))
args = append(args, "-v", mountPath+":"+mountPath)
}
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")
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/dev/testdata/recorderdriven/builder
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ id
bazel info workspace --color=no
cat crdb-checkout/build/.bazelbuilderversion
docker volume inspect bzlhome
git rev-parse --git-dir
git rev-parse --git-common-dir
mkdir crdb-checkout/artifacts
docker run --rm -it -v crdb-checkout:/cockroach --workdir=/cockroach -v crdb-checkout/build/bazelutil/empty.bazelrc:/cockroach/.bazelrc.user -v crdb-checkout/artifacts:/artifacts -v bzlhome:/home/roach:delegated -u 502:502 cockroachdb/bazel:20220328-163955

Expand All @@ -15,5 +17,7 @@ id
bazel info workspace --color=no
cat crdb-checkout/build/.bazelbuilderversion
docker volume inspect bzlhome
git rev-parse --git-dir
git rev-parse --git-common-dir
mkdir crdb-checkout/artifacts
docker run --rm -i -v crdb-checkout:/cockroach --workdir=/cockroach -v crdb-checkout/build/bazelutil/empty.bazelrc:/cockroach/.bazelrc.user -v crdb-checkout/artifacts:/artifacts -v bzlhome:/home/roach:delegated -u 502:502 cockroachdb/bazel:20220328-163955 echo hi
12 changes: 12 additions & 0 deletions pkg/cmd/dev/testdata/recorderdriven/builder.rec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ docker volume inspect bzlhome
}
]

git rev-parse --git-dir
----

git rev-parse --git-common-dir
----

mkdir crdb-checkout/artifacts
----

Expand Down Expand Up @@ -62,6 +68,12 @@ docker volume inspect bzlhome
}
]

git rev-parse --git-dir
----

git rev-parse --git-common-dir
----

mkdir crdb-checkout/artifacts
----

Expand Down

0 comments on commit bc0aa27

Please sign in to comment.