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

devices/adb: Find adb executable in $ANDROID_HOME/$ANDROID_SDK_ROOT #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MarijnS95
Copy link
Member

adb is not always available on PATH, sometimes it is installed only via the SDK. Make sure we find it there too - after checking PATH - via well-known SDK variables.


I tried but thus far failed to easily add Adb::which() (Result) to x doctor, so that the result is accurate.

MarijnS95 added a commit that referenced this pull request May 3, 2023
…nment

Environment variables can be set and optionally override the process
environment through `.cargo/config.toml`'s `[env]` section:
https://doc.rust-lang.org/cargo/reference/config.html#env

These config variables have specific precedence rules with regards to
overriding the environment set in the process, and can optionally
represent paths relative to the parent of the containing `.cargo/`
folder.

Besides exposing variables to all other processes called by `xbuild`,
this also allows `xbuild` itself to be driven by variables set in
`.cargo/config.toml`, such as `$ANDROID_HOME` needed for #116.

rust-mobile/cargo-subcommand#12
rust-mobile/cargo-subcommand#16
pub fn which() -> Result<PathBuf> {
const ADB: &str = exe!("adb");

match which::which(ADB) {
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 thought for a second about using which::which_in_global(ADB, paths) but that requires paths to be a single concatenated string of env("PATH"):env("ANDROID_HOME") in the event that these env vars exist, and that overall looks more messy without including any context about PATH vs ANDROID_HOME vs ANDROID_NDK_ROOT providing this exe.

@dvc94ch
Copy link
Contributor

dvc94ch commented May 3, 2023

I'm not a big fan of adding a bunch of hacks for Android. Having adb in the path seems like a reasonable assumption. Package managers on Linux, macos, windows easily let you install adb and add it to path.

@MarijnS95
Copy link
Member Author

I've been told by my colleagues that there's no adb via winget yet.

MarijnS95 added a commit that referenced this pull request May 15, 2023
…nment

Environment variables can be set and optionally override the process
environment through `.cargo/config.toml`'s `[env]` section:
https://doc.rust-lang.org/cargo/reference/config.html#env

These config variables have specific precedence rules with regards to
overriding the environment set in the process, and can optionally
represent paths relative to the parent of the containing `.cargo/`
folder.

Besides exposing variables to all other processes called by `xbuild`,
this also allows `xbuild` itself to be driven by variables set in
`.cargo/config.toml`, such as `$ANDROID_HOME` needed for #116.

rust-mobile/cargo-subcommand#12
rust-mobile/cargo-subcommand#16
@dvc94ch
Copy link
Contributor

dvc94ch commented Aug 15, 2023

looks like this issue is being tracked here: microsoft/winget-pkgs#4082

@dvc94ch
Copy link
Contributor

dvc94ch commented Aug 15, 2023

would be cool to track which packages are missing in winget that x doctor requires. Maybe contributing to winget pkgs might be the best option.

@MarijnS95
Copy link
Member Author

Adding xbuild as a winget buildable package with proper dependencies?

@dvc94ch
Copy link
Contributor

dvc94ch commented Aug 15, 2023

Once all the dependencies are on Winget, we could maintain a Winget/brew package. Probably not worth it for Linux as everyone knows what they're doing and use their own package manager

MarijnS95 added a commit that referenced this pull request Aug 17, 2023
…nment

Environment variables can be set and optionally override the process
environment through `.cargo/config.toml`'s `[env]` section:
https://doc.rust-lang.org/cargo/reference/config.html#env

These config variables have specific precedence rules with regards to
overriding the environment set in the process, and can optionally
represent paths relative to the parent of the containing `.cargo/`
folder.

Besides exposing variables to all other processes called by `xbuild`,
this also allows `xbuild` itself to be driven by variables set in
`.cargo/config.toml`, such as `$ANDROID_HOME` needed for #116.

rust-mobile/cargo-subcommand#12
rust-mobile/cargo-subcommand#16
Comment on lines 149 to 177
if let Some(line) = output.split('\n').nth(version.row as _) {
if let Some(line) = output.lines().nth(version.row as _) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Drive-by fix (that I can PR separately): on Windows adb --version returns \r\n, so the \r remains in the version() string and clears the line (adb 1.0.41\r) that was printed before it, leaving only path() 🤭

MarijnS95 added a commit that referenced this pull request Aug 22, 2023
…nment (#117)

* Propagate `.cargo/config.toml` `[env]` settings to the process environment

Environment variables can be set and optionally override the process
environment through `.cargo/config.toml`'s `[env]` section:
https://doc.rust-lang.org/cargo/reference/config.html#env

These config variables have specific precedence rules with regards to
overriding the environment set in the process, and can optionally
represent paths relative to the parent of the containing `.cargo/`
folder.

Besides exposing variables to all other processes called by `xbuild`,
this also allows `xbuild` itself to be driven by variables set in
`.cargo/config.toml`, such as `$ANDROID_HOME` needed for #116.

rust-mobile/cargo-subcommand#12
rust-mobile/cargo-subcommand#16

* cargo/config: Don't canonicalize joined `[env]` `relative` paths

Cargo doesn't do this either, and canonicalization requires the path to
exist which it does not have to.
`adb` is not always available on `PATH`, sometimes it is installed only
via the SDK.  Make sure we find it there too - after checking `PATH` -
via well-known SDK variables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants