|
9 | 9 | export RUSTDOCFLAGS='-A rustdoc::broken-intra-doc-links' |
10 | 10 | REPO_DIR=$(git rev-parse --show-toplevel) |
11 | 11 | API_DIR="$REPO_DIR/api" |
12 | | -CMD="cargo +nightly public-api --simplified" |
| 12 | +CARGO="cargo +nightly public-api --simplified" |
13 | 13 | # `sort -n -u` doesn't work for some reason. |
14 | 14 | SORT="sort --numeric-sort" |
15 | 15 |
|
16 | | -# cargo public-api uses nightly so the toolchain must be available. |
17 | | -if ! cargo +nightly --version > /dev/null; then |
18 | | - echo "script requires a nightly toolchain to be installed (possibly >= nightly-2023-05-24)" >&2 |
19 | | - exit 1 |
20 | | -fi |
21 | | - |
22 | | -pushd "$REPO_DIR" > /dev/null |
23 | | -$CMD --no-default-features | $SORT | uniq > "$API_DIR/no-default-features.txt" |
24 | | -$CMD | $SORT | uniq > "$API_DIR/default-features.txt" |
25 | | -$CMD --no-default-features --features=alloc | $SORT | uniq > "$API_DIR/alloc.txt" |
26 | | -$CMD --no-default-features --features=core2 | $SORT | uniq > "$API_DIR/core2.txt" |
27 | | -$CMD --all-features | $SORT | uniq > "$API_DIR/all-features.txt" |
28 | | - |
29 | | -if [[ $(git status --porcelain api) ]]; then |
30 | | - echo "You have introduced changes to the public API, commit the changes to api/ currently in your working directory" >&2 |
| 16 | +main() { |
| 17 | + # cargo public-api uses nightly so the toolchain must be available. |
| 18 | + if ! cargo +nightly --version > /dev/null; then |
| 19 | + echo "script requires a nightly toolchain to be installed (possibly >= nightly-2023-05-24)" >&2 |
| 20 | + exit 1 |
| 21 | + fi |
| 22 | + |
| 23 | + generate_api_files |
| 24 | + check_for_changes |
| 25 | +} |
| 26 | + |
| 27 | +generate_api_files() { |
| 28 | + pushd "$REPO_DIR" > /dev/null |
| 29 | + |
| 30 | + $CARGO | $SORT | uniq > "$API_DIR/default-features.txt" |
| 31 | + |
| 32 | + $CARGO --no-default-features | $SORT | uniq > "$API_DIR/no-default-features.txt" |
| 33 | + $CARGO --no-default-features --features=alloc | $SORT | uniq > "$API_DIR/alloc.txt" |
| 34 | + $CARGO --no-default-features --features=core2 | $SORT | uniq > "$API_DIR/core2.txt" |
| 35 | + |
| 36 | + $CARGO --all-features | $SORT | uniq > "$API_DIR/all-features.txt" |
| 37 | + |
31 | 38 | popd > /dev/null |
32 | | - exit 1 |
33 | | -else |
34 | | - echo "No changes to the current public API" |
| 39 | +} |
| 40 | + |
| 41 | +# Check if there are changes (dirty git index) to the `api/` directory. |
| 42 | +check_for_changes() { |
| 43 | + pushd "$REPO_DIR" > /dev/null |
| 44 | + |
| 45 | + if [[ $(git status --porcelain api) ]]; then |
| 46 | + git diff --color=always |
| 47 | + |
| 48 | + echo |
| 49 | + echo "You have introduced changes to the public API, commit the changes to api/ currently in your working directory" >&2 |
| 50 | + exit 1 |
| 51 | + |
| 52 | + else |
| 53 | + echo "No changes to the current public API" |
| 54 | + fi |
| 55 | + |
35 | 56 | popd > /dev/null |
36 | | -fi |
| 57 | +} |
37 | 58 |
|
| 59 | +# |
| 60 | +# Main script |
| 61 | +# |
| 62 | +main "$@" |
38 | 63 | exit 0 |
39 | | - |
|
0 commit comments