pub struct DeveloperDirectory { /* private fields */ }
Expand description

A directory containing Apple platforms, SDKs, and other tools.

Implementations§

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?
src/lib.rs (line 582)
581
582
583
584
585
586
587
588
589
590
591
    pub fn find_default() -> Result<Option<Self>, Error> {
        if let Some(v) = Self::from_env()? {
            Ok(Some(v))
        } else if let Some(v) = Self::default_xcode() {
            Ok(Some(v))
        } else if let Ok(v) = Self::from_xcode_select() {
            Ok(Some(v))
        } else {
            Ok(None)
        }
    }
More examples
Hide additional examples
src/search.rs (line 165)
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())),
        }
    }

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?
src/lib.rs (line 586)
581
582
583
584
585
586
587
588
589
590
591
    pub fn find_default() -> Result<Option<Self>, Error> {
        if let Some(v) = Self::from_env()? {
            Ok(Some(v))
        } else if let Some(v) = Self::default_xcode() {
            Ok(Some(v))
        } else if let Ok(v) = Self::from_xcode_select() {
            Ok(Some(v))
        } else {
            Ok(None)
        }
    }
More examples
Hide additional examples
src/search.rs (line 190)
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())),
        }
    }

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?
src/lib.rs (line 584)
581
582
583
584
585
586
587
588
589
590
591
    pub fn find_default() -> Result<Option<Self>, Error> {
        if let Some(v) = Self::from_env()? {
            Ok(Some(v))
        } else if let Some(v) = Self::default_xcode() {
            Ok(Some(v))
        } else if let Ok(v) = Self::from_xcode_select() {
            Ok(Some(v))
        } else {
            Ok(None)
        }
    }
More examples
Hide additional examples
src/search.rs (line 174)
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())),
        }
    }

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?
src/search.rs (line 193)
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())),
        }
    }

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:

  1. DEVELOPER_DIR
  2. System Xcode.app application.
  3. xcode-select output.

Errors only if DEVELOPER_DIR is defined and it points to an invalid path. Errors from running xcode-select are ignored.

Examples found in repository?
src/lib.rs (line 598)
597
598
599
600
601
602
603
    pub fn find_default_required() -> Result<Self, Error> {
        if let Some(v) = Self::find_default()? {
            Ok(v)
        } else {
            Err(Error::DeveloperDirectoryNotFound)
        }
    }

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.

The filesystem path to this developer directory.

Examples found in repository?
src/search.rs (line 135)
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())),
        }
    }

The path to the directory containing platforms.

Examples found in repository?
src/lib.rs (line 625)
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)
    }

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?
src/lib.rs (line 660)
658
659
660
661
662
663
664
665
666
667
    pub fn sdks<SDK: AppleSdk>(&self) -> Result<Vec<SDK>, Error> {
        Ok(self
            .platforms()?
            .into_iter()
            .map(|platform| Ok(platform.find_sdks()?.into_iter()))
            .collect::<Result<Vec<_>, Error>>()?
            .into_iter()
            .flatten()
            .collect::<Vec<_>>())
    }
More examples
Hide additional examples
src/search.rs (line 167)
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())),
        }
    }

Find SDKs within this developer directory.

This is a convenience method for calling Self::platforms() + PlatformDirectory::find_sdks() and chaining the results.

Trait Implementations§

Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.