proto_pdk_api/api/
build.rs1use super::source::*;
2use crate::PluginContext;
3use derive_setters::Setters;
4use rustc_hash::FxHashMap;
5use semver::VersionReq;
6use std::path::PathBuf;
7use system_env::SystemDependency;
8use warpgate_api::{Id, VirtualPath, api_enum, api_struct};
9
10api_struct!(
11 pub struct BuildInstructionsInput {
13 pub context: PluginContext,
15
16 pub install_dir: VirtualPath,
18 }
19);
20
21api_struct!(
22 #[derive(Setters)]
24 pub struct BuilderInstruction {
25 #[setters(into)]
27 pub id: Id,
28
29 pub exe: PathBuf,
31
32 #[serde(default, skip_serializing_if = "FxHashMap::is_empty")]
34 pub exes: FxHashMap<String, PathBuf>,
35
36 pub git: GitSource,
38 }
39);
40
41api_struct!(
42 #[derive(Setters)]
44 pub struct CommandInstruction {
45 pub builder: bool,
47
48 #[serde(default, skip_serializing_if = "Vec::is_empty")]
50 pub args: Vec<String>,
51
52 #[serde(default, skip_serializing_if = "FxHashMap::is_empty")]
54 pub env: FxHashMap<String, String>,
55
56 #[setters(into)]
58 #[serde(alias = "bin")]
59 pub exe: String,
60
61 #[setters(strip_option)]
63 #[serde(default, skip_serializing_if = "Option::is_none")]
64 pub cwd: Option<PathBuf>,
65 }
66);
67
68impl CommandInstruction {
69 pub fn new<T: AsRef<str>, I: IntoIterator<Item = V>, V: AsRef<str>>(exe: T, args: I) -> Self {
71 Self {
72 builder: false,
73 exe: exe.as_ref().to_owned(),
74 args: args
75 .into_iter()
76 .map(|arg| arg.as_ref().to_owned())
77 .collect(),
78 env: FxHashMap::default(),
79 cwd: None,
80 }
81 }
82
83 pub fn with_builder<T: AsRef<str>, I: IntoIterator<Item = V>, V: AsRef<str>>(
85 id: T,
86 args: I,
87 ) -> Self {
88 let mut cmd = Self::new(id, args);
89 cmd.builder = true;
90 cmd
91 }
92}
93
94api_enum!(
95 #[serde(tag = "type", content = "instruction", rename_all = "kebab-case")]
97 pub enum BuildInstruction {
98 InstallBuilder(Box<BuilderInstruction>),
100
101 MakeExecutable(PathBuf),
103
104 MoveFile(PathBuf, PathBuf),
106
107 RemoveAllExcept(Vec<PathBuf>),
109
110 RemoveDir(PathBuf),
112
113 RemoveFile(PathBuf),
115
116 RequestScript(String),
118
119 #[cfg_attr(feature = "schematic", schema(nested))]
121 RunCommand(Box<CommandInstruction>),
122
123 SetEnvVar(String, String),
125 }
126);
127
128api_enum!(
129 #[serde(tag = "type", content = "requirement", rename_all = "kebab-case")]
131 pub enum BuildRequirement {
132 CommandExistsOnPath(String),
133 CommandVersion(String, VersionReq, Option<String>),
134 ManualIntercept(String), GitConfigSetting(String, String),
136 GitVersion(VersionReq),
137 XcodeCommandLineTools,
139 WindowsDeveloperMode,
141 }
142);
143
144api_struct!(
145 #[serde(default)]
147 pub struct BuildInstructionsOutput {
148 #[serde(skip_serializing_if = "Option::is_none")]
150 pub help_url: Option<String>,
151
152 #[serde(skip_serializing_if = "Vec::is_empty")]
155 pub instructions: Vec<BuildInstruction>,
156
157 #[serde(skip_serializing_if = "Vec::is_empty")]
160 pub requirements: Vec<BuildRequirement>,
161
162 #[serde(skip_serializing_if = "Option::is_none")]
164 pub source: Option<SourceLocation>,
165
166 #[serde(skip_serializing_if = "Vec::is_empty")]
169 pub system_dependencies: Vec<SystemDependency>,
170 }
171);