rel make: Add `--quiet`/`-q`, `--names`/`-n` args

`-n` is a somewhat ugly hack to only select certain modules from `config.yml`, for games with overlapping module IDs
This commit is contained in:
Luke Street 2023-11-18 23:34:44 -05:00
parent 38c692650f
commit 28af4872ab
1 changed files with 34 additions and 13 deletions

View File

@ -96,9 +96,15 @@ pub struct MakeArgs {
#[argp(option, short = 'c')] #[argp(option, short = 'c')]
/// (optional) project configuration file /// (optional) project configuration file
config: Option<PathBuf>, config: Option<PathBuf>,
#[argp(option, short = 'n')]
/// (optional) module names
names: Vec<String>,
#[argp(switch, short = 'w')] #[argp(switch, short = 'w')]
/// disable warnings /// disable warnings
no_warn: bool, no_warn: bool,
#[argp(switch, short = 'q')]
/// only print errors
quiet: bool,
} }
pub fn run(args: Args) -> Result<()> { pub fn run(args: Args) -> Result<()> {
@ -250,16 +256,26 @@ fn make(args: MakeArgs) -> Result<()> {
if let Some(config_path) = &args.config { if let Some(config_path) = &args.config {
let config: ProjectConfig = serde_yaml::from_reader(&mut buf_reader(config_path)?)?; let config: ProjectConfig = serde_yaml::from_reader(&mut buf_reader(config_path)?)?;
for module_config in &config.modules { for module_config in &config.modules {
if !args.names.is_empty() && !args.names.iter().any(|n| n == &module_config.name()) {
continue;
}
let _span = info_span!("module", name = %module_config.name()).entered(); let _span = info_span!("module", name = %module_config.name()).entered();
let info = load_rel(module_config).with_context(|| { let info = load_rel(module_config).with_context(|| {
format!("While loading REL '{}'", module_config.object.display()) format!("While loading REL '{}'", module_config.object.display())
})?; })?;
existing_headers.insert(info.0.module_id, info); match existing_headers.entry(info.0.module_id) {
btree_map::Entry::Vacant(e) => e.insert(info),
btree_map::Entry::Occupied(_) => {
bail!("Duplicate module ID {}", info.0.module_id)
}
};
} }
} }
let paths = process_rsp(&args.files)?; let paths = process_rsp(&args.files)?;
if !args.quiet {
info!("Loading {} modules", paths.len()); info!("Loading {} modules", paths.len());
}
// Load all modules // Load all modules
let files = paths.iter().map(map_file).collect::<Result<Vec<_>>>()?; let files = paths.iter().map(map_file).collect::<Result<Vec<_>>>()?;
@ -304,6 +320,7 @@ fn make(args: MakeArgs) -> Result<()> {
.with_context(|| format!("While resolving relocations in '{}'", path.display()))?; .with_context(|| format!("While resolving relocations in '{}'", path.display()))?;
} }
if !args.quiet {
let duration = start.elapsed(); let duration = start.elapsed();
info!( info!(
"Symbol resolution completed in {}.{:03}s (resolved {} symbols)", "Symbol resolution completed in {}.{:03}s (resolved {} symbols)",
@ -311,6 +328,7 @@ fn make(args: MakeArgs) -> Result<()> {
duration.subsec_millis(), duration.subsec_millis(),
resolved resolved
); );
}
// Write RELs // Write RELs
let start = Instant::now(); let start = Instant::now();
@ -347,11 +365,14 @@ fn make(args: MakeArgs) -> Result<()> {
.with_context(|| format!("Failed to write '{}'", rel_path.display()))?; .with_context(|| format!("Failed to write '{}'", rel_path.display()))?;
w.flush()?; w.flush()?;
} }
if !args.quiet {
let duration = start.elapsed(); let duration = start.elapsed();
info!("RELs written in {}.{:03}s", duration.as_secs(), duration.subsec_millis()); info!("RELs written in {}.{:03}s", duration.as_secs(), duration.subsec_millis());
let duration = total.elapsed(); let duration = total.elapsed();
info!("Total time: {}.{:03}s", duration.as_secs(), duration.subsec_millis()); info!("Total time: {}.{:03}s", duration.as_secs(), duration.subsec_millis());
}
Ok(()) Ok(())
} }