-
-
Notifications
You must be signed in to change notification settings - Fork 164
Bundle Android template for release-install local runs #11276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Bundle the Android Gradle template, Kotlin/Java bridge, and resources in the | ||
| compiler so `perry run android --local` and Wear OS packaging work from release | ||
| installs without a Perry source checkout. Build-time collection tracks new | ||
| resources while excluding Gradle caches, local SDK paths, generated output, and | ||
| JNI binaries. Includes extraction, resource-fidelity, collector, and Wear OS | ||
| regression coverage; the extracted template was built into a debug APK with | ||
| Gradle 9.4, JDK 21, and Android SDK 35. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| //! Embed the checked-in Gradle project without development-machine build output. | ||
| use std::{env, fs, io, path::Path}; | ||
|
|
||
| pub fn emit() -> io::Result<()> { | ||
| let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../perry-ui-android/template"); | ||
| let mut files = Vec::new(); | ||
| collect(&root, &root, &mut files)?; | ||
| files.sort(); | ||
| let mut source = String::from("pub(super) static FILES: &[(&str, &[u8])] = &[\n"); | ||
| for name in files { | ||
| let path = root.join(&name); | ||
| println!("cargo:rerun-if-changed={}", path.display()); | ||
| source.push_str(&format!( | ||
| " ({:?}, include_bytes!({:?})),\n", | ||
| name.replace('\\', "/"), | ||
| path.to_str().expect("Android template path must be UTF-8") | ||
| )); | ||
| } | ||
| source.push_str("];"); | ||
| fs::write( | ||
| Path::new(&env::var_os("OUT_DIR").unwrap()).join("android_template.rs"), | ||
| source, | ||
| ) | ||
| } | ||
|
|
||
| fn collect(root: &Path, dir: &Path, files: &mut Vec<String>) -> io::Result<()> { | ||
| // Watching directories also detects newly added template resources. | ||
| println!("cargo:rerun-if-changed={}", dir.display()); | ||
| for entry in fs::read_dir(dir)? { | ||
| let entry = entry?; | ||
| let name = entry.file_name(); | ||
| let name = name.to_string_lossy(); | ||
| let relative = entry | ||
| .path() | ||
| .strip_prefix(root) | ||
| .unwrap() | ||
| .to_str() | ||
| .unwrap() | ||
| .replace('\\', "/"); | ||
| // Gradle caches, generated wrappers/builds, machine-specific SDK paths, | ||
| // and native outputs are not template sources. They must not be shipped. | ||
| if name.starts_with('.') | ||
| || matches!( | ||
| name.as_ref(), | ||
| "build" | "gradlew" | "gradlew.bat" | "local.properties" | "jniLibs" | ||
| ) | ||
| || relative == "gradle/wrapper" | ||
| { | ||
| continue; | ||
| } | ||
| let kind = entry.file_type()?; | ||
| if kind.is_symlink() { | ||
| return Err(io::Error::new( | ||
| io::ErrorKind::InvalidData, | ||
| format!( | ||
| "Android template must not contain symlinks: {}", | ||
| entry.path().display() | ||
| ), | ||
| )); | ||
| } | ||
| if kind.is_dir() { | ||
| collect(root, &entry.path(), files)?; | ||
| } else if kind.is_file() { | ||
| files.push(relative); | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn android_template_collector_includes_new_resources_but_not_machine_files() { | ||
| let temp = tempfile::tempdir().unwrap(); | ||
| let root = temp.path(); | ||
| for name in [ | ||
| "gradle/libs.versions.toml", | ||
| "app/src/main/res/drawable/new_icon.png", | ||
| "app/src/main/java/com/perry/app/NewBridge.kt", | ||
| "local.properties", | ||
| ".gradle/cache", | ||
| "app/build/generated/secret", | ||
| "app/src/main/jniLibs/arm64-v8a/libperry_app.so", | ||
| "gradlew", | ||
| "gradle/wrapper/gradle-wrapper.jar", | ||
| ] { | ||
| let file = root.join(name); | ||
| fs::create_dir_all(file.parent().unwrap()).unwrap(); | ||
| fs::write(file, [0, 255, 128, 10]).unwrap(); | ||
| } | ||
| let mut files = Vec::new(); | ||
| collect(root, root, &mut files).unwrap(); | ||
| files.sort(); | ||
| assert_eq!( | ||
| files, | ||
| [ | ||
| "app/src/main/java/com/perry/app/NewBridge.kt", | ||
| "app/src/main/res/drawable/new_icon.png", | ||
| "gradle/libs.versions.toml", | ||
| ] | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| //! The Android/Wear OS project ships inside the compiler, including resources | ||
| //! and Kotlin/Java bridge sources. build.rs derives this table from the template. | ||
| use std::{fs, io, path::Path}; | ||
|
|
||
| include!(concat!(env!("OUT_DIR"), "/android_template.rs")); | ||
|
|
||
| pub(super) fn extract(destination: &Path) -> io::Result<()> { | ||
| for (relative, contents) in FILES { | ||
| let path = destination.join(relative); | ||
| fs::create_dir_all(path.parent().unwrap())?; | ||
| fs::write(path, contents)?; | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn bundled_android_template_extracts_without_a_checkout() { | ||
| let temp = tempfile::tempdir().unwrap(); | ||
| let destination = temp.path().join("release-app/android-build"); | ||
| extract(&destination).unwrap(); | ||
| // Required packaging/bridge inputs, not just a non-empty output tree. | ||
| for relative in [ | ||
| "build.gradle.kts", | ||
| "settings.gradle.kts", | ||
| "gradle.properties", | ||
| "app/build.gradle.kts", | ||
| "app/src/main/AndroidManifest.xml", | ||
| "app/src/main/java/com/perry/app/PerryActivity.kt", | ||
| "app/src/main/java/com/perry/app/PerryBridge.kt", | ||
| "app/src/main/java/com/perry/app/PerryMediaSessionCallback.java", | ||
| "app/src/main/res/values/themes.xml", | ||
| "app/src/main/res/drawable/splash_background.xml", | ||
| ] { | ||
| assert!(destination.join(relative).is_file(), "missing {relative}"); | ||
| } | ||
| for (relative, bytes) in FILES { | ||
| assert_eq!( | ||
| fs::read(destination.join(relative)).unwrap(), | ||
| *bytes, | ||
| "{relative}" | ||
| ); | ||
| } | ||
| assert!(!destination.join("local.properties").exists()); | ||
| assert!(!destination.join("app/src/main/jniLibs").exists()); | ||
| let manifest = | ||
| fs::read_to_string(destination.join("app/src/main/AndroidManifest.xml")).unwrap(); | ||
| assert!(manifest.contains("PerryActivity")); | ||
| let gradle = fs::read_to_string(destination.join("app/build.gradle.kts")).unwrap(); | ||
| assert!(gradle.contains("applicationId = \"com.perry.template\"")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn bundled_android_template_matches_checked_in_sources() { | ||
| // Every embedded file must match the source tree byte-for-byte. This | ||
| // catches lossy string conversions and platform newline rewriting. | ||
| let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../perry-ui-android/template"); | ||
| for (relative, contents) in FILES { | ||
| assert_eq!( | ||
| fs::read(root.join(relative)).unwrap(), | ||
| *contents, | ||
| "{relative}" | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Run the build-time collector's regression cases in the CLI test harness. | ||
| #[cfg(test)] | ||
| #[allow(dead_code)] | ||
| #[path = "../../../build/android_template.rs"] | ||
| mod embedding; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
Package the template with the
perrycrate.cargo package -p perryverifies the crate from an extracted source package. That package does not contain the siblingperry-ui-android/templatedirectory. The unconditional call toemit()then fails atcollect(), so source-package verification and installs from a published crate cannot build. Put the template inside the packaged crate, or include another packaged source for the embedded table. (doc.rust-lang.org)🤖 Prompt for AI Agents