diff --git a/src/main.rs b/src/main.rs index 8158f7e78..b393f7ea1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,6 +68,14 @@ enum PackageFormat { Conda, } +/// Common opts that are shared between [`Rebuild`] and [`Build`]` subcommands +#[derive(Parser)] +struct CommonOpts { + /// Output directory for build artifacts. Defaults to `./output`. + #[clap(long, env = "CONDA_BLD_PATH", default_value = "./output")] + output_dir: PathBuf, +} + #[derive(Parser)] struct BuildOpts { /// The recipe file or directory containing `recipe.yaml`. Defaults to the current directory. @@ -95,10 +103,6 @@ struct BuildOpts { #[arg(long)] keep_build: bool, - /// Output directory for build artifacts. Defaults to `./output`. - #[clap(long, env = "CONDA_BLD_PATH", default_value = "./output")] - output_dir: PathBuf, - /// Don't use build id(timestamp) when creating build directory name. Defaults to `false`. #[arg(long)] no_build_id: bool, @@ -107,6 +111,13 @@ struct BuildOpts { /// Defaults to `.tar.bz2`. #[arg(long, default_value = "tar-bz2")] package_format: PackageFormat, + + /// Do not store the recipe in the final package + #[arg(long)] + no_include_recipe: bool, + + #[clap(flatten)] + common: CommonOpts, } #[derive(Parser)] @@ -116,6 +127,16 @@ struct TestOpts { package_file: PathBuf, } +#[derive(Parser)] +struct RebuildOpts { + /// The package file to rebuild + #[arg(short, long)] + package_file: PathBuf, + + #[clap(flatten)] + common: CommonOpts, +} + #[tokio::main] async fn main() -> miette::Result<()> { let args = App::parse(); @@ -319,7 +340,7 @@ async fn run_build_from_args(args: BuildOpts, multi_progress: MultiProgress) -> directories: Directories::create( name.as_normalized(), &recipe_path, - &args.output_dir, + &args.common.output_dir, args.no_build_id, ×tamp, ) @@ -331,6 +352,7 @@ async fn run_build_from_args(args: BuildOpts, multi_progress: MultiProgress) -> PackageFormat::TarBz2 => ArchiveType::TarBz2, PackageFormat::Conda => ArchiveType::Conda, }, + store_recipe: !args.no_include_recipe, }, finalized_dependencies: None, }; @@ -342,17 +364,6 @@ async fn run_build_from_args(args: BuildOpts, multi_progress: MultiProgress) -> Ok(()) } -#[derive(Parser)] -struct RebuildOpts { - /// The package file to rebuild - #[arg(short, long)] - package_file: PathBuf, - - /// Output directory for build artifacts. Defaults to `./output`. - #[clap(long, env = "CONDA_BLD_PATH", default_value = "./output")] - output_dir: PathBuf, -} - async fn rebuild_from_args(args: RebuildOpts) -> miette::Result<()> { tracing::info!("Rebuilding {}", args.package_file.to_string_lossy()); // we extract the recipe folder from the package file (info/recipe/*) @@ -374,7 +385,7 @@ async fn rebuild_from_args(args: RebuildOpts) -> miette::Result<()> { // set recipe dir to the temp folder output.build_configuration.directories.recipe_dir = temp_dir; output.build_configuration.directories.output_dir = - fs::canonicalize(args.output_dir).into_diagnostic()?; + fs::canonicalize(args.common.output_dir).into_diagnostic()?; let tool_config = tool_configuration::Configuration { client: AuthenticatedClient::default(), diff --git a/src/metadata.rs b/src/metadata.rs index 28f1f4bfc..0f88471c2 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -155,6 +155,11 @@ impl Directories { } } +/// Default value for store recipe for backwards compatiblity +fn default_true() -> bool { + true +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BuildConfiguration { /// The target platform for the build @@ -177,6 +182,9 @@ pub struct BuildConfiguration { pub subpackages: BTreeMap, /// Package format (.tar.bz2 or .conda) pub package_format: ArchiveType, + /// Wether to store the recipe and build instructions in the final package or not + #[serde(skip_serializing, default = "default_true")] + pub store_recipe: bool, } impl BuildConfiguration { diff --git a/src/packaging.rs b/src/packaging.rs index 6818fecdd..363faadf5 100644 --- a/src/packaging.rs +++ b/src/packaging.rs @@ -864,9 +864,10 @@ pub fn package_conda( variant_config .write_all(serde_json::to_string_pretty(&output.build_configuration.variant)?.as_bytes())?; - // TODO write recipe to info/recipe/ folder - let recipe_files = write_recipe_folder(output, tmp_dir_path)?; - tmp_files.extend(recipe_files); + if output.build_configuration.store_recipe { + let recipe_files = write_recipe_folder(output, tmp_dir_path)?; + tmp_files.extend(recipe_files); + } let test_files = write_test_files(output, tmp_dir_path)?; tmp_files.extend(test_files);