docs/scripts/giza-rename.sh, run over the moves of Phase 3a:
- com.machankura.bennu.{compose,android,desktop} -> mobi.giza.{...}, in
package lines, imports, fully qualified references, the manifest, mainClass,
the Android namespace (one value with applicationId again), the m3Audit
source path, the six docs/scripts tools, and the source links in docs/;
- Res moves from bennu.composeapp.generated.resources to
mobi.giza.compose.resources, now pinned with packageOfResClass so a later
rename of the root project leaves the imports alone;
- BennuDatabase, BennuTheme and the other eleven Bennu identifiers are Giza*.
The script's search is now the same pattern as its sed expressions, so on a
renamed tree it finds nothing and changes nothing.
Checked against the Phase 0 baseline: jvmTest 1643 run (1642 + AppDirJvmTest),
0 failed, 2 skipped; compileDebugKotlinAndroid passes; m3-audit prints the
baseline report line for line. iOS is not compiled on this Linux host.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
114 lines
4.8 KiB
Bash
Executable File
114 lines
4.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# The mechanical part of the Giza fork: docs/giza-rebrand.md, Phase 3.
|
|
#
|
|
# docs/scripts/giza-rename.sh moves, then rewrites
|
|
# docs/scripts/giza-rename.sh --moves-only moves only (commit 3a)
|
|
#
|
|
# Moves com/machankura/bennu to mobi/giza in every source set, renames the files and the
|
|
# Room schema directory that carry the name, and rewrites packages, imports, the Res package
|
|
# and the thirteen Bennu identifiers to match.
|
|
#
|
|
# Idempotent: on a tree that is already renamed it finds nothing and changes nothing. That
|
|
# is the point of it being a script. A merge from Bennu (Phase 9) brings files Bennu added
|
|
# after the fork in under com/machankura/bennu and in Bennu's names; re-running this over
|
|
# the merge moves and rewrites them the way the fork itself was.
|
|
#
|
|
# What it never touches: user-facing strings (Phase 4 words those by hand), anything under
|
|
# lightning-kmp-app/, the mantra/ derivation tags, fr.acinq.*, and this file and the plan,
|
|
# which name the old spellings on purpose.
|
|
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")/../.." || exit 1
|
|
|
|
MOVES_ONLY=0
|
|
[[ "${1:-}" == "--moves-only" ]] && MOVES_ONLY=1
|
|
|
|
SOURCE_SETS=(androidMain commonMain commonTest iosMain jvmMain jvmTest)
|
|
OLD_SCHEMAS=composeApp/schemas/com.machankura.bennu.compose.database.BennuDatabase
|
|
NEW_SCHEMAS=composeApp/schemas/mobi.giza.compose.database.GizaDatabase
|
|
|
|
conflicts=0
|
|
|
|
# Moves one file, with git when git knows it. Refuses to overwrite: a file at both paths
|
|
# after a merge is two versions of one file, and which one wins is a person's decision.
|
|
move_file() {
|
|
local from=$1 to=$2
|
|
if [[ -e "$to" ]]; then
|
|
echo "giza-rename: both $from and $to exist; resolve by hand" >&2
|
|
conflicts=$((conflicts + 1))
|
|
return
|
|
fi
|
|
mkdir -p "$(dirname "$to")"
|
|
if git ls-files --error-unmatch "$from" >/dev/null 2>&1; then
|
|
git mv "$from" "$to"
|
|
else
|
|
mv "$from" "$to"
|
|
fi
|
|
}
|
|
|
|
# Moves a whole tree: in one git mv when nothing is there yet, which is the fork itself,
|
|
# and file by file when something is, which is a merge.
|
|
move_tree() {
|
|
local from=$1 to=$2
|
|
[[ -d "$from" ]] || return 0
|
|
if [[ ! -e "$to" ]]; then
|
|
mkdir -p "$(dirname "$to")"
|
|
git mv "$from" "$to"
|
|
else
|
|
while IFS= read -r -d '' file; do
|
|
move_file "$file" "$to/${file#"$from"/}"
|
|
done < <(find "$from" -type f -print0)
|
|
fi
|
|
find "$from" -depth -type d -empty -delete 2>/dev/null || true
|
|
}
|
|
|
|
for set in "${SOURCE_SETS[@]}"; do
|
|
root=composeApp/src/$set/kotlin
|
|
move_tree "$root/com/machankura/bennu" "$root/mobi/giza"
|
|
# com/machankura and com, if nothing else lives there now.
|
|
rmdir "$root/com/machankura" "$root/com" 2>/dev/null || true
|
|
done
|
|
|
|
# Files whose names carry the brand: BennuDatabase.kt, BennuApp.kt and the rest.
|
|
while IFS= read -r -d '' file; do
|
|
base=$(basename "$file")
|
|
move_file "$file" "$(dirname "$file")/${base//Bennu/Giza}"
|
|
done < <(find composeApp/src -type f -name '*Bennu*' -print0)
|
|
|
|
# Room names the schema directory after the database class's fully qualified name, so it
|
|
# moves with the package and the class together.
|
|
move_tree "$OLD_SCHEMAS" "$NEW_SCHEMAS"
|
|
|
|
if (( MOVES_ONLY )); then
|
|
(( conflicts == 0 )) || exit 1
|
|
exit 0
|
|
fi
|
|
|
|
# Every text file git knows that still names the old packages, Res or identifiers, but for
|
|
# the two files that name them on purpose. The pattern is the sed expressions' own, so a
|
|
# renamed tree matches nothing -- `com.machankura.bennu` in prose, with no separator after
|
|
# it, and the code.sigidli.com/machankura/bennu-kmp URL are left for a person to word.
|
|
mapfile -t files < <(
|
|
git grep -lIE 'com\.machankura\.bennu\.|com/machankura/bennu/|bennu\.composeapp\.generated\.resources|\bBennu(Database|DatabaseConstructor|DatabaseJvmTest|Global|Application|App|Converters|NavHost|NavigationSuite|Theme|Shapes)\b|\bbennuGlobal\b|\bNotYetOnBennu\b|\bdefaultBennuDir\b' \
|
|
-- . ':!lightning-kmp-app' ':!docs/giza-rebrand.md' ':!docs/scripts/giza-rename.sh' || true
|
|
)
|
|
|
|
if (( ${#files[@]} > 0 )); then
|
|
# The order matters only where one pattern's output could match another's input, and
|
|
# none does: each replacement spells Giza, and every pattern looks for Bennu.
|
|
sed -i -E \
|
|
-e 's#com\.machankura\.bennu\.#mobi.giza.#g' \
|
|
-e 's#com/machankura/bennu/#mobi/giza/#g' \
|
|
-e 's#bennu\.composeapp\.generated\.resources#mobi.giza.compose.resources#g' \
|
|
-e 's#\bBennu(Database|DatabaseConstructor|DatabaseJvmTest|Global|Application|App|Converters|NavHost|NavigationSuite|Theme|Shapes)\b#Giza\1#g' \
|
|
-e 's#\bbennuGlobal\b#gizaGlobal#g' \
|
|
-e 's#\bNotYetOnBennu\b#NotYetOnGiza#g' \
|
|
-e 's#\bdefaultBennuDir\b#defaultGizaDir#g' \
|
|
"${files[@]}"
|
|
echo "giza-rename: rewrote ${#files[@]} files"
|
|
fi
|
|
|
|
(( conflicts == 0 )) || exit 1
|