Skip to content

Commit 01c7b0e

Browse files
committed
Clarify pure-rust-build cc1 wrapping
This adds comments, and also refactors, to make these steps of the `pure-rust-build` CI job more readable, and to make clearer what the wrapping does and how it works: - "Wrap cc1 (and cc1plus if present) to record calls" - "Build max-pure with limited dev tools and log cc1" The logic clarified here was introduced in #1682. The clarification is mainly through these two changes: - Document each of the scripts the steps create and use with an explanatory comment above the "stanza" of code that creates it. - Extract the command to create the `~/display` symlink to such a script, which also has such a comment to explain the effect of writing to that symlink, why it is needed, and why it has to be set in the same GitHub Actions step as the related `cargo` command. Two other less significant clarifcations are made, which arguably are not refactorings in that they could change the behavior (for the better) in some hypothetical situations, but the goal is clarity rather than a behavioral change: - In the scripts that had more than one non-shebang line, take `-e` out of the shebangs and use a `set -e` commmand. This makes no difference in how the scripts are used, since they are always executed directoy. But may make them easier to read, as readers need not check that they are only run in this way to verify their understanding of what they do. - Set `noclobber` in the step that uses `>` to create the script files in `/usr/local`, so that if they somehow clash with files already there, we get an error rather than proceeding and maybe having them called in unantiicpated ways. The likelihood this would happen on a GHA runner is very low, so the real impact of this change is to make immediately clear to readers that the scripts and their names do not have a pre-defined meaning but are instead simply helpers for these GHA steps.
1 parent ab47769 commit 01c7b0e

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

.github/workflows/ci.yml

+29-4
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,56 @@ 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 script that wires up the `~/display` symlink that `wrapper1` uses to report
104+
# calls as GitHub Actions step output (in addition to writing them to a log file). This
105+
# is needed because stdout and stderr are both redirected elsewhere when the wrapper
106+
# actually runs, and `/dev/tty` is not usable. This script must be run in the same step
107+
# as the `cargo` command that causes wrapped executables to be run, because different
108+
# steps write to different pipe objects. (As implemented, this also needs the calling
109+
# shell to remain running, but that is not the cause of the underlying limitation.)
110+
cat >/usr/local/bin/set-display <<'EOF'
111+
#!/bin/sh
112+
ln -s -- "/proc/$$/fd/1" ~/display
113+
EOF
114+
115+
chmod +x /usr/local/bin/wrapper1 /usr/local/bin/wrap1 /usr/local/bin/set-display
91116
mkdir /run/lock/wrapper1.fbd136bd-9b1b-448d-84a9-e18be53ae63c.lock
92117
93118
find /usr/lib/gcc \( -name cc1 -o -name cc1plus \) \
94119
-print -exec /usr/local/bin/wrap1 {} \;
95120
- name: Build max-pure with limited dev tools and log cc1
96121
run: |
97-
ln -s -- "/proc/$$/fd/1" ~/display # Bypass `cc1` redirection.
122+
/usr/local/bin/set-display
98123
cargo install --debug --locked --no-default-features --features max-pure --path .
99124
- name: Show logged C and C++ compilations (should be none)
100125
run: |

0 commit comments

Comments
 (0)