Skip to content

Commit

Permalink
Added ability to build and install workspace projects with multiple p…
Browse files Browse the repository at this point in the history
…lugins
  • Loading branch information
ko1N committed Mar 29, 2024
1 parent ff3d19c commit b683e23
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ pub async fn handle(matches: &ArgMatches) -> Result<()> {
// run compilation and installation
let source_path =
download_from_repository(repository_or_path, &commit, temp_dir.as_path()).await?;
let artifact_path = build_artifact_from_source(&source_path, all_features).await?;
install_artifact(&artifact_path).await?;
let artifacts = build_artifacts_from_source(&source_path, all_features).await?;
for artifact in artifacts.iter() {
install_artifact(artifact).await.ok();
}
} else {
// install from local path
let path = Path::new(repository_or_path);
Expand All @@ -79,8 +81,10 @@ pub async fn handle(matches: &ArgMatches) -> Result<()> {
));
}

let artifact_path = build_artifact_from_source(path, all_features).await?;
install_artifact(&artifact_path).await?;
let artifacts = build_artifacts_from_source(path, all_features).await?;
for artifact in artifacts.iter() {
install_artifact(artifact).await.ok();
}
}

Ok(())
Expand Down Expand Up @@ -115,7 +119,11 @@ async fn download_from_repository(
}

/// Builds the plugin from the given source path and returns the path of the resulting artifact.
async fn build_artifact_from_source(source_path: &Path, all_features: bool) -> Result<PathBuf> {
/// For workspace repos this can return a list of artifacts.
async fn build_artifacts_from_source(
source_path: &Path,
all_features: bool,
) -> Result<Vec<PathBuf>> {
// build plugin
println!(
"{} Building plugin in: {:?}",
Expand All @@ -131,39 +139,35 @@ async fn build_artifact_from_source(source_path: &Path, all_features: bool) -> R
// try to find a valid artifact in the build folder
let artifact_path = source_path.to_path_buf().join("target").join("release");
let paths = std::fs::read_dir(artifact_path)?;
let mut artifact_file_name = None;
let mut artifacts = Vec::new();
for path in paths.filter_map(|p| p.ok()) {
if path.path().is_file() {
if let Some(extension) = path.path().extension() {
if extension.to_str().unwrap_or_default() == util::plugin_extension() {
artifact_file_name = Some(path.path());
break;
println!(
"{} Plugin artifact successfully built: {:?}",
console::style("[=]").bold().dim().green(),
path.path()
);
artifacts.push(path.path());
}
}
}
}

// extract the artifact file name
let artifact_file_name = match artifact_file_name {
Some(v) => v,
None => {
println!(
if !artifacts.is_empty() {
Ok(artifacts)
} else {
println!(
"{} No valid build artifact with the `{}` file extension found. Are you sure this is a dylib project?",
console::style("[-]").bold().dim(),
util::plugin_extension(),
);
return Err(Error::NotFound(
"no supported build artifact found.".to_string(),
));
}
};
println!(
"{} Plugin artifact successfully built: {:?}",
console::style("[=]").bold().dim().green(),
artifact_file_name
);

Ok(artifact_file_name)
Err(Error::NotFound(
"no supported build artifact found.".to_string(),
))
}
}

async fn install_artifact(artifact_path: &Path) -> Result<()> {
Expand All @@ -185,8 +189,9 @@ async fn install_artifact(artifact_path: &Path) -> Result<()> {
},
None => {
println!(
"{} PluginDescriptor not found in artifact. Are you sure this is a memflow plugin project?",
"{} PluginDescriptor not found in artifact {:?}. Are you sure this is a memflow plugin project?",
console::style("[-]").bold().dim(),
artifact_path
);
return Err(Error::NotFound(
"no supported build artifact found.".to_string(),
Expand Down

0 comments on commit b683e23

Please sign in to comment.