#[cfg(feature = "apple")]
use apple_bundle::plist;
use displaydoc::Display;
use std::path::PathBuf;
use std::process::Command;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(feature = "android")]
#[derive(Display, Debug, Error)]
pub enum AndroidError {
AndroidNdkNotFound,
FailedToReadSourceProperties,
InvalidSourceProperties(String),
GradleDependencyProjectNotFound(PathBuf),
GradleDependencyProjectNoBuildFile(PathBuf),
GradleNotFound,
BuildToolsNotFound,
NoPlatformsFound,
PlatformNotFound(u32),
UnsupportedTarget,
UnsupportedHost(String),
InvalidSemver,
InvalidBuildTarget(String),
InvalidAppWrapper(String),
InvalidBuildStrategy(String),
FailedToFindAndroidManifest(String),
UnableToFindNDKFile,
AndroidTools(#[from] android_tools::error::Error),
AndroidManifest(#[from] android_manifest::error::Error),
}
#[cfg(feature = "apple")]
#[derive(Display, Debug, Error)]
pub enum AppleError {
CodeSigningProfilesNotFound,
CodeSigningProfileNotProvided,
CodesignFailed(String),
ZipCommandFailed,
CodesignAllocateNotFound,
Simctl(simctl::Error),
TargetNotFound,
ResourcesNotFound,
InvalidBuildStrategy(String),
InvalidBuildTarget(String),
AssetsNotFound,
FailedToFindInfoPlist(String),
Plist(#[from] plist::Error),
}
#[derive(Display, Debug, Error)]
#[ignore_extra_doc_attributes]
pub enum Error {
CmdFailed(Command, String, String),
CmdNotFound(String),
CopyToFileFailed {
path: PathBuf,
cause: std::io::Error,
},
WidthAndHeightDifSizes,
IconsAlreadyExist,
FailedToFindManifest(PathBuf),
InvalidProfile(String),
ToolchainBinaryNotFound {
toolchain_path: PathBuf,
gnu_bin: String,
llvm_bin: String,
},
PathNotFound(PathBuf),
FailedToFindCargoManifest(String),
FailedToChooseShellStringColor(String),
Io(#[from] std::io::Error),
FsExtra(#[from] fs_extra::error::Error),
Zip(#[from] zip::result::ZipError),
#[cfg(feature = "android")]
Android(#[from] AndroidError),
ImageError(#[from] image::ImageError),
#[cfg(feature = "apple")]
Apple(#[from] AppleError),
AnyhowError(#[from] anyhow::Error),
OtherError(#[from] Box<dyn std::error::Error>),
}
pub trait CommandExt {
fn output_err(self, print_logs: bool) -> Result<std::process::Output>;
}
impl CommandExt for Command {
fn output_err(mut self, print_logs: bool) -> Result<std::process::Output> {
let output = match print_logs {
true => self.spawn().and_then(|p| p.wait_with_output())?,
false => self.output()?,
};
if !output.status.success() {
return Err(Error::CmdFailed(
self,
String::from_utf8_lossy(&output.stdout).to_string(),
String::from_utf8_lossy(&output.stderr).to_string(),
));
}
Ok(output)
}
}
#[cfg(feature = "apple")]
impl From<plist::Error> for Error {
fn from(error: plist::Error) -> Self {
AppleError::from(error).into()
}
}
#[cfg(feature = "apple")]
impl From<simctl::Error> for Error {
fn from(error: simctl::Error) -> Self {
AppleError::Simctl(error).into()
}
}
#[cfg(feature = "android")]
impl From<android_tools::error::Error> for Error {
fn from(error: android_tools::error::Error) -> Self {
AndroidError::AndroidTools(error).into()
}
}