Skip to content

Commit

Permalink
feat: make recipe storing optional (defaults to true) (prefix-dev#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Nov 10, 2023
1 parent 2e01c72 commit 4463fef
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
45 changes: 28 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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)]
Expand All @@ -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();
Expand Down Expand Up @@ -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,
&timestamp,
)
Expand All @@ -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,
};
Expand All @@ -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/*)
Expand All @@ -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(),
Expand Down
8 changes: 8 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -177,6 +182,9 @@ pub struct BuildConfiguration {
pub subpackages: BTreeMap<PackageName, PackageIdentifier>,
/// 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 {
Expand Down
7 changes: 4 additions & 3 deletions src/packaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4463fef

Please sign in to comment.