Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ enum Opts {

#[structopt(help = "ignore patches", long = "ignore-patches")]
ignore_patches: bool,

#[structopt(
help = "Do not transfer .git. Note that .git is hidden so .git is transferred only \
if --transfer-hidden|-h is set and --no-transfer-git|-G is not set",
short = "G",
long = "no-transfer-git"
)]
no_transfer_git: bool,
},
}

Expand Down Expand Up @@ -130,6 +138,7 @@ fn main() {
command,
options,
ignore_patches,
no_transfer_git,
} = Opts::from_args();

let mut metadata_cmd = cargo_metadata::MetadataCommand::new();
Expand Down Expand Up @@ -196,18 +205,24 @@ fn main() {
&format!("{}/", project_dir.display()),
&format!("{}:{}", build_server, build_path),
hidden,
no_transfer_git,
)
.unwrap_or_else(|e| {
error!("Failed to transfer project to build server (error: {})", e);
exit(-4);
});

if !ignore_patches {
patches::handle_patches(&build_path, &build_server, manifest_path, hidden).unwrap_or_else(
|err| {
log::error!("Could not transfer patched workspaces to remote: {}", err);
},
);
patches::handle_patches(
&build_path,
&build_server,
manifest_path,
hidden,
no_transfer_git,
)
.unwrap_or_else(|err| {
log::error!("Could not transfer patched workspaces to remote: {}", err);
});
} else {
log::debug!("Potential patches will be ignored due to command line flag.");
}
Expand Down Expand Up @@ -300,6 +315,7 @@ pub fn copy_to_remote(
local_dir: &str,
remote_dir: &str,
hidden: bool,
no_transfer_git: bool,
) -> Result<std::process::Output, std::io::Error> {
let mut rsync_to = Command::new("rsync");
rsync_to
Expand All @@ -317,6 +333,10 @@ pub fn copy_to_remote(
rsync_to.arg("--exclude").arg(".*");
}

if no_transfer_git {
rsync_to.arg("--exclude").arg(".git");
}

rsync_to
.arg("--rsync-path")
.arg("mkdir -p remote-builds && rsync")
Expand Down
17 changes: 11 additions & 6 deletions src/patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn handle_patches(
build_server: &String,
manifest_path: PathBuf,
copy_hidden_files: bool,
no_transfer_git: bool,
) -> Result<(), String> {
let cargo_file_content = std::fs::read_to_string(&manifest_path).map_err(|err| {
format!(
Expand All @@ -38,6 +39,7 @@ pub fn handle_patches(
patched_cargo_doc,
project_list,
copy_hidden_files,
no_transfer_git,
)?;
}
Ok(())
Expand Down Expand Up @@ -114,11 +116,7 @@ fn extract_patched_crates_and_adjust_toml<F: Fn(PathBuf) -> Result<PathBuf, Stri
for inline_crate_table in patched_paths {
// We only act if there is a path given for a crate
if let Some(path) = inline_crate_table.get("path") {
let path = PathBuf::from(
path.as_str()
.ok_or("Unable to get path from toml Value")?
.clone(),
);
let path = PathBuf::from(path.as_str().ok_or("Unable to get path from toml Value")?);

// Check if the current crate is located in a subfolder of a workspace we
// already know.
Expand Down Expand Up @@ -192,6 +190,7 @@ fn copy_patches_to_remote(
patched_cargo_doc: Document,
projects_to_copy: Vec<PatchProject>,
copy_hidden_files: bool,
no_transfer_git: bool,
) -> Result<(), String> {
for patch_operation in projects_to_copy.iter() {
let local_proj_path = format!("{}/", patch_operation.local_path.display());
Expand All @@ -207,7 +206,13 @@ fn copy_patches_to_remote(
&remote_proj_path
);
// transfer project to build server
copy_to_remote(&local_proj_path, &remote_proj_path, copy_hidden_files).map_err(|err| {
copy_to_remote(
&local_proj_path,
&remote_proj_path,
copy_hidden_files,
no_transfer_git,
)
.map_err(|err| {
format!(
"Failed to transfer project {} to build server (error: {})",
local_proj_path, err
Expand Down
Loading