use crate::ToolContext;
use rustc_hash::FxHashMap;
use semver::VersionReq;
use std::path::PathBuf;
use system_env::SystemDependency;
use warpgate_api::{api_enum, api_struct};
api_struct!(
pub struct BuildInstructionsInput {
pub context: ToolContext,
}
);
api_struct!(
pub struct ArchiveSource {
pub url: String,
pub prefix: Option<String>,
}
);
api_struct!(
pub struct GitSource {
pub url: String,
pub reference: String,
pub submodules: bool,
}
);
api_enum!(
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum SourceLocation {
#[cfg_attr(feature = "schematic", schema(nested))]
Archive(ArchiveSource),
#[cfg_attr(feature = "schematic", schema(nested))]
Git(GitSource),
}
);
api_struct!(
pub struct CommandInstruction {
pub bin: String,
pub args: Vec<String>,
pub env: FxHashMap<String, String>,
pub cwd: Option<PathBuf>,
}
);
impl CommandInstruction {
pub fn new<I: IntoIterator<Item = V>, V: AsRef<str>>(bin: &str, args: I) -> Self {
Self {
bin: bin.to_owned(),
args: args
.into_iter()
.map(|arg| arg.as_ref().to_owned())
.collect(),
env: FxHashMap::default(),
cwd: None,
}
}
}
api_enum!(
#[serde(tag = "type", content = "instruction", rename_all = "kebab-case")]
pub enum BuildInstruction {
MakeExecutable(PathBuf),
MoveFile(PathBuf, PathBuf),
RemoveDir(PathBuf),
RemoveFile(PathBuf),
RequestScript(String),
#[cfg_attr(feature = "schematic", schema(nested))]
RunCommand(Box<CommandInstruction>),
}
);
api_enum!(
#[serde(tag = "type", content = "requirement", rename_all = "kebab-case")]
pub enum BuildRequirement {
CommandExistsOnPath(String),
ManualIntercept(String), GitConfigSetting(String, String),
GitVersion(VersionReq),
PythonVersion(VersionReq),
RubyVersion(VersionReq),
XcodeCommandLineTools,
WindowsDeveloperMode,
}
);
api_struct!(
pub struct BuildInstructionsOutput {
pub help_url: Option<String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub instructions: Vec<BuildInstruction>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub requirements: Vec<BuildRequirement>,
pub source: Option<SourceLocation>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub system_dependencies: Vec<SystemDependency>,
}
);