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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
use {
crate::{AppleSdk, Error, Platform, SdkPath, SdkVersion},
std::path::{Path, PathBuf},
};
#[cfg(feature = "parse")]
use crate::parsed_sdk::ParsedSdk;
#[derive(Clone, Debug)]
pub struct SimpleSdk {
path: PathBuf,
is_symlink: bool,
sdk_path: SdkPath,
}
impl AsRef<Path> for SimpleSdk {
fn as_ref(&self) -> &Path {
&self.path
}
}
impl AppleSdk for SimpleSdk {
fn from_directory(path: &Path) -> Result<Self, Error> {
let sdk = SdkPath::from_path(path)?;
let metadata = std::fs::symlink_metadata(path)?;
let is_symlink = metadata.file_type().is_symlink();
let json_path = path.join("SDKSettings.json");
let plist_path = path.join("SDKSettings.plist");
if json_path.exists() || plist_path.exists() {
Ok(Self {
path: path.to_path_buf(),
is_symlink,
sdk_path: sdk,
})
} else {
Err(Error::PathNotSdk(path.to_path_buf()))
}
}
fn is_symlink(&self) -> bool {
self.is_symlink
}
fn platform(&self) -> &Platform {
&self.sdk_path.platform
}
fn version(&self) -> Option<&SdkVersion> {
self.sdk_path.version.as_ref()
}
fn supports_deployment_target(
&self,
_target_name: &str,
_target_version: &SdkVersion,
) -> Result<bool, Error> {
Err(Error::FunctionalityNotSupported(
"evaluating deployment target support on UnparsedSdk instances",
))
}
}
impl SimpleSdk {
#[cfg(feature = "parse")]
pub fn try_parse(self) -> Result<ParsedSdk, Error> {
self.try_into()
}
}
#[cfg(test)]
mod test {
use {
super::*,
crate::{DeveloperDirectory, COMMAND_LINE_TOOLS_DEFAULT_PATH},
};
#[test]
fn find_default_sdks() -> Result<(), Error> {
if let Ok(developer_dir) = DeveloperDirectory::find_default_required() {
assert!(!developer_dir.sdks::<SimpleSdk>()?.is_empty());
}
Ok(())
}
#[test]
fn find_command_line_tools_sdks() -> Result<(), Error> {
let sdk_path = PathBuf::from(COMMAND_LINE_TOOLS_DEFAULT_PATH).join("SDKs");
let res = SimpleSdk::find_command_line_tools_sdks()?;
if sdk_path.exists() {
assert!(res.is_some());
assert!(!res.unwrap().is_empty());
} else {
assert!(res.is_none());
}
Ok(())
}
#[test]
fn find_all_sdks() -> Result<(), Error> {
for dir in DeveloperDirectory::find_system_xcodes()? {
for sdk in dir.sdks::<SimpleSdk>()? {
assert!(!matches!(sdk.platform(), Platform::Unknown(_)));
}
}
Ok(())
}
}