Modern Apps git

← Modern-Apps.git

install: support projectDir-remapped modules (watch:wear)

Commit
94b70ac39dcb59ea9d6ed6e1dcd0ae87c6a9313c
Author
Vayun Mathur <[email protected]>
When
2026-12-04 23:55 UTC (1 day ago)
Parents
a7053e1
The install script converted a Gradle module to its filesystem
directory by replacing ":" with "/", so :watch:wear (remapped in
settings.gradle.kts to watch-wear/ via projectDir) was rejected
as missing watch/wear/build.gradle.kts, and passing watch-wear
instead built the nonexistent :watch-wear task.

Add module_fs_path/fs_path_to_module helpers that parse the
project(":a:b").projectDir = file("...") remappings from
settings.gradle.kts (falling back to the Gradle path for every
unremapped module) and use them everywhere the script converts
module<->path: module discovery, the valid-module list, "all"
expansion, validation, module_application_id and built_apk.
Also accept common-conventions-wear beside common-conventions-app
as installable, since the sole wear-convention module
(:watch:wear) is a real installable APK sharing the phone app
applicationId; without it the module could never validate.

Behaviour for every other module is unchanged: unremapped modules
resolve to exactly their previous filesystem path, Gradle task
and APK name.

Verified: ./install --device=watch --dry-run contacts watch:wear
lists :contacts:assembleRelease and :watch:wear:assembleRelease
with APKs under contacts/ and watch-wear/ respectively;
./install --dry-run 9 contacts is unchanged; a real
./install --device=watch watch:wear built wear-release.apk and
session-installed com.vayunmathur.watch on the Pixel Watch.

Diff

install
diff --git a/install b/installindex 307a4e81e3..67d2a7d056 100755--- a/install+++ b/install@@ -80,6 +80,46 @@ normalize_module() {   echo "$m" } +# Filesystem dir (relative to $ROOT) for a colon Gradle module. Most modules+# live at their Gradle path (games:voxels -> games/voxels), but a module may+# be remapped in settings.gradle.kts, e.g.+#   project(":watch:wear").projectDir = file("watch-wear")+# so resolve through those remappings instead of assuming path == Gradle path.+module_fs_path() {+  local mod="$1" settings_file="$ROOT/settings.gradle.kts" remapped=""+  if [[ -f "$settings_file" ]]; then+    remapped="$(grep -F "project(\":$mod\").projectDir" "$settings_file" 2>/dev/null \+      | sed -nE 's/.*file\("([^"]+)"\).*/\1/p' | head -1)"+  fi+  if [[ -n "$remapped" ]]; then+    echo "$remapped"+  else+    echo "$mod" | tr ':' '/'+  fi+}++# Inverse of module_fs_path: filesystem dir -> colon Gradle module.+fs_path_to_module() {+  local fs_path="$1" settings_file="$ROOT/settings.gradle.kts" remapped=""+  if [[ -f "$settings_file" ]]; then+    remapped="$(grep -E 'project\(":[^"]+"\)\.projectDir' "$settings_file" 2>/dev/null \+      | sed -nE 's/.*project\(":([^"]+)"\).*file\("([^"]+)"\).*/\2 \1/p' \+      | awk -v p="$fs_path" '$1 == p { print $2; exit }')"+  fi+  if [[ -n "$remapped" ]]; then+    echo "$remapped"+  else+    echo "$fs_path" | tr '/' ':'+  fi+}++# True when a build file applies an installable app convention (phone app or+# its Wear OS companion, e.g. :watch:wear via common-conventions-wear).+is_installable_build_file() {+  grep -qF 'id("common-conventions-app")' "$1" 2>/dev/null \+    || grep -qF 'id("common-conventions-wear")' "$1" 2>/dev/null+}+ get_app_modules_slash() {   local settings_file="$ROOT/settings.gradle.kts"   if [[ ! -f "$settings_file" ]]; then@@ -87,10 +127,10 @@ get_app_modules_slash() {   fi   grep -E 'include\(":[^"]+"\)' "$settings_file" 2>/dev/null \     | sed -E 's/.*include\(":([^"]+)"\).*/\1/' \-    | tr ':' '/' \-    | while IFS= read -r p; do-        case "$p" in "" ) continue;; esac-        if [[ -f "$ROOT/$p/build.gradle.kts" ]] && grep -qF 'id("common-conventions-app")' "$ROOT/$p/build.gradle.kts" 2>/dev/null; then+    | while IFS= read -r colon_mod; do+        case "$colon_mod" in "" ) continue;; esac+        p="$(module_fs_path "$colon_mod")"+        if [[ -f "$ROOT/$p/build.gradle.kts" ]] && is_installable_build_file "$ROOT/$p/build.gradle.kts"; then           echo "$p"         fi       done | sort -u@@ -110,7 +150,7 @@ print_valid_modules() {   printf "  %-30s %s\n" "--------------------" "-------------------"   while IFS= read -r sm; do     case "$sm" in "" ) continue;; esac-    colon_mod="$(echo "$sm" | tr '/' ':')"+    colon_mod="$(fs_path_to_module "$sm")"     printf "  %-30s :%s\n" "$sm" "$colon_mod"   done <<< "$slash_modules"   echo ""@@ -299,7 +339,7 @@ while [[ $idx -lt ${#MODULES_RAW[@]} ]]; do       fi       while IFS= read -r sm; do         case "$sm" in "" ) continue;; esac-        colon_mod="$(echo "$sm" | tr '/' ':')"+        colon_mod="$(fs_path_to_module "$sm")"         # dedup for expanded modules         dup=0         j=0@@ -368,12 +408,12 @@ INVALID_MODULES=() idx=0 while [[ $idx -lt ${#NORMALIZED_MODULES[@]} ]]; do   mod="${NORMALIZED_MODULES[$idx]}"-  fs_path="$(echo "$mod" | tr ':' '/')"+  fs_path="$(module_fs_path "$mod")"   full_path="$ROOT/$fs_path"   if [[ ! -f "$full_path/build.gradle.kts" ]]; then     INVALID_MODULES+=("$mod (not found: $fs_path/build.gradle.kts)")   else-    if ! grep -qF 'id("common-conventions-app")' "$full_path/build.gradle.kts" 2>/dev/null; then+    if ! is_installable_build_file "$full_path/build.gradle.kts"; then       INVALID_MODULES+=("$mod (exists but is not an app module - missing common-conventions-app)")     fi   fi@@ -500,14 +540,14 @@ fi # applicationId for a module (all are string literals in build.gradle.kts). module_application_id() {   sed -nE 's/^[[:space:]]*applicationId[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' \-    "$ROOT/$(echo "$1" | tr ':' '/')/build.gradle.kts" | head -1+    "$ROOT/$(module_fs_path "$1")/build.gradle.kts" | head -1 }  # APK built for a module; output-metadata.json names the file authoritatively # (nested modules like cast:tv build tv-dev.apk, not cast-tv-dev.apk). built_apk() {   local mod="$1" fs_path out_dir meta base_name file_name-  fs_path="$(echo "$mod" | tr ':' '/')"+  fs_path="$(module_fs_path "$mod")"   out_dir="$ROOT/$fs_path/build/outputs/apk/$VARIANT_LC"   meta="$out_dir/output-metadata.json"   base_name="${mod##*:}"