def task_build_package():
	import shutil
	config = get_make_config()
	output_dir = config.get_path(os.path.join("output/debug", config.get_mod_dir()))
	ensure_directory(config.get_path("output/release"))
	output_file = config.get_path("output/release/"+config.get_mod_dir() + ".icmod")
	output_file_tmp = config.get_path("toolchain/build/mod.zip")
	ensure_directory(output_dir)
	ensure_file_dir(output_file_tmp)
	if os.path.isfile(output_file):
		os.remove(output_file)
	if os.path.isfile(output_file_tmp):
		os.remove(output_file_tmp)
	shutil.make_archive(output_file_tmp[:-4], 'zip', output_dir)
	os.rename(output_file_tmp, output_file)
	return 0
def task_exclude_directories():
	config = get_make_config()
	for path in config.get_value("make.excludeFromRelease", []):
		for exclude in config.get_paths(os.path.join("output", config.get_mod_dir(), path)):
			if os.path.isdir(exclude):
				clear_directory(exclude)
			elif os.path.isfile(exclude):
				os.remove(exclude)
	return 0
def task_build_info():
	import json
	config = get_make_config()
	out_dir = os.path.join("output/debug", config.get_mod_dir())
	with open(config.get_path(os.path.join(out_dir, "mod.info")), "w") as info_file:
		info = dict(config.get_value("global.info", fallback={"name": "No was provided"}))
		if "icon" in info:
			del info["icon"]
		info_file.write(json.dumps(info, indent=" " * 4))
	icon_path = config.get_value("global.info.icon")
	if icon_path is not None:
		copy_file(config.get_path(icon_path, True), config.get_path(os.path.join(out_dir, "mod_icon.png")))
	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_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_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("make.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_path(os.path.join("output", "debug", make_config.get_mod_dir(), directory_name)))
	print(directories)
	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 task_build_additional():
	overall_result = 0
	config = get_make_config()
	for additional_dir in config.get_value("additional", fallback=[]):
		if "source" in additional_dir and "targetDir" in additional_dir:
			for additional_path in config.get_paths(additional_dir["source"]):
				if not os.path.exists(additional_path):
					print("non existing additional path: " + additional_path)
					overall_result = 1
					break
				target = config.get_path(os.path.join(
					"output",
					"debug",
					config.get_mod_dir(),
					additional_dir["targetDir"],
					os.path.basename(additional_path)
				))
				if os.path.isdir(additional_path):
					copy_directory(additional_path, target)
				else:
					ensure_file_dir(target)
					copy_file(additional_path, target)
	return overall_result
Example #6
0
        build_config_file = os.path.join(self.directory, "build.config")
        if os.path.isdir(build_config_file):
            clear_directory(build_config_file)
            os.remove(build_config_file)
        ensure_file_dir(build_config_file)
        with open(build_config_file, "w", encoding="utf-8") as build_config:
            build_config.write(json.dumps(self.build_config, indent=" " * 4))

    def setup_default_config(self):
        self.read_or_create_build_config()
        if "defaultConfig" not in self.build_config or not isinstance(
                self.build_config["defaultConfig"], dict):
            self.build_config["defaultConfig"] = {}
        default_config = self.build_config["defaultConfig"]
        default_config[
            "readme"] = "this build config is generated automatically by mod development toolchain"
        default_config["api"] = make_config.get_value("global.api",
                                                      fallback="CoreEngine")
        default_config["buildType"] = "develop"
        self.write_build_config()

    def update_build_config_list(self, list_name):
        self.setup_default_config()
        self.build_config[list_name] = self.create_build_config_list(
            list_name, default_overrides=self.build_config["defaultConfig"])
        self.write_build_config()


mod_structure = ModStructure(
    os.path.join("output/debug", make_config.get_mod_dir()))
def task_clear_output():
	config = get_make_config()
	clear_directory(config.get_path(os.path.join("output", "debug", config.get_mod_dir())))
	return 0
def task_push_everything():
	from push import push
	config = get_make_config()
	return push(config.get_path(os.path.join("output", "debug", config.get_mod_dir())))