|
| 1 | +name := "compiler-builtins" |
| 2 | +# Override these environment variables to test against a fork |
| 3 | +upstream_repo := env("UPSTREAM_ORG", "rust-lang") + "/rust" |
| 4 | +upstream_ref := env("UPSTREAM_REF", "HEAD") |
| 5 | +upstream_url := "https://github.com/" + upstream_repo |
| 6 | + |
| 7 | +josh_port := "42042" |
| 8 | +josh_filter := ":/library/compiler-builtins" |
| 9 | +josh_url_base := "http://localhost:" + josh_port |
| 10 | +josh_cache_dir := cache_directory() / "rust-lang.compiler-builtins-josh" |
| 11 | + |
| 12 | +export JUST_EXECUTABLE := just_executable() |
| 13 | + |
| 14 | +# Macro to set traps then launch Josh |
| 15 | +start_josh := """ |
| 16 | + # Trap on shell exit or failure |
| 17 | + trap 'exit $EXIT_CODE' INT TERM |
| 18 | + trap 'EXIT_CODE=$?; kill 0' EXIT |
| 19 | +
|
| 20 | + RUST_LOG="${RUST_LOG:-info}" $JUST_EXECUTABLE start-josh & |
| 21 | + $JUST_EXECUTABLE _ensure-josh-running |
| 22 | +""" |
| 23 | + |
| 24 | +# TODO make these messages better |
| 25 | +update_version_msg := """ |
| 26 | + Preparing for merge from rustc |
| 27 | +""" |
| 28 | +rustc_to_builtins_msg := """ |
| 29 | + Merge from rustc |
| 30 | +""" |
| 31 | + |
| 32 | +default: |
| 33 | + just --list |
| 34 | + |
| 35 | +# Exit with failure if the working directory has uncommitted files |
| 36 | +_ensure-clean: |
| 37 | + #!/bin/bash |
| 38 | + set -eaxo pipefail |
| 39 | + if [ -n "$(git status --untracked-files=no --porcelain)" ]; then |
| 40 | + echo "working directory must be clean" |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + |
| 44 | +# Make sure Josh is reachable. |
| 45 | +_ensure-josh-running: |
| 46 | + #!/bin/bash |
| 47 | + set -eaxo pipefail |
| 48 | + for _ in $(seq 1 100); do |
| 49 | + sleep 0.01s |
| 50 | + |
| 51 | + # Exit with success if we can connect to the port |
| 52 | + if nc -z 127.0.0.1 "{{ josh_port }}"; then |
| 53 | + exit |
| 54 | + fi |
| 55 | + done |
| 56 | + |
| 57 | + echo "Even after waiting for 1s, josh-proxy is still not available." |
| 58 | + exit 1 |
| 59 | + |
| 60 | +# Launch Josh, for running commands manually |
| 61 | +start-josh: |
| 62 | + josh-proxy --local '{{ josh_cache_dir }}' \ |
| 63 | + --remote 'https://github.com' \ |
| 64 | + --port '{{ josh_port }}' \ |
| 65 | + --no-background |
| 66 | + |
| 67 | +# Update this repo with changes from rust-lang/rust |
| 68 | +rustc-pull: _ensure-clean |
| 69 | + #!/bin/bash |
| 70 | + set -eaxo pipefail |
| 71 | + |
| 72 | + commit="$(git ls-remote "{{ upstream_url }}" "{{ upstream_ref }}" | awk '{ print $1 }')" |
| 73 | + josh_url="{{ josh_url_base }}/{{ upstream_repo }}.git@${commit}{{ josh_filter }}.git" |
| 74 | + |
| 75 | + {{ start_josh }} |
| 76 | + |
| 77 | + previous_base_commit="$(cat rust-version)" |
| 78 | + if [ "$previous_base_commit" = "$commit" ]; then |
| 79 | + echo "Nothing to pull; commit at $commit" |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | + |
| 83 | + orig_head="$(git rev-parse HEAD)" |
| 84 | + echo "$commit" > "rust-version" |
| 85 | + git commit rust-version --no-verify -m '{{ update_version_msg }}' |
| 86 | + |
| 87 | + if ! git fetch "$josh_url"; then |
| 88 | + echo "FAILED to fetch new commits, something went wrong." |
| 89 | + git reset --hard "$orig_head" |
| 90 | + echo "(committing the rust-version file has been undone)" |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + |
| 94 | + num_roots_before="$(git rev-list HEAD --max-parents=0 --count)" |
| 95 | + sha="$(git rev-parse HEAD)" |
| 96 | + git merge FETCH_HEAD --no-verify --no-ff -m '{{ rustc_to_builtins_msg }}' |
| 97 | + new_sha="$(git rev-parse HEAD)" |
| 98 | + |
| 99 | + if [ "$sha" = "$new_sha" ]; then |
| 100 | + git reset --hard "$orig_head" |
| 101 | + echo "No merge was performed, no changes to pull were found. Rolled back the preparation commit." |
| 102 | + exit 1 |
| 103 | + fi |
| 104 | + |
| 105 | + num_roots="$(git rev-list HEAD --max-parents=0 --count)" |
| 106 | + |
| 107 | + if [ "$num_roots" -ne "$num_roots_before" ]; then |
| 108 | + echo "Josh created a new root commit. This is probably not the history you want." |
| 109 | + exit 1 |
| 110 | + fi |
| 111 | + |
| 112 | +# Create a pull request to rust-lang/rust with changes from this repo |
| 113 | +rustc-push github_user branch="update-builtins": _ensure-clean |
| 114 | + #!/bin/bash |
| 115 | + set -eaxo pipefail |
| 116 | + |
| 117 | + base="$(cat rust-version)" |
| 118 | + branch="{{ branch }}" |
| 119 | + github_user="{{ github_user }}" |
| 120 | + josh_url="{{ josh_url_base }}/{{ github_user }}/rust.git{{ josh_filter }}.git" |
| 121 | + user_rust_url= "[email protected]:{{ github_user }}/rust.git" |
| 122 | + |
| 123 | + if [ -z "$RUSTC_GIT" ]; then |
| 124 | + echo "The RUSTC_GIT environment variable must be set" |
| 125 | + exit 1 |
| 126 | + fi |
| 127 | + |
| 128 | + {{ start_josh }} |
| 129 | + |
| 130 | + ( |
| 131 | + # Execute in the rustc directory |
| 132 | + cd "$RUSTC_GIT" |
| 133 | + |
| 134 | + echo "Preparing $github_user/rust (base: $base)..." |
| 135 | + |
| 136 | + if git fetch "$user_rust_url" "$branch" > /dev/null 2>&1; then |
| 137 | + echo "The branch '$branch' seems to already exist in '$user_rust_url'. \ |
| 138 | + Please delete it and try again." |
| 139 | + exit 1 |
| 140 | + fi |
| 141 | + |
| 142 | + git fetch "https://github.com/{{ upstream_repo }}" "$base" |
| 143 | + git push "$user_rust_url" "$base:refs/heads/$branch" --no-verify |
| 144 | + ) |
| 145 | + |
| 146 | + # Do the actual push. |
| 147 | + echo "Pushing changes..." |
| 148 | + git push "$josh_url" "HEAD:$branch" |
| 149 | + |
| 150 | + # Do a round-trip check to make sure the push worked as expected |
| 151 | + git fetch "$josh_url" "$branch" |
| 152 | + head="$(git rev-parse HEAD)" |
| 153 | + fetch_head="$(git rev-parse FETCH_HEAD)" |
| 154 | + |
| 155 | + if [ "$head" != "$fetch_head" ]; then |
| 156 | + echo "Josh created a non-roundtrip push! Do NOT merge this into rustc!" |
| 157 | + echo "Expected '$head', got '$fetch_head'." |
| 158 | + exit 1 |
| 159 | + fi |
| 160 | + |
| 161 | + echo "Confirmed that the push round-trips back to {{ name }} properly. Please create a rustc PR:" |
| 162 | + # Open PR with `subtree update` title to silence the `no-merges` triagebot check |
| 163 | + echo " {{ upstream_url }}/compare/$github_user:$branch?quick_pull=1&title=rustc-dev-guide+subtree+update&body=r?+@ghost" |
0 commit comments