diff --git a/decomp_settings.pyi b/decomp_settings.pyi index e2875f1..a085b3b 100644 --- a/decomp_settings.pyi +++ b/decomp_settings.pyi @@ -73,11 +73,135 @@ class Version: """ The sha1 hash of the target executable. This can be used by tools to ensure the correct executable is being worked with. """ - paths: dict[str, str] + paths: VersionPaths """ - A map of path names to paths that tools may care about. Common paths would be baserom, asm, build, map, expected, etc. + A list of paths that tools may care about. """ +class VersionPaths: + """ + Represents the set of important file and directory paths associated with a project version. + + Each field corresponds to a specific artifact or directory relevant to decomp tools. + """ + + target: str + """ + Path to the original target binary (e.g., the ROM or executable to decompile). Usually called "baserom" by many projects. + + ## Examples + + ``` + target: "config/us/baserom_decompressed.us.z64" + ``` + """ + + build_dir: str + """ + Directory where build artifacts are generated. + + ## Examples + + ``` + build_dir: "build/ntsc-u/" + ``` + """ + + map: str + """ + Path to the map file generated during the build. + + ## Examples + + ``` + map: "build/us/drmario64.us.map" + ``` + """ + + compiled_target: str + """ + Path to the binary produced by the project's build system. + + ## Examples + + ``` + compiled_target: "build/us/drmario64_uncompressed.us.z64" + ``` + """ + + elf: str | None + """ + Path to the intermediary ELF file generated during the build, if any. + + ## Examples + + ``` + elf: "build/pokemonsnap.elf" + ``` + """ + + expected_dir: str | None + """ + Directory containing the expected files used for comparison. + + Many projects simply put a copy of their `build` directory inside this expected directory. + + ## Examples + + ``` + expected_dir: "expected/" + ``` + """ + + asm: str | None + """ + Directory containing disassembled assembly files. + + ## Examples + + ``` + asm: "asm/" + ``` + + ``` + asm: "asm/rev0/" + ``` + """ + + nonmatchings: str | None + """ + Directory containing functions or files that have not yet been matched to the original binary. + + ## Examples + + ``` + nonmatchings: "asm/rev0/nonmatchings" + ``` + """ + + compressed_target: str | None + """ + Path to the original target binary before decompression, if any. + + ## Examples + + ``` + compressed_target: "config/usa/rom_original.z64" + ``` + """ + + compressed_compiled_target: str | None + """ + Path to the compressed binary produced by the build system, if any. + + ## Examples + + ``` + compressed_compiled_target: "build/usa/compressed_rom.z64" + ``` + """ + + class ToolOpts: """ Represents a tool and its settings diff --git a/src/config.rs b/src/config.rs index f773276..9d1cb57 100644 --- a/src/config.rs +++ b/src/config.rs @@ -84,7 +84,7 @@ impl ToolOpts { } #[cfg(feature = "python_bindings")] -impl<'a, 'py> IntoPyObject<'py> for &'a AnyOpts { +impl<'py> IntoPyObject<'py> for &AnyOpts { type Target = PyAny; type Output = Bound<'py, PyAny>; type Error = PyErr; @@ -168,8 +168,8 @@ pub struct Version { pub fullname: String, /// The sha1 hash of the target executable. This can be used by tools to ensure the correct executable is being worked with. pub sha1: Option, - /// A map of path names to paths that tools may care about. Common paths would be baserom, asm, build, map, expected, etc. - pub paths: HashMap, + /// A list of paths that tools may care about. + pub paths: VersionPaths, } impl Display for Version { @@ -178,6 +178,108 @@ impl Display for Version { } } +#[derive(Clone, Debug, Deserialize)] +#[serde(deny_unknown_fields)] +#[cfg_attr( + feature = "python_bindings", + pyclass(frozen, get_all, module = "decomp_settings") +)] +/// Represents the set of important file and directory paths associated with a project version. +/// +/// Each field corresponds to a specific artifact or directory relevant to decomp tools. +pub struct VersionPaths { + /// Path to the original target binary (e.g., the ROM or executable to decompile). Usually called "baserom" by many projects. + /// + /// ## Examples + /// + /// ```yaml + /// target: "config/us/baserom_decompressed.us.z64" + /// ``` + pub target: PathBuf, + + /// Directory where build artifacts are generated. + /// + /// ## Examples + /// + /// ```yaml + /// build_dir: "build/ntsc-u/" + /// ``` + pub build_dir: PathBuf, + /// Path to the map file generated during the build. + /// + /// ## Examples + /// + /// ```yaml + /// map: "build/us/drmario64.us.map" + /// ``` + pub map: PathBuf, + /// Path to the binary produced by the project's build system. + /// + /// ## Examples + /// + /// ```yaml + /// compiled_target: "build/us/drmario64_uncompressed.us.z64" + /// ``` + pub compiled_target: PathBuf, + /// Path to the intermediary ELF file generated during the build, if any. + /// + /// ## Examples + /// + /// ```yaml + /// elf: "build/pokemonsnap.elf" + /// ``` + pub elf: Option, + + /// Directory containing the expected files used for comparison. + /// + /// Many projects simply put a copy of their `build` directory inside this expected directory. + /// + /// ## Examples + /// + /// ```yaml + /// expected_dir: "expected/" + /// ``` + pub expected_dir: Option, + + /// Directory containing disassembled assembly files. + /// + /// ## Examples + /// + /// ```yaml + /// asm: "asm/" + /// ``` + /// + /// ```yaml + /// asm: "asm/rev0/" + /// ``` + pub asm: Option, + /// Directory containing functions or files that have not yet been matched to the original binary. + /// + /// ## Examples + /// + /// ```yaml + /// nonmatchings: "asm/rev0/nonmatchings" + /// ``` + pub nonmatchings: Option, + + /// Path to the original target binary before decompression, if any. + /// + /// ## Examples + /// + /// ```yaml + /// compressed_target: "config/usa/rom_original.z64" + /// ``` + pub compressed_target: Option, + /// Path to the compressed binary produced by the build system, if any. + /// + /// ## Examples + /// + /// ```yaml + /// compressed_compiled_target: "build/usa/compressed_rom.z64" + /// ``` + pub compressed_compiled_target: Option, +} + #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] #[cfg_attr( diff --git a/src/lib.rs b/src/lib.rs index 226806e..ee0043a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,14 +80,18 @@ pub fn read_config(path: PathBuf) -> Result { #[cfg(feature = "python_bindings")] #[pymodule] fn decomp_settings(m: &Bound<'_, PyModule>) -> PyResult<()> { - use config::{AnyOpts, ToolOpts}; + use config::{AnyOpts, ToolOpts, Version, VersionPaths}; m.add_function(wrap_pyfunction!(scan_for_config, m)?)?; m.add_function(wrap_pyfunction!(scan_for_config_from, m)?)?; m.add_function(wrap_pyfunction!(read_config, m)?)?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; m.add_class::()?; m.add_class::()?; + Ok(()) } diff --git a/test/arbitrary_tool.yaml b/test/arbitrary_tool.yaml index adfb00e..ca2c78e 100644 --- a/test/arbitrary_tool.yaml +++ b/test/arbitrary_tool.yaml @@ -5,9 +5,21 @@ versions: - name: us fullname: US paths: + target: "pokemonsnap.z64" + + build_dir: "build" + map: "build/pokemonsnap.map" + compiled_target: "build/pokemonsnap.z64" + elf: "build/pokemonsnap.elf" + + expected_dir: "expected/" + + asm: "asm" + nonmatchings: "asm/nonmatchings" + tools: arbitrary_tool: meowp: 125 others: - thing: {stuff: 1} - - thing2: {stuff: 2} \ No newline at end of file + - thing2: {stuff: 2} diff --git a/test/decomp.yaml b/test/decomp.yaml index 4cfa956..6e29511 100644 --- a/test/decomp.yaml +++ b/test/decomp.yaml @@ -6,12 +6,18 @@ versions: fullname: US sha1: edc7c49cc568c045fe48be0d18011c30f393cbaf paths: - baserom: "pokemonsnap.z64" - build: "build/pokemonsnap.z64" - asm: "asm" - nonmatchings: "asm/nonmatchings" + target: "pokemonsnap.z64" + + build_dir: "build" map: "build/pokemonsnap.map" + compiled_target: "build/pokemonsnap.z64" elf: "build/pokemonsnap.elf" + + expected_dir: "expected/" + + asm: "asm" + nonmatchings: "asm/nonmatchings" + tools: decompme: preset: 125 @@ -23,4 +29,4 @@ tools: project: pokemonsnap versions: us: # corresponds with top-level version snames - version: us \ No newline at end of file + version: us