示例#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_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
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
示例#4
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", path)):
            if os.path.isdir(exclude):
                clear_directory(exclude)
            elif os.path.isfile(exclude):
                os.remove(exclude)
    return 0
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 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("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
示例#7
0
def get_path_set(paths, error_sensitive=False):
    directories = []
    for path in paths:
        for directory in make_config.get_paths(path):
            if os.path.isdir(directory):
                directories.append(directory)
            else:
                if error_sensitive:
                    print(
                        f"declared invalid directory {path}, task will be terminated"
                    )
                    return None
                else:
                    print(
                        f"declared invalid directory {path}, it will be skipped"
                    )
    return directories
示例#8
0
def push_set_of_paths(path_set,
                      relative_directory,
                      src_relative=False,
                      cleanup=False):
    push_result = 0
    for path in path_set:
        for directory in make_config.get_paths(path):
            if os.path.isdir(directory):
                push_result = push(directory,
                                   relative_directory,
                                   src_relative=src_relative,
                                   cleanup=cleanup)
                cleanup = False
                if push_result != 0:
                    print("failed to push directory", directory)
                    break
            else:
                print("failed to locate directory", path)
                push_result = -1
                break
    return push_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
示例#10
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