Skip to content

Commit c3dcab8

Browse files
committed
Improve Android UI test dependency logging
1 parent 3eca38d commit c3dcab8

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

scripts/build-android-app.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,16 @@ if [ ! -f "$APP_BUILD_GRADLE" ]; then
293293
exit 1
294294
fi
295295

296-
"$SCRIPT_DIR/update_android_ui_test_gradle.py" "$APP_BUILD_GRADLE"
296+
GRADLE_UPDATE_OUTPUT="$("$SCRIPT_DIR/update_android_ui_test_gradle.py" "$APP_BUILD_GRADLE")"
297+
if [ -n "$GRADLE_UPDATE_OUTPUT" ]; then
298+
while IFS= read -r line; do
299+
[ -n "$line" ] && ba_log "$line"
300+
done <<<"$GRADLE_UPDATE_OUTPUT"
301+
fi
302+
303+
ba_log "Dependencies block after instrumentation update:"
304+
awk '/^\s*dependencies\s*\{/{flag=1} flag{print} /^\s*\}/{if(flag){exit}}' "$APP_BUILD_GRADLE" \
305+
| sed 's/^/[build-android-app] | /'
297306

298307
FINAL_ARTIFACT_DIR="${CN1_TEST_SCREENSHOT_EXPORT_DIR:-$REPO_ROOT/build-artifacts}"
299308
mkdir -p "$FINAL_ARTIFACT_DIR"

scripts/update_android_ui_test_gradle.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
class GradleFile:
2525
def __init__(self, content: str) -> None:
2626
self.content = content
27+
self.configuration_used: str | None = None
28+
self.added_dependencies: list[str] = []
2729

2830
def find_block(self, name: str) -> tuple[int, int] | None:
2931
pattern = re.compile(rf"(^\s*{re.escape(name)}\s*\{{)", re.MULTILINE)
@@ -88,6 +90,7 @@ def ensure_dependencies(self) -> None:
8890
raise SystemExit("Unable to locate dependencies block in Gradle file")
8991
existing_block = self.content[block[0]:block[1]]
9092
configuration = self._select_configuration(existing_block, self.content)
93+
self.configuration_used = configuration
9194
insertion_point = block[1] - 1
9295
for coordinate in ANDROID_TEST_DEPENDENCIES:
9396
if self._has_dependency(existing_block, coordinate):
@@ -100,6 +103,7 @@ def ensure_dependencies(self) -> None:
100103
)
101104
insertion_point += len(combined)
102105
existing_block += combined
106+
self.added_dependencies.append(coordinate)
103107

104108
@staticmethod
105109
def _has_dependency(block: str, coordinate: str) -> bool:
@@ -119,18 +123,38 @@ def _select_configuration(block: str, content: str) -> str:
119123
return "androidTestImplementation"
120124
if re.search(r"^\s*androidTestCompile\b", content, re.MULTILINE):
121125
return "androidTestCompile"
122-
return "androidTestCompile"
126+
if re.search(r"^\s*implementation\b", block, re.MULTILINE) or re.search(
127+
r"^\s*implementation\b", content, re.MULTILINE
128+
):
129+
return "androidTestImplementation"
130+
if re.search(r"^\s*compile\b", block, re.MULTILINE) or re.search(
131+
r"^\s*compile\b", content, re.MULTILINE
132+
):
133+
return "androidTestCompile"
134+
return "androidTestImplementation"
123135

124136
def apply(self) -> None:
125137
self.ensure_test_options()
126138
self.ensure_instrumentation_runner()
127139
self.ensure_dependencies()
128140

141+
def summary(self) -> str:
142+
configuration = self.configuration_used or "<unknown>"
143+
if self.added_dependencies:
144+
deps = ", ".join(self.added_dependencies)
145+
else:
146+
deps = "none (already present)"
147+
return (
148+
"Instrumentation dependency configuration: "
149+
f"{configuration}; added dependencies: {deps}"
150+
)
151+
129152

130153
def process(path: pathlib.Path) -> None:
131154
editor = GradleFile(path.read_text(encoding="utf-8"))
132155
editor.apply()
133156
path.write_text(editor.content, encoding="utf-8")
157+
print(editor.summary())
134158

135159

136160
def main(argv: list[str] | None = None) -> int:

0 commit comments

Comments
 (0)