Skip to content

Commit 28080ae

Browse files
authored
Merge pull request #1872 from EliahKagan/run-ci/workflow-readability
Clarify `pure-rust-build` cc1 wrapping
2 parents f58897d + 69582a4 commit 28080ae

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

.github/workflows/ci.yml

+31-8
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
)
3939
apt-get update
4040
apt-get install --no-install-recommends -y -- "${prerequisites[@]}"
41-
shell: bash
41+
shell: bash # This step needs `bash`, and the default in container jobs is `sh`.
4242
- name: Verify that we are in an environment with limited dev tools
4343
run: |
4444
set -x
@@ -70,31 +70,55 @@ jobs:
7070
! grep -qP '(?<!\blinux-raw)-sys\b' tree.txt
7171
- name: Wrap cc1 (and cc1plus if present) to record calls
7272
run: |
73+
set -o noclobber # Catch any collisions with existing entries in /usr/local.
74+
75+
# Define the wrapper script for a compiler driver (for cc1 or cc1plus). This wrapper
76+
# records calls, then delegates to the executable it wraps. When recording calls, writes
77+
# to the log are synchronized so fragments of separate log entries aren't interleaved,
78+
# even in concurrent runs. This wrapper knows what executable it is wrapping because,
79+
# when deployed, this wrapper (or a symlink) replaces that executable, which will itself
80+
# have been moved aside by being renamed with a `.orig` suffix, so this can call it.
7381
cat >/usr/local/bin/wrapper1 <<'EOF'
74-
#!/bin/sh -e
82+
#!/bin/sh
83+
set -e
7584
printf '%s\n' "$0 $*" |
7685
flock /run/lock/wrapper1.fbd136bd-9b1b-448d-84a9-e18be53ae63c.lock \
7786
tee -a -- /var/log/wrapper1.log ~/display >/dev/null # We'll link ~/display later.
7887
exec "$0.orig" "$@"
7988
EOF
8089
90+
# Define the script that performs the wrapping. This script shall be run once for each
91+
# executable to be wrapped, renaming it with a `.orig` suffix and replacing it with a
92+
# symlink to the wrapper script, defined above.
8193
cat >/usr/local/bin/wrap1 <<'EOF'
82-
#!/bin/sh -e
94+
#!/bin/sh
95+
set -e
8396
dir="$(dirname -- "$1")"
8497
base="$(basename -- "$1")"
8598
cd -- "$dir"
8699
mv -- "$base" "$base.orig"
87100
ln -s -- /usr/local/bin/wrapper1 "$base"
88101
EOF
89102
90-
chmod +x /usr/local/bin/wrap1 /usr/local/bin/wrapper1
103+
# Define a helper file that, when sourced, wires up the `~/display` symlink `wrapper1`
104+
# uses to report calls as GitHub Actions step output (in addition to writing them to a
105+
# log file). This is needed because stdout and stderr are both redirected elsewhere when
106+
# the wrapper actually runs, and `/dev/tty` is not usable. This must be sourced in the
107+
# same step as the `cargo` command that causes wrapped executables to be run, because
108+
# different steps write to different pipe objects. (This also needs the shell that
109+
# sourced it to remain running. But that is not the cause of the underlying limitation.)
110+
cat >/usr/local/bin/set-display.sh <<'EOF'
111+
ln -s -- "/proc/$$/fd/1" ~/display
112+
EOF
113+
114+
chmod +x /usr/local/bin/wrapper1 /usr/local/bin/wrap1
91115
mkdir /run/lock/wrapper1.fbd136bd-9b1b-448d-84a9-e18be53ae63c.lock
92116
93117
find /usr/lib/gcc \( -name cc1 -o -name cc1plus \) \
94118
-print -exec /usr/local/bin/wrap1 {} \;
95119
- name: Build max-pure with limited dev tools and log cc1
96120
run: |
97-
ln -s -- "/proc/$$/fd/1" ~/display # Bypass `cc1` redirection.
121+
. /usr/local/bin/set-display.sh
98122
cargo install --debug --locked --no-default-features --features max-pure --path .
99123
- name: Show logged C and C++ compilations (should be none)
100124
run: |
@@ -226,7 +250,6 @@ jobs:
226250
- name: Compare expected and actual failures
227251
run: |
228252
# Fail on any differences, even unexpectedly passing tests, so they can be investigated.
229-
# (If the job is made blocking for PRs, it may make sense to make this less stringent.)
230253
git --no-pager diff --no-index --exit-code --unified=1000000 --color=always -- `
231254
etc/test-fixtures-windows-expected-failures-see-issue-1358.txt actual-failures.txt
232255
@@ -265,7 +288,7 @@ jobs:
265288
dpkg --add-architecture ${{ matrix.runner-arch }}
266289
apt-get update
267290
apt-get install --no-install-recommends -y -- "${prerequisites[@]}"
268-
shell: bash
291+
shell: bash # This step needs `bash`, and the default in container jobs is `sh`.
269292
- uses: actions/checkout@v4
270293
- name: Install Rust via Rustup
271294
run: |
@@ -428,7 +451,7 @@ jobs:
428451
429452
defaults:
430453
run:
431-
shell: bash # Without specifying this, we don't get `-o pipefail`.
454+
shell: bash # Without this, the shell here is `bash` but without `-o pipefail`.
432455

433456
steps:
434457
- name: Find this workflow

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ permissions:
1717

1818
defaults:
1919
run:
20-
shell: bash
20+
shell: bash # Use `bash` even in the Windows jobs.
2121

2222
jobs:
2323
# Create a draft release, initially with no binary assets attached.

0 commit comments

Comments
 (0)