1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use displaydoc::Display;
use std::path::PathBuf;
use std::process::Command;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Display, Debug, Error)]
pub enum AndroidError {
AndroidSdkNotFound,
AndroidNdkNotFound,
BuildToolsNotFound,
NoPlatformsFound,
PlatformNotFound(u32),
UnsupportedTarget,
UnsupportedHost(String),
InvalidSemver,
InvalidBuildTarget(String),
}
#[derive(Display, Debug, Error)]
pub enum AppleError {
CodeSigningProfilesNotFound,
CodeSigningProfileNotProvided,
CodesignFailed(String),
CodesignAllocateNotFound,
Simctl(simctl::Error),
TargetNotFound,
ResourcesNotFound,
AssetsNotFound,
Plist(#[from] plist::Error),
}
#[derive(Display, Debug, Error)]
pub enum Error {
CmdFailed(Command, String, String),
CmdNotFound(String),
InvalidProfile(String),
InvalidInterfaceOrientation(String),
PathNotFound(PathBuf),
Io(#[from] std::io::Error),
FsExtra(#[from] fs_extra::error::Error),
Android(#[from] AndroidError),
Apple(#[from] AppleError),
OtherError(#[from] Box<dyn std::error::Error>),
}
pub trait CommandExt {
fn output_err(self, print_logs: bool) -> Result<std::process::Output>;
}
impl CommandExt for std::process::Command {
fn output_err(mut self, print_logs: bool) -> Result<std::process::Output> {
let output = match log::max_level() > log::LevelFilter::Error && 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)
}
}
impl From<plist::Error> for Error {
fn from(error: plist::Error) -> Self {
AppleError::from(error).into()
}
}
impl From<simctl::Error> for Error {
fn from(error: simctl::Error) -> Self {
AppleError::Simctl(error).into()
}
}