Struct apple_sdk::DeveloperDirectory
source · pub struct DeveloperDirectory { /* private fields */ }Expand description
A directory containing Apple platforms, SDKs, and other tools.
Implementations§
source§impl DeveloperDirectory
impl DeveloperDirectory
sourcepub fn from_env() -> Result<Option<Self>, Error>
pub fn from_env() -> Result<Option<Self>, Error>
Resolve an instance from the DEVELOPER_DIR environment variable.
This environment variable is used by convention to override default search locations for the developer directory.
If DEVELOPER_DIR is defined, the value/path is validated for existence
and an error is returned if it doesn’t exist.
If DEVELOPER_DIR isn’t defined, returns Ok(None).
Examples found in repository?
More examples
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
fn resolve_location(&self) -> Result<SdkSearchResolvedLocation, Error> {
match self {
Self::SdkRootEnv => {
if let Some(path) = std::env::var_os("SDKROOT") {
let path = PathBuf::from(path);
if path.exists() {
Ok(SdkSearchResolvedLocation::SdkDirectoryUnfiltered(path))
} else {
Err(Error::PathNotSdk(path))
}
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::DeveloperDirEnv => {
if let Some(dir) = DeveloperDirectory::from_env()? {
Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::SystemXcode => {
if let Some(dir) = DeveloperDirectory::default_xcode() {
Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::CommandLineTools => {
if let Some(path) = command_line_tools_sdks_directory() {
Ok(SdkSearchResolvedLocation::SdksDirectory(path))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::XcodeSelect => Ok(SdkSearchResolvedLocation::PlatformDirectories(
DeveloperDirectory::from_xcode_select()?.platforms()?,
)),
Self::SystemXcodes => Ok(SdkSearchResolvedLocation::PlatformDirectories(
DeveloperDirectory::find_system_xcodes()?
.into_iter()
.map(|dir| dir.platforms())
.collect::<Result<Vec<_>, Error>>()?
.into_iter()
.flatten()
.collect::<Vec<_>>(),
)),
Self::Developer(dir) => Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
)),
Self::Sdks(path) => Ok(SdkSearchResolvedLocation::SdksDirectory(path.clone())),
Self::Sdk(path) => Ok(SdkSearchResolvedLocation::SdkDirectory(path.clone())),
}
}sourcepub fn from_xcode_select() -> Result<Self, Error>
pub fn from_xcode_select() -> Result<Self, Error>
Attempt to resolve an instance by running xcode-select.
The output from xcode-select is implicitly trusted and no validation
of the path is performed.
Examples found in repository?
More examples
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
fn resolve_location(&self) -> Result<SdkSearchResolvedLocation, Error> {
match self {
Self::SdkRootEnv => {
if let Some(path) = std::env::var_os("SDKROOT") {
let path = PathBuf::from(path);
if path.exists() {
Ok(SdkSearchResolvedLocation::SdkDirectoryUnfiltered(path))
} else {
Err(Error::PathNotSdk(path))
}
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::DeveloperDirEnv => {
if let Some(dir) = DeveloperDirectory::from_env()? {
Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::SystemXcode => {
if let Some(dir) = DeveloperDirectory::default_xcode() {
Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::CommandLineTools => {
if let Some(path) = command_line_tools_sdks_directory() {
Ok(SdkSearchResolvedLocation::SdksDirectory(path))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::XcodeSelect => Ok(SdkSearchResolvedLocation::PlatformDirectories(
DeveloperDirectory::from_xcode_select()?.platforms()?,
)),
Self::SystemXcodes => Ok(SdkSearchResolvedLocation::PlatformDirectories(
DeveloperDirectory::find_system_xcodes()?
.into_iter()
.map(|dir| dir.platforms())
.collect::<Result<Vec<_>, Error>>()?
.into_iter()
.flatten()
.collect::<Vec<_>>(),
)),
Self::Developer(dir) => Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
)),
Self::Sdks(path) => Ok(SdkSearchResolvedLocation::SdksDirectory(path.clone())),
Self::Sdk(path) => Ok(SdkSearchResolvedLocation::SdkDirectory(path.clone())),
}
}sourcepub fn default_xcode() -> Option<Self>
pub fn default_xcode() -> Option<Self>
Attempt to resolve an instance from the default Xcode.app location.
This looks for a system installed Xcode.app and for the developer
directory within. If found, returns Some. If not, returns None.
Examples found in repository?
More examples
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
fn resolve_location(&self) -> Result<SdkSearchResolvedLocation, Error> {
match self {
Self::SdkRootEnv => {
if let Some(path) = std::env::var_os("SDKROOT") {
let path = PathBuf::from(path);
if path.exists() {
Ok(SdkSearchResolvedLocation::SdkDirectoryUnfiltered(path))
} else {
Err(Error::PathNotSdk(path))
}
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::DeveloperDirEnv => {
if let Some(dir) = DeveloperDirectory::from_env()? {
Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::SystemXcode => {
if let Some(dir) = DeveloperDirectory::default_xcode() {
Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::CommandLineTools => {
if let Some(path) = command_line_tools_sdks_directory() {
Ok(SdkSearchResolvedLocation::SdksDirectory(path))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::XcodeSelect => Ok(SdkSearchResolvedLocation::PlatformDirectories(
DeveloperDirectory::from_xcode_select()?.platforms()?,
)),
Self::SystemXcodes => Ok(SdkSearchResolvedLocation::PlatformDirectories(
DeveloperDirectory::find_system_xcodes()?
.into_iter()
.map(|dir| dir.platforms())
.collect::<Result<Vec<_>, Error>>()?
.into_iter()
.flatten()
.collect::<Vec<_>>(),
)),
Self::Developer(dir) => Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
)),
Self::Sdks(path) => Ok(SdkSearchResolvedLocation::SdksDirectory(path.clone())),
Self::Sdk(path) => Ok(SdkSearchResolvedLocation::SdkDirectory(path.clone())),
}
}sourcepub fn find_system_xcodes() -> Result<Vec<Self>, Error>
pub fn find_system_xcodes() -> Result<Vec<Self>, Error>
Finds all Developer directories for system installed Xcode applications.
This is a convenience method for find_system_xcode_applications() plus
resolving the Developer directory and filtering on missing items.
It will return all available Developer directories for all Xcode installs
under /Applications.
Examples found in repository?
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
fn resolve_location(&self) -> Result<SdkSearchResolvedLocation, Error> {
match self {
Self::SdkRootEnv => {
if let Some(path) = std::env::var_os("SDKROOT") {
let path = PathBuf::from(path);
if path.exists() {
Ok(SdkSearchResolvedLocation::SdkDirectoryUnfiltered(path))
} else {
Err(Error::PathNotSdk(path))
}
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::DeveloperDirEnv => {
if let Some(dir) = DeveloperDirectory::from_env()? {
Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::SystemXcode => {
if let Some(dir) = DeveloperDirectory::default_xcode() {
Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::CommandLineTools => {
if let Some(path) = command_line_tools_sdks_directory() {
Ok(SdkSearchResolvedLocation::SdksDirectory(path))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::XcodeSelect => Ok(SdkSearchResolvedLocation::PlatformDirectories(
DeveloperDirectory::from_xcode_select()?.platforms()?,
)),
Self::SystemXcodes => Ok(SdkSearchResolvedLocation::PlatformDirectories(
DeveloperDirectory::find_system_xcodes()?
.into_iter()
.map(|dir| dir.platforms())
.collect::<Result<Vec<_>, Error>>()?
.into_iter()
.flatten()
.collect::<Vec<_>>(),
)),
Self::Developer(dir) => Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
)),
Self::Sdks(path) => Ok(SdkSearchResolvedLocation::SdksDirectory(path.clone())),
Self::Sdk(path) => Ok(SdkSearchResolvedLocation::SdkDirectory(path.clone())),
}
}sourcepub fn find_default() -> Result<Option<Self>, Error>
pub fn find_default() -> Result<Option<Self>, Error>
Attempt to find a Developer Directory using reasonable semantics.
This is probably what most end-users want to use for resolving the path to a Developer Directory.
This is a convenience function for calling other APIs on this type to resolve the default instance.
In priority order:
DEVELOPER_DIR- System Xcode.app application.
xcode-selectoutput.
Errors only if DEVELOPER_DIR is defined and it points to an invalid path.
Errors from running xcode-select are ignored.
sourcepub fn find_default_required() -> Result<Self, Error>
pub fn find_default_required() -> Result<Self, Error>
Find the Developer Directory and error if not found.
This is a wrapper around Self::find_default() that will error if no Developer Directory could be found.
sourcepub fn path(&self) -> &Path
pub fn path(&self) -> &Path
The filesystem path to this developer directory.
Examples found in repository?
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::SdkRootEnv => f.write_str("SDKROOT environment variable"),
Self::DeveloperDirEnv => f.write_str("DEVELOPER_DIR environment variable"),
Self::SystemXcode => f.write_str("System-installed Xcode application"),
Self::CommandLineTools => f.write_str("Xcode Command Line Tools installation"),
Self::XcodeSelect => f.write_str("xcode-select"),
Self::SystemXcodes => f.write_str("All system-installed Xcode applications"),
Self::Developer(dir) => {
f.write_fmt(format_args!("Developer Directory {}", dir.path().display()))
}
Self::Sdks(path) => f.write_fmt(format_args!("SDKs directory {}", path.display())),
Self::Sdk(path) => f.write_fmt(format_args!("SDK directory {}", path.display())),
}
}sourcepub fn platforms_path(&self) -> PathBuf
pub fn platforms_path(&self) -> PathBuf
The path to the directory containing platforms.
Examples found in repository?
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
pub fn platforms(&self) -> Result<Vec<PlatformDirectory>, Error> {
let platforms_path = self.platforms_path();
let dir = match std::fs::read_dir(platforms_path) {
Ok(v) => Ok(v),
Err(e) => {
if e.kind() == std::io::ErrorKind::NotFound {
return Ok(vec![]);
} else {
Err(Error::from(e))
}
}
}?;
let mut res = vec![];
for entry in dir {
let entry = entry?;
if let Ok(platform) = PlatformDirectory::from_path(entry.path()) {
res.push(platform);
}
}
// Make deterministic.
res.sort();
Ok(res)
}sourcepub fn platforms(&self) -> Result<Vec<PlatformDirectory>, Error>
pub fn platforms(&self) -> Result<Vec<PlatformDirectory>, Error>
Find platform directories within this developer directory.
Platforms are defined by the presence of a Platforms directory under
the developer directory. This directory layout is only recognized
for modern Xcode layouts.
Returns all discovered instances inside this developer directory.
The return order is sorted and deterministic.
Examples found in repository?
More examples
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
fn resolve_location(&self) -> Result<SdkSearchResolvedLocation, Error> {
match self {
Self::SdkRootEnv => {
if let Some(path) = std::env::var_os("SDKROOT") {
let path = PathBuf::from(path);
if path.exists() {
Ok(SdkSearchResolvedLocation::SdkDirectoryUnfiltered(path))
} else {
Err(Error::PathNotSdk(path))
}
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::DeveloperDirEnv => {
if let Some(dir) = DeveloperDirectory::from_env()? {
Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::SystemXcode => {
if let Some(dir) = DeveloperDirectory::default_xcode() {
Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::CommandLineTools => {
if let Some(path) = command_line_tools_sdks_directory() {
Ok(SdkSearchResolvedLocation::SdksDirectory(path))
} else {
Ok(SdkSearchResolvedLocation::None)
}
}
Self::XcodeSelect => Ok(SdkSearchResolvedLocation::PlatformDirectories(
DeveloperDirectory::from_xcode_select()?.platforms()?,
)),
Self::SystemXcodes => Ok(SdkSearchResolvedLocation::PlatformDirectories(
DeveloperDirectory::find_system_xcodes()?
.into_iter()
.map(|dir| dir.platforms())
.collect::<Result<Vec<_>, Error>>()?
.into_iter()
.flatten()
.collect::<Vec<_>>(),
)),
Self::Developer(dir) => Ok(SdkSearchResolvedLocation::PlatformDirectories(
dir.platforms()?,
)),
Self::Sdks(path) => Ok(SdkSearchResolvedLocation::SdksDirectory(path.clone())),
Self::Sdk(path) => Ok(SdkSearchResolvedLocation::SdkDirectory(path.clone())),
}
}sourcepub fn sdks<SDK: AppleSdk>(&self) -> Result<Vec<SDK>, Error>
pub fn sdks<SDK: AppleSdk>(&self) -> Result<Vec<SDK>, Error>
Find SDKs within this developer directory.
This is a convenience method for calling Self::platforms() + PlatformDirectory::find_sdks() and chaining the results.
Trait Implementations§
source§impl AsRef<Path> for DeveloperDirectory
impl AsRef<Path> for DeveloperDirectory
source§impl Clone for DeveloperDirectory
impl Clone for DeveloperDirectory
source§fn clone(&self) -> DeveloperDirectory
fn clone(&self) -> DeveloperDirectory
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for DeveloperDirectory
impl Debug for DeveloperDirectory
source§impl From<&Path> for DeveloperDirectory
impl From<&Path> for DeveloperDirectory
source§impl From<&PathBuf> for DeveloperDirectory
impl From<&PathBuf> for DeveloperDirectory
source§impl From<PathBuf> for DeveloperDirectory
impl From<PathBuf> for DeveloperDirectory
source§impl PartialEq<DeveloperDirectory> for DeveloperDirectory
impl PartialEq<DeveloperDirectory> for DeveloperDirectory
source§fn eq(&self, other: &DeveloperDirectory) -> bool
fn eq(&self, other: &DeveloperDirectory) -> bool
self and other values to be equal, and is used
by ==.impl Eq for DeveloperDirectory
impl StructuralEq for DeveloperDirectory
impl StructuralPartialEq for DeveloperDirectory
Auto Trait Implementations§
impl RefUnwindSafe for DeveloperDirectory
impl Send for DeveloperDirectory
impl Sync for DeveloperDirectory
impl Unpin for DeveloperDirectory
impl UnwindSafe for DeveloperDirectory
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.