def compile_project(project_path, base_rom_filename, output_rom_filename, ccscript_offset=None, progress_bar=None): modules = load_modules() project_filename = os.path.join(project_path, PROJECT_FILENAME) project = Project() project.load(project_filename) check_if_project_too_old(project) check_if_project_too_new(project) if base_rom_filename != output_rom_filename: copyfile(base_rom_filename, output_rom_filename) # Compile scripts using CCScript script_filenames = [os.path.join(project_path, "ccscript", x) for x in os.listdir(os.path.join(project_path, "ccscript")) if x.lower().endswith('.ccs')] if script_filenames: log.info("Compiling CCScript") if not ccscript_offset: ccscript_offset = "F10000" elif type(ccscript_offset) == int: ccscript_offset = "{:x}".format(ccscript_offset) ccc_args = ["-n", "--libs", ccscript_library_path(), "--summary", os.path.join(project_path, "ccscript", "summary.txt"), "-s", ccscript_offset, "-o", output_rom_filename] + script_filenames ccc_returncode, ccc_log = ccc(ccc_args) if ccc_returncode == 0: log.info("Finished compiling CCScript") else: raise CCScriptCompilationError("CCScript compilation failed with output:\n" + ccc_log) rom = Rom() rom.from_file(output_rom_filename) check_if_types_match(project=project, rom=rom) compatible_modules = [(name, clazz) for name, clazz in modules if clazz.is_compatible_with_romtype(rom.type)] tick_amount = 1.0/(2*len(compatible_modules)) log.info("Compiling Project {}".format(project_path)) compile_start_time = time.time() for module_name, module_class in modules: if module_class.is_compatible_with_romtype(rom.type): for free_range in module_class.FREE_RANGES: rom.deallocate(free_range) for module_name, module_class in modules: if not module_class.is_compatible_with_romtype(rom.type): continue log.info("Compiling {}...".format(module_class.NAME)) start_time = time.time() with module_class() as module: module.read_from_project(lambda x, y: project.get_resource(module_name, x, y, 'rb')) if progress_bar: progress_bar.tick(tick_amount) module.write_to_rom(rom) if progress_bar: progress_bar.tick(tick_amount) log.info("Finished compiling {} in {:.2f}s".format(module_class.NAME, time.time() - start_time)) log.debug("Saving ROM") rom.to_file(output_rom_filename) log.info("Compiled to {} in {:.2f}s, finished at {}".format( output_rom_filename, time.time() - compile_start_time, datetime.now().strftime('%I:%M:%S %p')))
def compile_project(project_path, base_rom_filename, output_rom_filename, ccscript_offset=None, progress_bar=None): if not os.path.isdir(project_path): raise RuntimeError("Project directory \"" + project_path + "\" is not a directory.") if not os.path.isfile(base_rom_filename): raise RuntimeError("Base Rom \"" + base_rom_filename + "\" is not a file.") modules = load_modules() project_filename = os.path.join(project_path, PROJECT_FILENAME) project = Project() project.load(project_filename) check_if_project_too_old(project) check_if_project_too_new(project) if base_rom_filename != output_rom_filename: copyfile(base_rom_filename, output_rom_filename) # Compile scripts using CCScript script_filenames = [ os.path.join(project_path, "ccscript", x) for x in os.listdir(os.path.join(project_path, "ccscript")) if x.lower().endswith('.ccs') ] if script_filenames: log.info("Compiling CCScript") if not ccscript_offset: ccscript_offset = "F10000" elif type(ccscript_offset) == int: ccscript_offset = "{:x}".format(ccscript_offset) ccc_args = [ "-n", "--libs", ccscript_library_path(), "--summary", os.path.join(project_path, "ccscript", "summary.txt"), "-s", ccscript_offset, "-o", output_rom_filename ] + script_filenames ccc_returncode, ccc_log = ccc(ccc_args) if ccc_returncode == 0: log.info("Finished compiling CCScript") else: raise CCScriptCompilationError( "CCScript compilation failed with output:\n" + ccc_log) rom = Rom() rom.from_file(output_rom_filename) check_if_types_match(project=project, rom=rom) compatible_modules = [(name, clazz) for name, clazz in modules if clazz.is_compatible_with_romtype(rom.type)] tick_amount = 1.0 / (2 * len(compatible_modules)) log.info("Compiling Project {}".format(project_path)) compile_start_time = time.time() for module_name, module_class in modules: if module_class.is_compatible_with_romtype(rom.type): for free_range in module_class.FREE_RANGES: rom.deallocate(free_range) for module_name, module_class in modules: if not module_class.is_compatible_with_romtype(rom.type): continue log.info("Compiling {}...".format(module_class.NAME)) start_time = time.time() with module_class() as module: module.read_from_project( lambda x, y, astext=False: project.get_resource( module_name, x, y, 'rt' if astext else 'rb', 'utf-8' if astext else None)) if progress_bar: progress_bar.tick(tick_amount) module.write_to_rom(rom) if progress_bar: progress_bar.tick(tick_amount) log.info("Finished compiling {} in {:.2f}s".format( module_class.NAME, time.time() - start_time)) log.debug("Saving ROM") rom.to_file(output_rom_filename) log.info("Compiled to {} in {:.2f}s, finished at {}".format( output_rom_filename, time.time() - compile_start_time, datetime.now().strftime('%I:%M:%S %p')))