Skip to content
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

fix: ignore log lines in avd_list, fix docs.rs build #414

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/avd-list-log-lines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-mobile2": "patch"
---

Fix `android::emulator::avd_list` function interpreting log lines from `emulator -list-avd` as valid `Emulator`
13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ keywords = [ "cargo", "mobile", "ios", "android", "tauri" ]
categories = [ "development-tools::cargo-plugins" ]
license = "Apache-2.0 OR MIT"


[package.metadata.docs.rs]
no-default-features = true
features = ["native-tls"]
default-target = "x86_64-unknown-linux-gnu"
targets = [
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin",
]

[[bin]]
name = "cargo-mobile"
required-features = [ "cli" ]
Expand Down Expand Up @@ -42,7 +53,7 @@ cli = [
brainium = [ ]
rustls = [ "ureq/tls" ]
native-tls = [ "ureq/native-tls" ]
default = [ "cli", "ureq/native-tls" ]
default = [ "cli", "native-tls" ]

[dependencies]
handlebars = "6.0"
Expand Down
8 changes: 7 additions & 1 deletion src/android/emulator/avd_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn avd_list(env: &Env) -> Result<BTreeSet<Emulator>, Error> {
raw_list
.split('\n')
.filter_map(|name| {
if name.is_empty() {
if name.is_empty() || is_emulator_log_line(name) {
None
} else {
Some(Emulator::new(name.trim().into()))
Expand All @@ -31,3 +31,9 @@ pub fn avd_list(env: &Env) -> Result<BTreeSet<Emulator>, Error> {
})
.map_err(Error::ListAvdsFailed)
}

fn is_emulator_log_line(name: &str) -> bool {
["INFO |", "WARNING |", "ERROR |"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
["INFO |", "WARNING |", "ERROR |"]
["INFO", "WARNING", "ERROR"]

just in case the tabulation changes between OS or some other formatting condition..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find that hard to change but if it ever does, we can always adapt later.

I included the space and |, to ensure that it is in fact a log line and not just weirdly named emulator, because you can name an emulator INFO but you can't have | in the name.

Maybe we can change the detection to check for | and that would be enough?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just leave it as is then, they might also change the output layout in the future anyways

.iter()
.any(|prefix| name.starts_with(prefix))
}
Loading