Skip to content

Commit

Permalink
Merge pull request #169 from boozook/cargo/skip-pre-build
Browse files Browse the repository at this point in the history
Add option to skip assets pre-build step
  • Loading branch information
boozook authored Oct 6, 2023
2 parents e6ef141 + 002e761 commit 7beb6d0
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cargo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
59 changes: 28 additions & 31 deletions cargo/src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult<AssetsArtifacts<'cfg>> {
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(),
Expand All @@ -211,10 +213,8 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult<AssetsArtifacts<'cfg>> {
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)
Expand Down Expand Up @@ -272,38 +272,39 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult<AssetsArtifacts<'cfg>> {


// 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(())
};

// 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;
Expand All @@ -314,16 +315,12 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult<AssetsArtifacts<'cfg>> {
}

// 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;
}
Expand Down
2 changes: 2 additions & 0 deletions cargo/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ pub fn initialize_from(args: impl IntoIterator<Item = impl Into<OsString> + 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,
Expand All @@ -282,6 +283,7 @@ pub fn initialize_from(args: impl IntoIterator<Item = impl Into<OsString> + AsRe
quiet,
dry_run,
skip_unknown,
skip_prebuild,
no_sdk,
no_gcc,
sdk_path,
Expand Down
21 changes: 19 additions & 2 deletions cargo/src/cli/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ pub fn special_args_for(cmd: &Cmd) -> Vec<Arg> {
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![
Expand Down Expand Up @@ -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 {
Expand All @@ -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")
}
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions cargo/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<PathBuf>,
Expand Down Expand Up @@ -103,6 +105,7 @@ impl<'cfg> Config<'cfg> {
quiet,
dry_run,
skip_unknown,
skip_prebuild,
no_sdk,
no_gcc,
sdk_path,
Expand Down

0 comments on commit 7beb6d0

Please sign in to comment.