def build_all_resources(): mod_structure.cleanup_build_target("resource_directory") mod_structure.cleanup_build_target("gui") mod_structure.cleanup_build_target("minecraft_resource_pack") mod_structure.cleanup_build_target("minecraft_behavior_pack") overall_result = 0 for resource in make_config.get_project_value("resources", fallback=[]): if "path" not in resource or "type" not in resource: print("skipped invalid source json", resource, file=sys.stderr) overall_result = 1 continue for source_path in make_config.get_project_paths(resource["path"]): if not exists(source_path): print("skipped non-existing resource path", resource["path"], file=sys.stderr) overall_result = 1 continue resource_type = resource["type"] if resource_type not in ("resource_directory", "gui", "minecraft_resource_pack", "minecraft_behavior_pack"): print("skipped invalid resource with type", resource_type, file=sys.stderr) overall_result = 1 continue resource_name = resource[ "target"] if "target" in resource else basename(source_path) resource_name += "{}" if resource_type in ("resource_directory", "gui"): target = mod_structure.new_build_target( resource_type, resource_name, declare={ "resourceType": { "resource_directory": "resource", "gui": "gui" }[resource_type] }) else: target = mod_structure.new_build_target( resource_type, resource_name, exclude=True, declare_default={ "resourcePacksDir": mod_structure.get_target_directories( "minecraft_resource_pack")[0], "behaviorPacksDir": mod_structure.get_target_directories( "minecraft_behavior_pack")[0] }) clear_directory(target) copy_directory(source_path, target) mod_structure.update_build_config_list("resources") return overall_result
def task_exclude_directories(): config = get_make_config() for path in config.get_project_value("excludeFromRelease", []): for exclude in config.get_project_paths(os.path.join("output", path)): if os.path.isdir(exclude): clear_directory(exclude) elif os.path.isfile(exclude): os.remove(exclude) return 0
def compile_all_using_make_config(): import time start_time = time.time() overall_result = 0 cache_dir = make_config.get_path("toolchain/build/gradle") ensure_directory(cache_dir) directories = [] directory_names = [] for directory in make_config.get_project_filtered_list("compile", prop="type", values=("java", )): if "source" not in directory: print("skipped invalid java directory json", directory, file=sys.stderr) overall_result = -1 continue for path in make_config.get_project_paths(directory["source"]): if not os.path.isdir(path): print("skipped non-existing java directory path", directory["source"], file=sys.stderr) overall_result = -1 continue directories.append(path) if overall_result != 0: print("failed to get java directories", file=sys.stderr) return overall_result if len(directories) > 0: classpath_directories = [make_config.get_path("toolchain/classpath") ] + make_config.get_value( "gradle.classpath", []) overall_result = build_java_directories( directories, cache_dir, get_classpath_from_directories(classpath_directories)) if overall_result != 0: print(f"failed, clearing compiled directories {directories} ...") for directory_name in directory_names: clear_directory( make_config.get_project_path("output/" + directory_name)) cleanup_gradle_scripts(directories) mod_structure.update_build_config_list("javaDirs") print( f"completed java build in {int((time.time() - start_time) * 100) / 100}s with result {overall_result} - {'OK' if overall_result == 0 else 'ERROR'}" ) return overall_result
def compile_all_using_make_config(abis): import time start_time = time.time() std_includes = make_config.get_path("toolchain/stdincludes") cache_dir = make_config.get_path("toolchain/build/gcc") ensure_directory(cache_dir) mod_structure.cleanup_build_target("native") overall_result = CODE_OK #print(make_config.get_project_filtered_list("compile", prop="type", values=("native",))) for native_dir in make_config.get_project_filtered_list("compile", prop="type", values=("native",)): if "source" not in native_dir: print("skipped invalid native directory json", native_dir, file=sys.stderr) overall_result = CODE_INVALID_JSON continue for native_dir_path in make_config.get_project_paths(native_dir["source"]): if os.path.isdir(native_dir_path): directory_name = os.path.basename(native_dir_path) result = build_native_dir( native_dir_path, mod_structure.new_build_target("native", directory_name + "{}"), os.path.join(cache_dir, directory_name), abis, std_includes, BaseConfig(native_dir["rules"] if "rules" in native_dir else {}) ) if result != CODE_OK: overall_result = result else: print("skipped non-existing native directory path", native_dir["source"], file=sys.stderr) overall_result = CODE_INVALID_PATH mod_structure.update_build_config_list("nativeDirs") print(f"completed native build in {int((time.time() - start_time) * 100) / 100}s with result {overall_result} - {'OK' if overall_result == CODE_OK else 'ERROR'}") return overall_result
def build_all_scripts(): mod_structure.cleanup_build_target("script_source") mod_structure.cleanup_build_target("script_library") overall_result = 0 from functools import cmp_to_key def libraries_first(a, b): la = a["type"] == "library" lb = b["type"] == "library" if la == lb: return 0 elif la: return -1 else: return 1 sources = make_config.get_project_value("sources", fallback=[]) sources = sorted(sources, key=cmp_to_key(libraries_first)) for item in sources: _source = item["source"] _target = item["target"] if "target" in item else None _type = item["type"] _language = item["language"] if _type not in ("main", "launcher", "library", "preloader"): print(f"skipped invalid source with type {_type}") overall_result = 1 continue for source_path in make_config.get_project_paths(_source): if not exists(source_path): print(f"skipped non-existing source path {_source}") overall_result = 1 continue target_type = "script_library" if _type == "library" else "script_source" target_path = _target if _target is not None else f"{splitext(basename(source_path))[0]}.js" # translate make.json source type to build.config source type declare = { "sourceType": { "main": "mod", "launcher": "launcher", "preloader": "preloader", "library": "library" }[_type] } if "api" in item: declare["api"] = item["api"] try: dot_index = target_path.rindex(".") target_path = target_path[:dot_index] + "{}" + target_path[ dot_index:] except ValueError: target_path += "{}" destination_path = mod_structure.new_build_target( target_type, target_path, source_type=_type, declare=declare) mod_structure.update_build_config_list("compile") if (isfile(source_path)): copy_file(source_path, destination_path) else: overall_result += build_source(source_path, destination_path) return overall_result