Exemplo n.º 1
0
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
	for native_dir in make_config.get_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_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():
    overall_result = 0

    # FIXME: декларации создаются после компиляции мода, следовательно не указываются в tsconfig.json у мода
    # clear_directory(make_config.get_path("toolchain/build/typescript-headers"))

    mod_structure.cleanup_build_target("script_source")
    mod_structure.cleanup_build_target("script_library")
    for item in make_config.get_value("sources", fallback=[]):
        _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_err(f"skipped invalid source with type {_type}")
            overall_result = 1
            continue

        for source_path in make_config.get_paths(_source):
            if not exists(source_path):
                print_err(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 += "{}"

            print_info(
                f"building {_language} {_type} from {_source} {'to ' + _target if _target is not None else '' }"
            )
            tsconfig_path = build_script(
                source_path,
                mod_structure.new_build_target(target_type,
                                               target_path,
                                               source_type=_type,
                                               declare=declare))
            mod_structure.update_build_config_list("compile")

    return overall_result
def build_all_scripts():
    overall_result = 0

    mod_structure.cleanup_build_target("script_source")
    mod_structure.cleanup_build_target("script_library")
    for source in make_config.get_value("sources", fallback=[]):
        if "source" not in source or "type" not in source:
            print("skipped invalid source json", source, file=sys.stderr)
            overall_result = 1
            continue

        for source_path in make_config.get_paths(source["source"]):
            if not os.path.exists(source_path):
                print("skipped non-existing source path",
                      source["source"],
                      file=sys.stderr)
                overall_result = 1
                continue
            source_type = source["type"]
            if source_type not in ("main", "launcher", "library", "preloader"):
                print("skipped invalid source with type",
                      source_type,
                      file=sys.stderr)
                overall_result = 1
                continue
            target_type = "script_library" if source_type == "library" else "script_source"
            source_name = source[
                "target"] if "target" in source else os.path.basename(
                    source_path)
            try:
                dot_index = source_name.rindex(".")
                source_name = source_name[:dot_index] + "{}" + source_name[
                    dot_index:]
            except ValueError:
                source_name += "{}"
            declare = {
                "sourceType": {
                    "main": "mod",
                    "launcher": "launcher",
                    "preloader": "preloader",
                    "library": "library"
                }[source_type]
            }
            if "api" in source:
                declare["api"] = source["api"]
            overall_result = build_script(
                source_path,
                mod_structure.new_build_target(target_type,
                                               source_name,
                                               source_type=source_type,
                                               declare=declare))

    mod_structure.update_build_config_list("compile")
    return overall_result
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_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_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={
                        "type": {
                            "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
Exemplo n.º 5
0
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_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"]
		_includes = item["includes"] if "includes" in item else ".includes"

		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_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, _includes)

	return overall_result