|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euxo pipefail |
| 3 | + |
| 4 | +# This script creates a fresh temporary clone of the DMD repo and rewrites |
| 5 | +# it (via `git filter-repo`) according to LDC requirements (removing |
| 6 | +# unnecessary files and transforming the directory structure). |
| 7 | +# Then it pushes new tags and updated master/stable branches (all prefixed |
| 8 | +# with `dmd-rewrite-`) to the LDC repo, i.e., the rewritten updates to |
| 9 | +# the DMD repo since the last successful script invocation. |
| 10 | +# |
| 11 | +# Afterwards, merging a new frontend+druntime is a matter of merging branch |
| 12 | +# `dmd-rewrite-stable` or some tag (`dmd-rewrite-v2.101.0`). |
| 13 | + |
| 14 | +initialize="${INITIALIZE:-0}" # set INITIALIZE=1 for the very first rewrite |
| 15 | +refs_prefix="dmd-rewrite-" |
| 16 | + |
| 17 | +temp_dir="$(mktemp -d)" |
| 18 | +cd "$temp_dir" |
| 19 | + |
| 20 | +# generate message-filters.txt file for replacing GitHub refs in commit messages |
| 21 | +echo 'regex:(^|\s|\()#(\d{2,})==>\1dlang/dmd!\2' > message-filters.txt |
| 22 | + |
| 23 | +# clone DMD monorepo |
| 24 | +git clone [email protected]:dlang/dmd.git dmd.tmp |
| 25 | +cd dmd.tmp |
| 26 | + |
| 27 | +# only for initialization: |
| 28 | +# merge LDC druntime patches (tag: first-merged-dmd-druntime-with-ldc-druntime-patches) |
| 29 | +if [[ "$initialize" == 1 ]]; then |
| 30 | + git checkout -b ldc-tmp first-merged-dmd-druntime --no-track |
| 31 | + git subtree pull --prefix druntime [email protected]:ldc-developers/druntime.git ldc-pre-monorepo -m "Merge LDC pre-monorepo druntime patches" |
| 32 | + git tag first-merged-dmd-druntime-with-ldc-druntime-patches |
| 33 | +fi |
| 34 | + |
| 35 | +# extract a subset of the dmd monorepo (druntime source + tests + Makefiles, dmd source + tests + osmodel.mak) |
| 36 | +git filter-repo --force \ |
| 37 | + --path druntime/src --path druntime/test --path-glob 'druntime/*.mak' \ |
| 38 | + --path compiler/src/dmd --path compiler/test --path compiler/src/osmodel.mak \ |
| 39 | + --path src --path test # required to keep git history before upstream druntime-merge (and associated directory movals) |
| 40 | +# remove unused files |
| 41 | +git filter-repo --invert-paths \ |
| 42 | + --path-regex '(compiler/)?src/dmd/backend' \ |
| 43 | + --path-regex '(compiler/)?src/dmd/root/(env|response|strtold)\.d' \ |
| 44 | + --path-regex '(compiler/)?src/dmd/astbase\.d' \ |
| 45 | + --path-regex '(compiler/)?src/dmd/cpreprocess\.d' \ |
| 46 | + --path-regex '(compiler/)?src/dmd/dinifile\.d' \ |
| 47 | + --path-regex '(compiler/)?src/dmd/dmdparams\.d' \ |
| 48 | + --path-regex '(compiler/)?src/dmd/dmsc\.d' \ |
| 49 | + --path-regex '(compiler/)?src/dmd/eh\.d' \ |
| 50 | + --path-regex '(compiler/)?src/dmd/frontend\.d' \ |
| 51 | + --path-regex '(compiler/)?src/dmd/scan(elf|mach|mscoff|omf)\.d' \ |
| 52 | + --path-regex '(compiler/)?src/dmd/lib(|elf|mach|mscoff|omf)\.d' \ |
| 53 | + --path-regex '(compiler/)?src/dmd/link\.d' \ |
| 54 | + --path-regex '(compiler/)?src/dmd/(e|s)2ir\.d' \ |
| 55 | + --path-regex '(compiler/)?src/dmd/to(csym|ctype|cvdebug|dt|ir|obj)\.d' \ |
| 56 | + --path-regex '(compiler/)?src/dmd/iasm(|dmd)\.d' \ |
| 57 | + --path-regex '(compiler/)?src/dmd/(objc_)?glue\.d' \ |
| 58 | + --path-glob 'src/*.mak' # remaining Makefiles after moving dmd into compiler/ |
| 59 | +git filter-repo \ |
| 60 | + `# move dirs/files` \ |
| 61 | + --path-rename druntime/:runtime/druntime/ \ |
| 62 | + --path-rename compiler/src/dmd/:dmd/ \ |
| 63 | + --path-rename compiler/test/:tests/dmd/ \ |
| 64 | + --path-rename compiler/src/osmodel.mak:dmd/osmodel.mak \ |
| 65 | + `# prefix tags` \ |
| 66 | + --tag-rename ":$refs_prefix" \ |
| 67 | + `# replace GitHub refs in commit messages` \ |
| 68 | + --replace-message ../message-filters.txt |
| 69 | + |
| 70 | +# create prefixed master/stable branches |
| 71 | +git branch --no-track "${refs_prefix}master" master |
| 72 | +git branch --no-track "${refs_prefix}stable" stable |
| 73 | + |
| 74 | +# add LDC repo as `ldc` remote |
| 75 | +git remote add ldc [email protected]:ldc-developers/ldc.git |
| 76 | + |
| 77 | +# check for newly added DMD source files |
| 78 | +if [[ "$initialize" != 1 ]]; then |
| 79 | + git fetch ldc "${refs_prefix}master" |
| 80 | + numFiles="$(git diff --name-only --diff-filter=A --relative=dmd "ldc/${refs_prefix}master..${refs_prefix}master" | wc -l)" |
| 81 | + if [[ "$numFiles" != 0 ]]; then |
| 82 | + set +x |
| 83 | + echo "$numFiles newly added DMD source files in branch master:" |
| 84 | + echo "----------" |
| 85 | + git diff --name-only --diff-filter=A --relative=dmd "ldc/${refs_prefix}master..${refs_prefix}master" |
| 86 | + echo "----------" |
| 87 | + if [[ "${FORCE:-0}" == 1 ]]; then |
| 88 | + echo "Adding these files due to env variable FORCE=1." |
| 89 | + else |
| 90 | + echo "Aborting due to these newly added files." |
| 91 | + echo "Please check if they are of interest to LDC:" |
| 92 | + echo "* If they aren't, have them removed via filter-repo in this script, then re-run the script." |
| 93 | + echo "* If they are, re-run this script with env variable FORCE=1." |
| 94 | + exit 1 |
| 95 | + fi |
| 96 | + set -x |
| 97 | + fi |
| 98 | +fi |
| 99 | + |
| 100 | +# push prefixed master/stable branches and tags |
| 101 | +git push --tags ldc "${refs_prefix}master" "${refs_prefix}stable" |
| 102 | + |
| 103 | +cd ../.. |
| 104 | +rm -rf "$temp_dir" |
0 commit comments