use {
std::{
io::Error as IoError, num::ParseIntError, path::PathBuf, process::Command, str::Utf8Error,
},
thiserror::Error,
};
#[derive(Debug, Error)]
pub enum NdkError {
#[error(
"Android SDK is not found. \
Please set the path to the Android SDK with the $ANDROID_HOME \
environment variable."
)]
SdkNotFound,
#[error(
"Android NDK is not found. \
Please set the path to the Android NDK with $ANDROID_NDK_ROOT \
environment variable."
)]
NdkNotFound,
#[error(
"Path `{0:?}` is not a valid Android NDK installation: {1}. \
If you set the `ANDROID_NDK_ROOT` environment variable manually, \
it must point to the versioned NDK directory \
(e.g. `<sdk>/ndk/27.3.13750724`), not the `<sdk>/ndk` folder itself."
)]
InvalidNdk(PathBuf, IoError),
#[error(
"GNU toolchain binary `{gnu_bin}` nor LLVM toolchain binary `{llvm_bin}` found in `{toolchain_path:?}`."
)]
ToolchainBinaryNotFound {
toolchain_path: PathBuf,
gnu_bin: String,
llvm_bin: String,
},
#[error("Path `{0:?}` doesn't exist.")]
PathNotFound(PathBuf),
#[error("Command `{0}` not found.")]
CmdNotFound(String),
#[error("Android SDK has no build tools.")]
BuildToolsNotFound,
#[error("Android SDK has no platforms installed.")]
NoPlatformFound,
#[error(
"None of the installed Android SDK platforms ({installed}) are within the API level \
range {min}..={max} supported by the NDK at `{ndk_path:?}`. \
Install a platform within this range (e.g. `sdkmanager \"platforms;android-{max}\"`) \
or use a newer NDK that supports your target API level."
)]
NoSupportedPlatform {
installed: String,
ndk_path: PathBuf,
min: u32,
max: u32,
},
#[error("Platform `{0}` is not installed.")]
PlatformNotFound(u32),
#[error("Target is not supported.")]
UnsupportedTarget,
#[error("Host `{0}` is not supported.")]
UnsupportedHost(String),
#[error(transparent)]
Io(#[from] IoError),
#[error("IoError on `{0:?}`: {1}")]
IoPathError(PathBuf, #[source] IoError),
#[error("Invalid semver")]
InvalidSemver,
#[error("Command `{}` had a non-zero exit code.", format!("{:?}", .0).replace('"', ""))]
CmdFailed(Box<Command>),
#[error(transparent)]
Serialize(#[from] quick_xml::SeError),
#[error("String `{1}` is not a UID")]
NotAUid(#[source] ParseIntError, String),
#[error("Could not find `package:{package}` in output `{output}`")]
PackageNotInOutput { package: String, output: String },
#[error("Could not find `uid:` in output `{0}`")]
UidNotInOutput(String),
#[error(transparent)]
Utf8(#[from] Utf8Error),
#[error(transparent)]
ParseInt(#[from] ParseIntError),
}