-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathmod.rs
79 lines (69 loc) · 2.08 KB
/
mod.rs
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
use super::super::target::Target;
use super::DeviceKind;
use crate::apple::device::Device as AppleDevice;
use crate::env::{Env, ExplicitEnv};
use crate::DuctExpressionExt;
use serde::Deserialize;
use std::fmt::Display;
mod device_list;
mod run;
pub use device_list::device_list;
pub use run::run;
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct Device {
name: String,
udid: String,
}
impl Display for Device {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.name)
}
}
impl<'a> From<Device> for AppleDevice<'a> {
fn from(device: Device) -> AppleDevice<'a> {
let name = device.name.clone();
let is_visionos = name.contains("Apple Vision Pro");
let target = Target::for_triple(if cfg!(target_arch = "aarch64") {
match is_visionos {
true => "aarch64-apple-visionos",
_ => "aarch64-apple-ios", // TODO: figure out how to check for sim here, or probably do this elsewhere, and just add -sim to the triple
// true => "aarch64-apple-visionos-sim",
// _ => "aarch64-apple-ios-sim
}
} else {
"x86_64-apple-ios"
});
AppleDevice::new(
device.udid,
device.name,
"".into(),
target.unwrap(),
DeviceKind::Simulator,
)
}
}
impl Device {
pub fn name(&self) -> &str {
&self.name
}
fn command(&self, env: &Env) -> duct::Expression {
duct::cmd(
"open",
[
"-a",
"Simulator",
"--args",
"-CurrentDeviceUDID",
&self.udid,
],
)
.vars(env.explicit_env())
.dup_stdio()
}
pub fn start(&self, env: &Env) -> std::io::Result<duct::Handle> {
self.command(env).start()
}
pub fn start_detached(&self, env: &Env) -> std::io::Result<()> {
self.command(env).run_and_detach()
}
}