diff --git a/Cargo.lock b/Cargo.lock index 3fd191a4..54cd1a1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -353,7 +353,7 @@ dependencies = [ [[package]] name = "cargo-playdate" -version = "0.3.8" +version = "0.3.9" dependencies = [ "anyhow", "byteorder", diff --git a/cargo/Cargo.toml b/cargo/Cargo.toml index 39f12a5d..08688b0d 100644 --- a/cargo/Cargo.toml +++ b/cargo/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-playdate" -version = "0.3.8" +version = "0.3.9" readme = "README.md" description = "Build tool for neat yellow console." keywords = ["playdate", "build", "cargo", "plugin", "cargo-subcommand"] diff --git a/cargo/src/assets/mod.rs b/cargo/src/assets/mod.rs index 8948bb7d..82741296 100644 --- a/cargo/src/assets/mod.rs +++ b/cargo/src/assets/mod.rs @@ -202,6 +202,8 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult> { locked.prepare()?; for (dependency, mut plan) in plans.into_iter() { + let dep_pkg_id = dependency.package_id(); + let apply = |plan: CachedPlan, kind| -> CargoResult<()> { let dest = match kind { AssetKind::Package => locked.as_inner().assets(), @@ -211,10 +213,8 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult> { AssetKind::Package => "", AssetKind::Dev => "dev-", }; - config.log().status( - "Build", - format!("{kind_prefix}assets for {}", dependency.package_id()), - ); + config.log() + .status("Build", format!("{kind_prefix}assets for {}", dep_pkg_id)); config.log().verbose(|mut log| { let s = format!("destination: {}", dest.as_relative_to_root(config).display()); log.status("", s) @@ -272,21 +272,26 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult> { // finally build with pdc: - match pdc::build(config, dependency, locked.as_inner(), kind) { - Ok(_) => { - config.log().status( - "Finished", - format!("{kind_prefix}assets for {}", dependency.package_id()), - ); - }, - Err(err) => { - let message = format!("build with pdc failed: {err}"); - config.log() - .status_with_color("Error", message, termcolor::Color::Red); - if !config.compile_options.build_config.keep_going { - bail!("Assets build failed."); - } - }, + // if not disallowed explicitly + if config.skip_prebuild { + const REASON: &str = "as requested"; + let msg = format!("{kind_prefix}assets pre-build for {}, {REASON}.", dep_pkg_id); + config.log().status("Skip", msg); + } else { + match pdc::build(config, dependency, locked.as_inner(), kind) { + Ok(_) => { + let msg = format!("{kind_prefix}assets for {}", dep_pkg_id); + config.log().status("Finished", msg); + }, + Err(err) => { + let msg = format!("build {kind_prefix}assets with pdc failed: {err}"); + config.log() + .status_with_color("Error", msg, termcolor::Color::Red); + if !config.compile_options.build_config.keep_going { + bail!("Assets build failed."); + } + }, + } } Ok(()) @@ -294,16 +299,12 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult> { // main: let mut main_cache_hit = false; - if dependency.package_id() == target_pid { + if dep_pkg_id == target_pid { if let Some(plan) = plan.main.take() { if plan.difference.is_same() { config.log().status( "Skip", - format!( - "{}, cache state is {:?}", - dependency.package_id(), - &plan.difference - ), + format!("{}, cache state is {:?}", dep_pkg_id, &plan.difference), ); main_cache_hit = true; // continue; @@ -314,16 +315,12 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult> { } // dev: - if dependency.package_id() == target_pid { + if dep_pkg_id == target_pid { if let Some(plan) = plan.dev.take() { if main_cache_hit && plan.difference.is_same() { config.log().status( "Skip", - format!( - "{} (dev), cache state is {:?}", - dependency.package_id(), - &plan.difference - ), + format!("{} (dev), cache state is {:?}", dep_pkg_id, &plan.difference), ); continue; } diff --git a/cargo/src/cli/mod.rs b/cargo/src/cli/mod.rs index 834cfaed..c23a9a72 100644 --- a/cargo/src/cli/mod.rs +++ b/cargo/src/cli/mod.rs @@ -274,6 +274,7 @@ pub fn initialize_from(args: impl IntoIterator + AsRe let dry_run = matches.dry_run(); let skip_unknown = matches.flag("skip-unknown"); + let skip_prebuild = matches.flag("no-pre-build"); return Ok(Config::new( cmd, @@ -282,6 +283,7 @@ pub fn initialize_from(args: impl IntoIterator + AsRe quiet, dry_run, skip_unknown, + skip_prebuild, no_sdk, no_gcc, sdk_path, diff --git a/cargo/src/cli/opts.rs b/cargo/src/cli/opts.rs index 86a67030..0e6bd030 100644 --- a/cargo/src/cli/opts.rs +++ b/cargo/src/cli/opts.rs @@ -50,15 +50,19 @@ pub fn special_args_for(cmd: &Cmd) -> Vec { args.append(&mut shorthands_for(cmd)); args.push(flag_no_wait()); args.push(flag_no_info_file()); + args.push(flag_pdc_skip_unknown()); + args.push(flag_pdc_skip_prebuild()); args }, Cmd::Package => { let mut args = special_args_for(&Cmd::Build); args.push(flag_zip_package()); args.push(flag_no_info_file()); + args.push(flag_pdc_skip_unknown()); + args.push(flag_pdc_skip_prebuild()); args }, - Cmd::Assets => vec![flag_pdc_skip_unknown()], + Cmd::Assets => vec![flag_pdc_skip_unknown(), flag_pdc_skip_prebuild()], Cmd::New => { vec![ @@ -169,7 +173,11 @@ fn run() -> Command { fn package() -> Command { // extend `build` command: build().name(Cmd::Package.as_ref()) - .arg(flag_zip_package()).about("Compile a local package and all of its dependencies, build assets for them, manifests for local crates and pack it all together.") + .arg(flag_zip_package()) + .arg(flag_no_info_file()) + .arg(flag_pdc_skip_unknown()) + .arg(flag_pdc_skip_prebuild()) + .about("Compile a local package and all of its dependencies, build assets for them, manifests for local crates and pack it all together.") } fn migrate() -> Command { @@ -178,6 +186,7 @@ fn migrate() -> Command { } fn publish() -> Command { Command::new(Cmd::Publish.as_ref()).arg(flag_zip_package().default_value("true")) + .arg(flag_no_info_file()) .ignore_errors(true) .about("non implemented yet") } @@ -277,6 +286,14 @@ fn flag_pdc_skip_unknown() -> Arg { .action(ArgAction::SetTrue) } +fn flag_pdc_skip_prebuild() -> Arg { + let name = "no-pre-build"; + Arg::new(&name).long(&name) + .help(format!("Skip the pre-build assets step")) + .conflicts_with("no-sdk") + .action(ArgAction::SetTrue) +} + fn flag_zip_package() -> Arg { let name = "zip"; Arg::new(&name).long(&name) diff --git a/cargo/src/config.rs b/cargo/src/config.rs index 634881ac..303e5fdd 100644 --- a/cargo/src/config.rs +++ b/cargo/src/config.rs @@ -30,6 +30,7 @@ pub struct Config<'cfg> { pub dry_run: bool, pub skip_unknown: bool, + pub skip_prebuild: bool, pub no_sdk: bool, pub no_gcc: bool, @@ -76,6 +77,7 @@ impl<'cfg> Config<'cfg> { quiet: bool, dry_run: bool, skip_unknown: bool, + skip_prebuild: bool, no_sdk: bool, no_gcc: bool, sdk_path: Option, @@ -103,6 +105,7 @@ impl<'cfg> Config<'cfg> { quiet, dry_run, skip_unknown, + skip_prebuild, no_sdk, no_gcc, sdk_path,