| 1 |
#!/bin/sh |
| 2 |
set -ue |
| 3 |
|
| 4 |
# define various useful location |
| 5 |
this_dir=$(dirname "$0") |
| 6 |
repo_root=$(hg root --cwd "$this_dir") |
| 7 |
rel_bin_dir=".hg/dev-tools/bin" |
| 8 |
bin_dir="$repo_root/$rel_bin_dir/" |
| 9 |
env_dir="$repo_root/.hg/dev-tools/venv/" |
| 10 |
config_path="$repo_root/.hg/dev-tools/fix-conf.rc" |
| 11 |
export PIPX_HOME="$env_dir" |
| 12 |
export PIPX_BIN_DIR="$bin_dir" |
| 13 |
|
| 14 |
# TODO: we should make a symlink to `$bin_dir` in the working copy to make the |
| 15 |
# tools available easily. |
| 16 |
|
| 17 |
if ! (hg debugrequires | grep share-safe -q ); then |
| 18 |
echo 'the repository is not share-safe, upgrade your repo' >&2 |
| 19 |
echo '(see hg help config.format.use-share-safe)' >&2 |
| 20 |
exit 128 |
| 21 |
fi |
| 22 |
|
| 23 |
|
| 24 |
# fetch the black version in the toml is not easy and won't work as "23" is not |
| 25 |
# understood by pip as is. |
| 26 |
# |
| 27 |
# TODO: use a more precise black version in the pyproject.toml |
| 28 |
# TODO: rewrite this script in Python as python3.11 has native toml support |
| 29 |
pipx install black==23.12.1 --force --quiet --quiet |
| 30 |
|
| 31 |
# TODO: install/ensure rustfmt and clangformat |
| 32 |
# (or at least adjust configuration accordingly) |
| 33 |
|
| 34 |
# adjust the black path to point to the one we just installed. |
| 35 |
cp "$repo_root/contrib/fix-conf.rc" "$config_path" |
| 36 |
sed -i "s;black:command = black;black:command = $rel_bin_dir/black;" "$config_path" |
| 37 |
|
| 38 |
|
| 39 |
# ensure the configuration for fix is included. |
| 40 |
# |
| 41 |
# We include it on a per-share basis because the relative tool path is resolved |
| 42 |
# from the repository root, so each share needs its own setup. |
| 43 |
# |
| 44 |
# In addition, each share could be on revision using different version/config, |
| 45 |
# so keeping things separated seems simpler. |
| 46 |
if ! ( \ |
| 47 |
hg -R "$repo_root" config --debug -T '{source}\n' \ |
| 48 |
| grep -q "$config_path" \ |
| 49 |
); then |
| 50 |
echo "%include dev-tools/fix-conf.rc" >> .hg/hgrc-not-shared |
| 51 |
fi |