Skip to content

Commit 4b6e317

Browse files
committed
Adjustments for use with ninja build
1 parent 771c380 commit 4b6e317

File tree

6 files changed

+39
-33
lines changed

6 files changed

+39
-33
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "decomp-toolkit"
33
description = "Yet another GameCube/Wii decompilation toolkit."
44
authors = ["Luke Street <[email protected]>"]
55
license = "MIT OR Apache-2.0"
6-
version = "0.3.0"
6+
version = "0.3.1"
77
edition = "2021"
88
publish = false
99
build = "build.rs"

src/cmd/dol.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::{
2626
config::{apply_splits, parse_symbol_line, write_splits, write_symbols},
2727
dol::process_dol,
2828
elf::{process_elf, write_elf},
29-
file::{map_file, map_reader},
29+
file::{map_file, map_reader, touch},
3030
lcf::{asm_path_for_unit, generate_ldscript, obj_path_for_unit},
3131
},
3232
};
@@ -74,6 +74,9 @@ pub struct SplitArgs {
7474
#[argp(option, short = 'e')]
7575
/// ELF file to validate against (debugging only)
7676
elf_file: Option<PathBuf>,
77+
#[argp(switch)]
78+
/// skip updating splits & symbol files (for build systems)
79+
no_update: bool,
7780
}
7881

7982
pub fn run(args: Args) -> Result<()> {
@@ -179,20 +182,22 @@ fn split(args: SplitArgs) -> Result<()> {
179182
log::info!("Detecting strings");
180183
detect_strings(&mut obj)?;
181184

182-
if let Some(symbols_path) = &args.symbols_file {
183-
let mut symbols_writer = BufWriter::new(
184-
File::create(symbols_path)
185-
.with_context(|| format!("Failed to create '{}'", symbols_path.display()))?,
186-
);
187-
write_symbols(&mut symbols_writer, &obj)?;
188-
}
185+
if !args.no_update {
186+
if let Some(symbols_path) = &args.symbols_file {
187+
let mut symbols_writer = BufWriter::new(
188+
File::create(symbols_path)
189+
.with_context(|| format!("Failed to create '{}'", symbols_path.display()))?,
190+
);
191+
write_symbols(&mut symbols_writer, &obj)?;
192+
}
189193

190-
if let Some(splits_path) = &args.splits_file {
191-
let mut splits_writer = BufWriter::new(
192-
File::create(splits_path)
193-
.with_context(|| format!("Failed to create '{}'", splits_path.display()))?,
194-
);
195-
write_splits(&mut splits_writer, &obj)?;
194+
if let Some(splits_path) = &args.splits_file {
195+
let mut splits_writer = BufWriter::new(
196+
File::create(splits_path)
197+
.with_context(|| format!("Failed to create '{}'", splits_path.display()))?,
198+
);
199+
write_splits(&mut splits_writer, &obj)?;
200+
}
196201
}
197202

198203
log::info!("Adjusting splits");
@@ -202,6 +207,7 @@ fn split(args: SplitArgs) -> Result<()> {
202207
let split_objs = split_obj(&obj)?;
203208

204209
// Create out dirs
210+
touch(&args.out_dir)?;
205211
let asm_dir = args.out_dir.join("asm");
206212
let include_dir = args.out_dir.join("include");
207213
let obj_dir = args.out_dir.join("obj");

src/cmd/shasum.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
use std::{
2-
fs::{File, OpenOptions},
2+
fs::File,
33
io::{BufRead, BufReader, Read},
44
path::{Path, PathBuf},
55
};
66

77
use anyhow::{anyhow, bail, Context, Result};
88
use argp::FromArgs;
9-
use filetime::{set_file_mtime, FileTime};
109
use sha1::{Digest, Sha1};
1110

12-
use crate::util::file::process_rsp;
11+
use crate::util::file::{process_rsp, touch};
1312

1413
#[derive(FromArgs, PartialEq, Eq, Debug)]
1514
/// Print or check SHA1 (160-bit) checksums.
@@ -100,14 +99,3 @@ fn file_sha1(mut file: File) -> Result<sha1::digest::Output<Sha1>> {
10099
hasher.update(&buf[0..read]);
101100
})
102101
}
103-
104-
fn touch<P: AsRef<Path>>(path: P) -> std::io::Result<()> {
105-
if path.as_ref().exists() {
106-
set_file_mtime(path, FileTime::now())
107-
} else {
108-
match OpenOptions::new().create(true).write(true).open(path) {
109-
Ok(_) => Ok(()),
110-
Err(e) => Err(e),
111-
}
112-
}
113-
}

src/util/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn parse_symbol_line(line: &str, obj: &mut ObjInfo) -> Result<Option<ObjSymb
8888
}
8989
}
9090
Ok(Some(symbol))
91-
} else if COMMENT_LINE.is_match(line) {
91+
} else if line.is_empty() || COMMENT_LINE.is_match(line) {
9292
Ok(None)
9393
} else {
9494
Err(anyhow!("Failed to parse symbol line '{line}'"))

src/util/file.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::{
2-
fs::File,
2+
fs::{File, OpenOptions},
33
io::{BufRead, BufReader, Cursor, Read},
44
path::{Path, PathBuf},
55
};
66

77
use anyhow::{anyhow, Context, Result};
88
use byteorder::ReadBytesExt;
9+
use filetime::{set_file_mtime, FileTime};
910
use memmap2::{Mmap, MmapOptions};
1011

1112
use crate::util::{rarc, rarc::Node, yaz0};
@@ -234,3 +235,14 @@ impl Iterator for FileIterator {
234235

235236
fn next(&mut self) -> Option<Self::Item> { self.next_rarc().or_else(|| self.next_path()) }
236237
}
238+
239+
pub fn touch<P: AsRef<Path>>(path: P) -> std::io::Result<()> {
240+
if path.as_ref().exists() {
241+
set_file_mtime(path, FileTime::now())
242+
} else {
243+
match OpenOptions::new().create(true).write(true).open(path) {
244+
Ok(_) => Ok(()),
245+
Err(e) => Err(e),
246+
}
247+
}
248+
}

src/util/map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl StateMachine {
286286
}
287287
ProcessMapState::SectionLayout(ref mut state) => {
288288
if let Some(captures) = SECTION_LAYOUT_SYMBOL.captures(&line) {
289-
StateMachine::section_layout_entry(captures, state, &mut self.result)?;
289+
StateMachine::section_layout_entry(captures, state, &self.result)?;
290290
} else if let Some(captures) = SECTION_LAYOUT_START.captures(&line) {
291291
self.switch_state(ProcessMapState::SectionLayout(SectionLayoutState {
292292
current_section: captures["section"].to_string(),
@@ -493,7 +493,7 @@ impl StateMachine {
493493
fn section_layout_entry(
494494
captures: Captures,
495495
state: &mut SectionLayoutState,
496-
result: &mut MapInfo,
496+
result: &MapInfo,
497497
) -> Result<()> {
498498
if captures["rom_addr"].trim() == "UNUSED" {
499499
return Ok(());

0 commit comments

Comments
 (0)