1212
1313TARGET_PATH = setup .get_target_path ()
1414TARGET_ELF_PATH = setup .get_target_elf_path ()
15+ TARGET_UNCOMPRESSED_NSO_PATH = setup .config .get_versioned_data_path (setup .config .get_default_version ()) / 'main.uncompressed.nso'
1516
1617def prepare_executable (original_nso : Optional [Path ]):
1718 COMPRESSED_HASH = "63b7d29503400853c2cdb87a65d963cb9b5b934aea9d3d88b55764d33b13a722"
1819 UNCOMPRESSED_HASH = "f408dbfb901ab191fbcb7b5994580ed91812bafa90ae164796ae8a254e4dcef8"
1920
20- TARGET_HASH = UNCOMPRESSED_HASH
21+ target_hash = hashlib . sha256 ( TARGET_PATH . read_bytes ()). hexdigest ()
2122
22- if TARGET_PATH .is_file () and hashlib . sha256 ( TARGET_PATH . read_bytes ()). hexdigest () == TARGET_HASH and TARGET_ELF_PATH .is_file ():
23+ if TARGET_PATH .is_file () and target_hash == COMPRESSED_HASH or target_hash == UNCOMPRESSED_HASH and TARGET_ELF_PATH .is_file ():
2324 print (">>> NSO is already set up" )
2425 return
2526
@@ -29,30 +30,31 @@ def prepare_executable(original_nso: Optional[Path]):
2930 if not original_nso .is_file ():
3031 setup .fail (f"{ original_nso } is not a file" )
3132
32- nso_data = original_nso .read_bytes ()
33- nso_hash = hashlib .sha256 (nso_data ).hexdigest ()
33+ nso_hash = hashlib .sha256 (original_nso .read_bytes ()).hexdigest ()
3434
3535 if nso_hash == UNCOMPRESSED_HASH :
3636 print (">>> found uncompressed NSO" )
37- TARGET_PATH .write_bytes (nso_data )
3837
3938 elif nso_hash == COMPRESSED_HASH :
4039 print (">>> found compressed NSO" )
41- setup ._decompress_nso (original_nso , TARGET_PATH )
4240
4341 else :
4442 setup .fail (f"unknown executable: { nso_hash } " )
4543
46- if not TARGET_PATH .is_file ():
47- setup .fail ("internal error while preparing executable (missing NSO); please report" )
48- if hashlib .sha256 (TARGET_PATH .read_bytes ()).hexdigest () != TARGET_HASH :
49- setup .fail ("internal error while preparing executable (wrong NSO hash); please report" )
44+ setup ._convert_nso_to_elf (original_nso )
5045
51- setup . _convert_nso_to_elf ( TARGET_PATH )
46+ converted_elf_path = original_nso . with_suffix ( ".elf" )
5247
53- if not TARGET_ELF_PATH .is_file ():
48+ if not converted_elf_path .is_file ():
5449 setup .fail ("internal error while preparing executable (missing ELF); please report" )
5550
51+ shutil .move (converted_elf_path , TARGET_ELF_PATH )
52+
53+ uncompressed_nso_path = original_nso .with_suffix (".uncompressed.nso" )
54+ shutil .move (uncompressed_nso_path , TARGET_UNCOMPRESSED_NSO_PATH )
55+
56+ if not TARGET_UNCOMPRESSED_NSO_PATH .is_file () or hashlib .sha256 (TARGET_UNCOMPRESSED_NSO_PATH .read_bytes ()).hexdigest () != UNCOMPRESSED_HASH :
57+ setup .fail ("Internal error while exporting uncompressed NSO (uncompressed NSO either doesn't exist or has an incorrect hash); please report" )
5658
5759def get_build_dir ():
5860 return setup .ROOT / "build"
0 commit comments