Skip to content

Commit ca34687

Browse files
committed
ci: move toolstates.json to /tmp/toolstate/ and docker mount it
Before this commit toolstates.json was stored in /tmp and it wasn't mounted outside the build container. That caused uploading the file in the upload-artifacts task to fail, as the file was missing on the host. Mounting /tmp/toolstates.json alone is not the best approach: if the file is missing when the container is started the Docker engine will create a *directory* named /tmp/toolstates.json. The Docker issue could be solved by pre-creating an empty file named /tmp/toolstates.json, but doing that could cause problems if bootstrap fails to generate the file and the toolstate scripts receive an empty JSON. The approach I took in this commit is to instead mount a /tmp/toolstate directory inside Docker, and create the toolstates.json file in it. That also required a small bootstrap change to ensure the directory is created if it's missing.
1 parent bdfcde4 commit ca34687

File tree

6 files changed

+13
-6
lines changed

6 files changed

+13
-6
lines changed

src/bootstrap/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,10 @@ impl Build {
10801080
/// done. The file is updated immediately after this function completes.
10811081
pub fn save_toolstate(&self, tool: &str, state: ToolState) {
10821082
if let Some(ref path) = self.config.save_toolstates {
1083+
if let Some(parent) = path.parent() {
1084+
// Ensure the parent directory always exists
1085+
t!(std::fs::create_dir_all(parent));
1086+
}
10831087
let mut file = t!(fs::OpenOptions::new()
10841088
.create(true)
10851089
.read(true)

src/ci/azure-pipelines/auto.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ jobs:
263263
# MSVC tools tests
264264
x86_64-msvc-tools:
265265
MSYS_BITS: 64
266-
SCRIPT: src/ci/docker/x86_64-gnu-tools/checktools.sh x.py /tmp/toolstates.json windows
267-
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --save-toolstates=/tmp/toolstates.json
266+
SCRIPT: src/ci/docker/x86_64-gnu-tools/checktools.sh x.py /tmp/toolstate/toolstates.json windows
267+
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --save-toolstates=/tmp/toolstate/toolstates.json
268268
DEPLOY_TOOLSTATES_JSON: toolstates-windows.json
269269

270270
# 32/64-bit MinGW builds.

src/ci/docker/run.sh

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ fi
106106
mkdir -p $HOME/.cargo
107107
mkdir -p $objdir/tmp
108108
mkdir -p $objdir/cores
109+
mkdir -p /tmp/toolstate
109110

110111
args=
111112
if [ "$SCCACHE_BUCKET" != "" ]; then
@@ -156,6 +157,7 @@ else
156157
args="$args --volume $objdir:/checkout/obj"
157158
args="$args --volume $HOME/.cargo:/cargo"
158159
args="$args --volume $HOME/rustsrc:$HOME/rustsrc"
160+
args="$args --volume /tmp/toolstate:/tmp/toolstate"
159161
args="$args --env LOCAL_USER_ID=`id -u`"
160162
fi
161163

src/ci/docker/x86_64-gnu-tools/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ ENV CHECK_LINKS 1
2626

2727
ENV RUST_CONFIGURE_ARGS \
2828
--build=x86_64-unknown-linux-gnu \
29-
--save-toolstates=/tmp/toolstates.json
30-
ENV SCRIPT /tmp/checktools.sh ../x.py /tmp/toolstates.json linux
29+
--save-toolstates=/tmp/toolstate/toolstates.json
30+
ENV SCRIPT /tmp/checktools.sh ../x.py /tmp/toolstate/toolstates.json linux

src/ci/docker/x86_64-gnu-tools/checktools.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -eu
44

55
X_PY="$1"
6-
TOOLSTATE_FILE="$(realpath $2)"
6+
TOOLSTATE_FILE="$(realpath -m $2)"
77
OS="$3"
88
COMMIT="$(git rev-parse HEAD)"
99
CHANGED_FILES="$(git diff --name-status HEAD HEAD^)"
@@ -13,6 +13,7 @@ SIX_WEEK_CYCLE="$(( ($(date +%s) / 86400 - 20) % 42 ))"
1313
# The Wednesday after this has value 0.
1414
# We track this value to prevent regressing tools in the last week of the 6-week cycle.
1515

16+
mkdir -p "$(dirname $TOOLSTATE_FILE)"
1617
touch "$TOOLSTATE_FILE"
1718

1819
# Try to test all the tools and store the build/test success in the TOOLSTATE_FILE

src/ci/scripts/upload-artifacts.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cp cpu-usage.csv "${upload_dir}/cpu-${CI_JOB_NAME}.csv"
2525

2626
# Toolstate data.
2727
if [[ -n "${DEPLOY_TOOLSTATES_JSON+x}" ]]; then
28-
cp /tmp/toolstates.json "${upload_dir}/${DEPLOY_TOOLSTATES_JSON}"
28+
cp /tmp/toolstate/toolstates.json "${upload_dir}/${DEPLOY_TOOLSTATES_JSON}"
2929
fi
3030

3131
echo "Files that will be uploaded:"

0 commit comments

Comments
 (0)