polyhorn_cli/ios/tasks/
build_xcodeproj.rs

1use std::process::{Command, Stdio};
2
3use super::{IOSContext, IOSError};
4use crate::core::{Manager, Task};
5
6/// This task builds an .xcodeproj with the given scheme, configuration and
7/// destination. It does not install the resulting product.
8pub struct BuildXcodeproj {
9    /// The scheme that will be used to build the xcodeproj.
10    pub scheme: String,
11
12    /// The configuration that will be used to build the xcodeproj.
13    pub configuration: String,
14
15    /// The destination platform that will be used to build the xcodeproj. E.g.
16    /// "iOS Simulator".
17    pub destination_platform: String,
18
19    /// The destination name that will be used to build the xcodeproj. E.g.
20    /// "iPhone SE (2nd generation)".
21    pub destination_name: String,
22}
23
24impl Task for BuildXcodeproj {
25    type Context = IOSContext;
26    type Error = IOSError;
27
28    fn verb(&self) -> &str {
29        "Building"
30    }
31
32    fn message(&self) -> &str {
33        "xcodeproj"
34    }
35
36    fn detail(&self) -> &str {
37        ""
38    }
39
40    fn run(
41        &self,
42        context: Self::Context,
43        _manager: &mut Manager,
44    ) -> Result<Self::Context, Self::Error> {
45        let target_dir = context.config.target_dir.join("polyhorn-ios");
46
47        assert!(Command::new("xcrun")
48            .arg("xcodebuild")
49            .arg("-scheme")
50            .arg(&self.scheme)
51            .arg("-configuration")
52            .arg(&self.configuration)
53            .arg("-destination")
54            .arg(format!(
55                "platform={},name={}",
56                self.destination_platform, self.destination_name
57            ))
58            .arg("-derivedDataPath")
59            .arg("derived-data")
60            .stdout(Stdio::null())
61            .current_dir(target_dir)
62            .spawn()
63            .unwrap()
64            .wait()
65            .unwrap()
66            .success());
67
68        Ok(context)
69    }
70}