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