mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-06-24 05:44:17 +08:00
Adds patches and script to SourceRecipe::Git
This commit is contained in:
parent
69c6dd237a
commit
bde00ef0c7
@ -249,6 +249,8 @@ fn fetch(recipe_dir: &Path, source: &Option<SourceRecipe>) -> Result<PathBuf, St
|
||||
upstream,
|
||||
branch,
|
||||
rev,
|
||||
patches,
|
||||
script,
|
||||
}) => {
|
||||
//TODO: use libgit?
|
||||
if !source_dir.is_dir() {
|
||||
@ -326,6 +328,14 @@ fi"#,
|
||||
run_command(command)?;
|
||||
}
|
||||
|
||||
if !patches.is_empty() || script.is_some() {
|
||||
// Hard reset
|
||||
let mut command = Command::new("git");
|
||||
command.arg("-C").arg(&source_dir);
|
||||
command.arg("reset").arg("--hard");
|
||||
run_command(command)?;
|
||||
}
|
||||
|
||||
// Sync submodules URL
|
||||
let mut command = Command::new("git");
|
||||
command.arg("-C").arg(&source_dir);
|
||||
@ -341,6 +351,41 @@ fi"#,
|
||||
.arg("--init")
|
||||
.arg("--recursive");
|
||||
run_command(command)?;
|
||||
|
||||
// Apply patches
|
||||
for patch_name in patches {
|
||||
let patch_file = recipe_dir.join(patch_name);
|
||||
if !patch_file.is_file() {
|
||||
return Err(format!(
|
||||
"failed to find patch file '{}'",
|
||||
patch_file.display()
|
||||
));
|
||||
}
|
||||
|
||||
let patch = fs::read_to_string(&patch_file).map_err(|err| {
|
||||
format!(
|
||||
"failed to read patch file '{}': {}\n{:#?}",
|
||||
patch_file.display(),
|
||||
err,
|
||||
err
|
||||
)
|
||||
})?;
|
||||
|
||||
let mut command = Command::new("patch");
|
||||
command.arg("--forward");
|
||||
command.arg("--batch");
|
||||
command.arg("--directory").arg(&source_dir);
|
||||
command.arg("--strip=1");
|
||||
run_command_stdin(command, patch.as_bytes())?;
|
||||
}
|
||||
|
||||
// Run source script
|
||||
if let Some(script) = script {
|
||||
let mut command = Command::new("bash");
|
||||
command.arg("-ex");
|
||||
command.current_dir(&source_dir);
|
||||
run_command_stdin(command, format!("{SHARED_PRESCRIPT}\n{script}").as_bytes())?;
|
||||
}
|
||||
}
|
||||
Some(SourceRecipe::Tar {
|
||||
tar,
|
||||
|
||||
@ -36,6 +36,11 @@ pub enum SourceRecipe {
|
||||
/// The optional revision of the git repository to use for builds. Please specify for
|
||||
/// reproducible builds
|
||||
rev: Option<String>,
|
||||
/// A list of patch files to apply to the source
|
||||
#[serde(default)]
|
||||
patches: Vec<String>,
|
||||
/// Optional script to run to prepare the source
|
||||
script: Option<String>,
|
||||
},
|
||||
/// A tar file source
|
||||
Tar {
|
||||
@ -236,6 +241,8 @@ mod tests {
|
||||
upstream: None,
|
||||
branch: Some("master".to_string()),
|
||||
rev: Some("06344744d3d55a5ac9a62a6059cb363d40699bbc".to_string()),
|
||||
patches: Vec::new(),
|
||||
script: None,
|
||||
}),
|
||||
build: BuildRecipe {
|
||||
kind: BuildKind::Cargo {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user