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
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ pub struct Cook {
/// Path to Cargo.toml
#[arg(long)]
manifest_path: Option<PathBuf>,
/// Manifest(s) that should not be overwritten or have their artifacts cleaned up.
#[arg(long)]
ignore_manifest: Option<Vec<PathBuf>>,
/// Package(s) to build (see `cargo help pkgid`)
#[arg(long, short = 'p')]
package: Option<Vec<String>>,
Expand Down Expand Up @@ -183,6 +186,7 @@ fn _main() -> Result<(), anyhow::Error> {
examples,
all_targets,
manifest_path,
ignore_manifest,
package,
workspace,
offline,
Expand Down Expand Up @@ -284,6 +288,7 @@ fn _main() -> Result<(), anyhow::Error> {
target_dir,
target_args,
manifest_path,
ignore_manifest,
package,
workspace,
offline,
Expand Down
13 changes: 12 additions & 1 deletion src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct CookArgs {
pub target_dir: Option<PathBuf>,
pub target_args: TargetArgs,
pub manifest_path: Option<PathBuf>,
pub ignore_manifest: Option<Vec<PathBuf>>,
pub package: Option<Vec<String>>,
pub workspace: bool,
pub offline: bool,
Expand All @@ -57,8 +58,16 @@ impl Recipe {

pub fn cook(&self, args: CookArgs) -> Result<(), anyhow::Error> {
let current_directory = std::env::current_dir()?;
let ignored_manifests = args
.ignore_manifest
.as_deref()
.unwrap_or(&[])
.iter()
.map(|p| current_directory.join(p))
.collect::<Vec<_>>();

self.skeleton
.build_minimum_project(&current_directory, args.no_std)?;
.build_minimum_project(&current_directory, args.no_std, &ignored_manifests)?;
if args.no_build {
return Ok(());
}
Expand All @@ -69,6 +78,7 @@ impl Recipe {
args.profile,
args.target,
args.target_dir,
&ignored_manifests,
)
.context("Failed to clean up dummy compilation artifacts.")?;
Ok(())
Expand Down Expand Up @@ -106,6 +116,7 @@ fn build_dependencies(args: &CookArgs) {
target_dir,
target_args,
manifest_path,
ignore_manifest: _ignore_manifest,
package,
workspace,
offline,
Expand Down
13 changes: 12 additions & 1 deletion src/skeleton/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl Skeleton {
&self,
base_path: &Path,
no_std: bool,
ignored_manifests: &[PathBuf],
) -> Result<(), anyhow::Error> {
// Save lockfile to disk, if available
if let Some(lock_file) = &self.lock_file {
Expand Down Expand Up @@ -146,8 +147,12 @@ fn panic(_: &core::panic::PanicInfo) -> ! {

// Save all manifests to disks
for manifest in &self.manifests {
// Persist manifest
let manifest_path = base_path.join(&manifest.relative_path);
if ignored_manifests.contains(&manifest_path) {
continue;
}

// Persist manifest
let parent_directory = if let Some(parent_directory) = manifest_path.parent() {
fs::create_dir_all(parent_directory)?;
parent_directory.to_path_buf()
Expand Down Expand Up @@ -211,6 +216,7 @@ fn panic(_: &core::panic::PanicInfo) -> ! {
profile: OptimisationProfile,
target: Option<Vec<String>>,
target_dir: Option<PathBuf>,
ignored_paths: &[PathBuf],
) -> Result<(), anyhow::Error> {
let target_dir = match target_dir {
None => base_path.as_ref().join("target"),
Expand Down Expand Up @@ -243,6 +249,11 @@ fn panic(_: &core::panic::PanicInfo) -> ! {
.collect();

for manifest in &self.manifests {
let manifest_path = base_path.as_ref().join(&manifest.relative_path);
if ignored_paths.contains(&manifest_path) {
continue;
}

let parsed_manifest =
cargo_manifest::Manifest::from_slice(manifest.contents.as_bytes())?;
if let Some(package) = parsed_manifest.package.as_ref() {
Expand Down
38 changes: 19 additions & 19 deletions tests/skeletons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ path = "src/main.rs"
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

// Assert
Expand All @@ -53,7 +53,7 @@ path = "src/main.rs"
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), true)
.build_minimum_project(cook_directory.path(), true, &[])
.unwrap();

// Assert (no_std)
Expand Down Expand Up @@ -126,7 +126,7 @@ uuid = { version = "=0.8.0", features = ["v4"] }
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

// Assert
Expand All @@ -148,7 +148,7 @@ uuid = { version = "=0.8.0", features = ["v4"] }
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), true)
.build_minimum_project(cook_directory.path(), true, &[])
.unwrap();

// Assert (no_std)
Expand Down Expand Up @@ -202,7 +202,7 @@ harness = false
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

// Assert
Expand Down Expand Up @@ -240,7 +240,7 @@ name = "foo"
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

// Assert
Expand All @@ -253,7 +253,7 @@ name = "foo"
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), true)
.build_minimum_project(cook_directory.path(), true, &[])
.unwrap();

// Assert (no_std)
Expand Down Expand Up @@ -303,7 +303,7 @@ harness = false
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

cook_directory
Expand Down Expand Up @@ -335,7 +335,7 @@ name = "foo"
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

// Assert
Expand All @@ -351,7 +351,7 @@ name = "foo"
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), true)
.build_minimum_project(cook_directory.path(), true, &[])
.unwrap();

// Assert (no_std)
Expand Down Expand Up @@ -431,7 +431,7 @@ edition = "2018"
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

// Assert
Expand Down Expand Up @@ -469,7 +469,7 @@ edition = "2018"
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

// Assert
Expand Down Expand Up @@ -512,7 +512,7 @@ version = "1.2.3"
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

// Assert
Expand Down Expand Up @@ -615,7 +615,7 @@ dependencies = [
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

// Assert
Expand Down Expand Up @@ -797,7 +797,7 @@ checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

// Assert
Expand Down Expand Up @@ -965,7 +965,7 @@ checksum = "3df10e9ed85b51fa3434bc5676eaa90479ce14ac3e101c8ce07e1bb5ef0b7255"
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

// Assert
Expand Down Expand Up @@ -1255,7 +1255,7 @@ anyhow = { workspace = true }
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

let first = skeleton.manifests[0].clone();
Expand Down Expand Up @@ -1468,7 +1468,7 @@ edition = "2021"
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

// Assert
Expand Down Expand Up @@ -1515,7 +1515,7 @@ channel = "1.75.0"
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.build_minimum_project(cook_directory.path(), false, &[])
.unwrap();

// Assert
Expand Down