Adjustments for use with ninja build

This commit is contained in:
Luke Street 2023-08-05 20:27:05 -04:00
parent 771c380129
commit 4b6e317d0b
6 changed files with 39 additions and 33 deletions

View File

@ -3,7 +3,7 @@ name = "decomp-toolkit"
description = "Yet another GameCube/Wii decompilation toolkit."
authors = ["Luke Street <luke@street.dev>"]
license = "MIT OR Apache-2.0"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
publish = false
build = "build.rs"

View File

@ -26,7 +26,7 @@ use crate::{
config::{apply_splits, parse_symbol_line, write_splits, write_symbols},
dol::process_dol,
elf::{process_elf, write_elf},
file::{map_file, map_reader},
file::{map_file, map_reader, touch},
lcf::{asm_path_for_unit, generate_ldscript, obj_path_for_unit},
},
};
@ -74,6 +74,9 @@ pub struct SplitArgs {
#[argp(option, short = 'e')]
/// ELF file to validate against (debugging only)
elf_file: Option<PathBuf>,
#[argp(switch)]
/// skip updating splits & symbol files (for build systems)
no_update: bool,
}
pub fn run(args: Args) -> Result<()> {
@ -179,20 +182,22 @@ fn split(args: SplitArgs) -> Result<()> {
log::info!("Detecting strings");
detect_strings(&mut obj)?;
if let Some(symbols_path) = &args.symbols_file {
let mut symbols_writer = BufWriter::new(
File::create(symbols_path)
.with_context(|| format!("Failed to create '{}'", symbols_path.display()))?,
);
write_symbols(&mut symbols_writer, &obj)?;
}
if !args.no_update {
if let Some(symbols_path) = &args.symbols_file {
let mut symbols_writer = BufWriter::new(
File::create(symbols_path)
.with_context(|| format!("Failed to create '{}'", symbols_path.display()))?,
);
write_symbols(&mut symbols_writer, &obj)?;
}
if let Some(splits_path) = &args.splits_file {
let mut splits_writer = BufWriter::new(
File::create(splits_path)
.with_context(|| format!("Failed to create '{}'", splits_path.display()))?,
);
write_splits(&mut splits_writer, &obj)?;
if let Some(splits_path) = &args.splits_file {
let mut splits_writer = BufWriter::new(
File::create(splits_path)
.with_context(|| format!("Failed to create '{}'", splits_path.display()))?,
);
write_splits(&mut splits_writer, &obj)?;
}
}
log::info!("Adjusting splits");
@ -202,6 +207,7 @@ fn split(args: SplitArgs) -> Result<()> {
let split_objs = split_obj(&obj)?;
// Create out dirs
touch(&args.out_dir)?;
let asm_dir = args.out_dir.join("asm");
let include_dir = args.out_dir.join("include");
let obj_dir = args.out_dir.join("obj");

View File

@ -1,15 +1,14 @@
use std::{
fs::{File, OpenOptions},
fs::File,
io::{BufRead, BufReader, Read},
path::{Path, PathBuf},
};
use anyhow::{anyhow, bail, Context, Result};
use argp::FromArgs;
use filetime::{set_file_mtime, FileTime};
use sha1::{Digest, Sha1};
use crate::util::file::process_rsp;
use crate::util::file::{process_rsp, touch};
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Print or check SHA1 (160-bit) checksums.
@ -100,14 +99,3 @@ fn file_sha1(mut file: File) -> Result<sha1::digest::Output<Sha1>> {
hasher.update(&buf[0..read]);
})
}
fn touch<P: AsRef<Path>>(path: P) -> std::io::Result<()> {
if path.as_ref().exists() {
set_file_mtime(path, FileTime::now())
} else {
match OpenOptions::new().create(true).write(true).open(path) {
Ok(_) => Ok(()),
Err(e) => Err(e),
}
}
}

View File

@ -88,7 +88,7 @@ pub fn parse_symbol_line(line: &str, obj: &mut ObjInfo) -> Result<Option<ObjSymb
}
}
Ok(Some(symbol))
} else if COMMENT_LINE.is_match(line) {
} else if line.is_empty() || COMMENT_LINE.is_match(line) {
Ok(None)
} else {
Err(anyhow!("Failed to parse symbol line '{line}'"))

View File

@ -1,11 +1,12 @@
use std::{
fs::File,
fs::{File, OpenOptions},
io::{BufRead, BufReader, Cursor, Read},
path::{Path, PathBuf},
};
use anyhow::{anyhow, Context, Result};
use byteorder::ReadBytesExt;
use filetime::{set_file_mtime, FileTime};
use memmap2::{Mmap, MmapOptions};
use crate::util::{rarc, rarc::Node, yaz0};
@ -234,3 +235,14 @@ impl Iterator for FileIterator {
fn next(&mut self) -> Option<Self::Item> { self.next_rarc().or_else(|| self.next_path()) }
}
pub fn touch<P: AsRef<Path>>(path: P) -> std::io::Result<()> {
if path.as_ref().exists() {
set_file_mtime(path, FileTime::now())
} else {
match OpenOptions::new().create(true).write(true).open(path) {
Ok(_) => Ok(()),
Err(e) => Err(e),
}
}
}

View File

@ -286,7 +286,7 @@ impl StateMachine {
}
ProcessMapState::SectionLayout(ref mut state) => {
if let Some(captures) = SECTION_LAYOUT_SYMBOL.captures(&line) {
StateMachine::section_layout_entry(captures, state, &mut self.result)?;
StateMachine::section_layout_entry(captures, state, &self.result)?;
} else if let Some(captures) = SECTION_LAYOUT_START.captures(&line) {
self.switch_state(ProcessMapState::SectionLayout(SectionLayoutState {
current_section: captures["section"].to_string(),
@ -493,7 +493,7 @@ impl StateMachine {
fn section_layout_entry(
captures: Captures,
state: &mut SectionLayoutState,
result: &mut MapInfo,
result: &MapInfo,
) -> Result<()> {
if captures["rom_addr"].trim() == "UNUSED" {
return Ok(());