Commit 1db37d1
committed
Don't generate cargo metadata eagerly in justfile
- Have the `justfile` wait to run `cargo metadata` until it is
running a recipe that actually needs the information from it.
(Currently, that information is always the `target` directory
location, in whose `debug` subdirectory some binaries are found.)
This avoids a delay if `cargo metadata` has not run. The length
of the delay varied but was often noticeable on Windows. Because
running it again (in the absence of a clean or relevant change)
is cheap, it is not a performance problem that this runs the
command multiple times instead of once.
This also avoids error messages from `cargo metadata` if it can't
complete, unless it is actually being used. Those messages didn't
prevent other recipes (besides those that used the metadata) from
running. But they created the appearance of failure, and also
were misleading when they didn't come from the recipe being run.
- Handle errors from `cargo metadata` more robustly, by causing
recipes that actually need the result of `cargo metadata` to fail
if it fail -- and to fail immediately before attempting any other
operations -- rather than attempting to use empty data.
The metadata are piped to `jq -r .target_directory`, which
actually succeeds even if it doesn't receive any data, giving
empty output. Before, an attempt was made to use the empty output
in building paths meant to go to debug builds of some binaries.
Because the command is now running only when the output is
actually needed, it is fine to make it hard error when it fails.
The natural way to do this would be to `set -o pipefail`. But
while it is in the newest POSIX standard, there remain otherwise
largely POSIX-compatible `sh` implementations in use that don't
support it (koalaman/shellcheck#2555).
Our test suite requires `bash`, so the next obvious choice would
be to use a shebang recipe or script recipe for `bash`. The
problem is that shebang and script recipes don't usually work on
Windows, because `just` passes a Windows path with `\` separators
to the shell unquoted. This often results in the shell trying to
run a file whose name is transformed by treating them specially,
then causing them to dropped as if by quote removal. For example,
on a recipe named `hello` with a `#!/usr/bin/env bash` shebang:
/bin/bash: C:UsersekAppDataLocalTempjust-BVbCgphello: No such file or directory
(One way this happens is by argument processing in `cygwin1.dll`
or `msys-2.0.dll`, which seek to bridge the gap between the Unix
expectation that the caller is responsible for all expansions and
the Windows expectation that the callee is responsible for some.
See rust-lang/rust#82227. Even when
only globbing is attempted, `\` can be treated specially if it
seems to escape a wildcard, or to escape another `\` that seems
to escape a wildcard, etc.)
Fortunately, in this case we can just check if the result of
trying to parse out the `target` directory path gave a nonempty
result, and treat the failure to do that as a hard error.
- Remove the `check-mode` recipe's need for cargo metadata, by
having it run the `internal-tools` binary via `cargo run` rather
than looking up where the `target` directory is and finding `it`
in `debug` under it.
That approach is needed for the paths that are passed to the
journey test runner, but `check-mode` can just use `cargo`.
The preceding build command could be removed, since `cargo run`
builds unless the binary is up to date. But keeping them as
separate commands may make the output more readable.1 parent 892cd32 commit 1db37d1
1 file changed
+19
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | | - | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
191 | 193 | | |
192 | 194 | | |
193 | 195 | | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
199 | 203 | | |
200 | 204 | | |
201 | | - | |
| 205 | + | |
202 | 206 | | |
203 | 207 | | |
204 | | - | |
| 208 | + | |
205 | 209 | | |
206 | 210 | | |
207 | | - | |
| 211 | + | |
208 | 212 | | |
209 | 213 | | |
210 | | - | |
| 214 | + | |
211 | 215 | | |
212 | 216 | | |
213 | | - | |
| 217 | + | |
214 | 218 | | |
215 | 219 | | |
216 | | - | |
| 220 | + | |
217 | 221 | | |
218 | 222 | | |
219 | | - | |
| 223 | + | |
220 | 224 | | |
221 | 225 | | |
222 | | - | |
| 226 | + | |
223 | 227 | | |
224 | 228 | | |
225 | 229 | | |
| |||
260 | 264 | | |
261 | 265 | | |
262 | 266 | | |
263 | | - | |
| 267 | + | |
264 | 268 | | |
265 | 269 | | |
266 | 270 | | |
| |||
0 commit comments