def main(): args = parse_args() framework_info = load_framework_info(args.framework_info_file.resolve()) staging_dir = args.staging_dir.resolve() print(f"Assembling files in staging directory: {staging_dir}") if staging_dir.exists(): print("Warning: staging directory already exists", file=sys.stderr) # copy the necessary files to the staging directory framework_dir = args.framework_dir.resolve() shutil.copytree(framework_dir, staging_dir / framework_dir.name, dirs_exist_ok=True) public_headers_dir = args.public_headers_dir.resolve() shutil.copytree(public_headers_dir, staging_dir / public_headers_dir.name, dirs_exist_ok=True) copy_repo_relative_to_dir(["LICENSE"], staging_dir) # generate the podspec file from the template variable_substitutions = { "VERSION": args.pod_version, "IOS_DEPLOYMENT_TARGET": framework_info["IOS_DEPLOYMENT_TARGET"], "WEAK_FRAMEWORK": framework_info["WEAK_FRAMEWORK"], "LICENSE_FILE": '"LICENSE"', } podspec_template = _script_dir / "onnxruntime-mobile-c.podspec.template" podspec = staging_dir / "onnxruntime-mobile-c.podspec" gen_file_from_template(podspec_template, podspec, variable_substitutions) return 0
def assemble_c_pod_package(staging_dir: pathlib.Path, pod_version: str, framework_info_file: pathlib.Path, public_headers_dir: pathlib.Path, framework_dir: pathlib.Path, package_variant: PackageVariant): ''' Assembles the files for the C/C++ pod package in a staging directory. :param staging_dir Path to the staging directory for the C/C++ pod files. :param pod_version C/C++ pod version. :param framework_info_file Path to the framework_info.json file containing additional values for the podspec. :param public_headers_dir Path to the public headers directory to include in the pod. :param framework_dir Path to the onnxruntime framework directory to include in the pod. :param package_variant The pod package variant. :return Tuple of (package name, path to the podspec file). ''' staging_dir = staging_dir.resolve() framework_info_file = framework_info_file.resolve(strict=True) public_headers_dir = public_headers_dir.resolve(strict=True) framework_dir = framework_dir.resolve(strict=True) framework_info = load_json_config(framework_info_file) pod_config = load_json_config(get_pod_config_file(package_variant)) pod_name = pod_config["name"] print(f"Assembling files in staging directory: {staging_dir}") if staging_dir.exists(): print("Warning: staging directory already exists", file=sys.stderr) # copy the necessary files to the staging directory shutil.copytree(framework_dir, staging_dir / framework_dir.name, dirs_exist_ok=True) shutil.copytree(public_headers_dir, staging_dir / public_headers_dir.name, dirs_exist_ok=True) copy_repo_relative_to_dir(["LICENSE"], staging_dir) # generate the podspec file from the template variable_substitutions = { "DESCRIPTION": pod_config["description"], "IOS_DEPLOYMENT_TARGET": framework_info["IOS_DEPLOYMENT_TARGET"], "LICENSE_FILE": "LICENSE", "NAME": pod_name, "ORT_C_FRAMEWORK": framework_dir.name, "ORT_C_HEADERS_DIR": public_headers_dir.name, "SUMMARY": pod_config["summary"], "VERSION": pod_version, "WEAK_FRAMEWORK": framework_info["WEAK_FRAMEWORK"], } podspec_template = _script_dir / "c.podspec.template" podspec = staging_dir / f"{pod_name}.podspec" gen_file_from_template(podspec_template, podspec, variable_substitutions) return pod_name, podspec
def assemble_objc_pod_package(staging_dir: pathlib.Path, pod_version: str, framework_info_file: pathlib.Path, package_variant: PackageVariant): ''' Assembles the files for the Objective-C pod package in a staging directory. :param staging_dir Path to the staging directory for the Objective-C pod files. :param pod_version Objective-C pod version. :param framework_info_file Path to the framework_info.json file containing additional values for the podspec. :param package_variant The pod package variant. :return Tuple of (package name, path to the podspec file). ''' staging_dir = staging_dir.resolve() framework_info_file = framework_info_file.resolve(strict=True) framework_info = load_json_config(framework_info_file) pod_config = load_json_config(get_pod_config_file(package_variant)) c_pod_config = load_json_config(get_c_pod_config_file(package_variant)) pod_name = pod_config["name"] print(f"Assembling files in staging directory: {staging_dir}") if staging_dir.exists(): print("Warning: staging directory already exists", file=sys.stderr) # copy the necessary files to the staging directory copy_repo_relative_to_dir( [license_file] + source_files + test_source_files + test_resource_files, staging_dir) # generate the podspec file from the template def path_patterns_as_variable_value(patterns: list[str]): return ", ".join([f'"{pattern}"' for pattern in patterns]) variable_substitutions = { "C_POD_NAME": c_pod_config["name"], "DESCRIPTION": pod_config["description"], "INCLUDE_DIR_LIST": path_patterns_as_variable_value(include_dirs), "IOS_DEPLOYMENT_TARGET": framework_info["IOS_DEPLOYMENT_TARGET"], "LICENSE_FILE": license_file, "NAME": pod_name, "PUBLIC_HEADER_FILE_LIST": path_patterns_as_variable_value(public_header_files), "SOURCE_FILE_LIST": path_patterns_as_variable_value(source_files), "SUMMARY": pod_config["summary"], "TEST_RESOURCE_FILE_LIST": path_patterns_as_variable_value(test_resource_files), "TEST_SOURCE_FILE_LIST": path_patterns_as_variable_value(test_source_files), "VERSION": pod_version, } podspec_template = _script_dir / "objc.podspec.template" podspec = staging_dir / f"{pod_name}.podspec" gen_file_from_template(podspec_template, podspec, variable_substitutions) return pod_name, podspec
def main(): args = parse_args() framework_info = load_framework_info(args.framework_info_file.resolve()) staging_dir = args.staging_dir.resolve() print(f"Assembling files in staging directory: {staging_dir}") if staging_dir.exists(): print("Warning: staging directory already exists", file=sys.stderr) # copy the necessary files to the staging directory copy_repo_relative_to_dir([license_file] + source_files + test_source_files + test_resource_files, staging_dir) # generate the podspec file from the template def path_patterns_as_variable_value(patterns: list[str]): return ", ".join([f'"{pattern}"' for pattern in patterns]) variable_substitutions = { "VERSION": args.pod_version, "IOS_DEPLOYMENT_TARGET": framework_info["IOS_DEPLOYMENT_TARGET"], "LICENSE_FILE": path_patterns_as_variable_value([license_file]), "INCLUDE_DIR_LIST": path_patterns_as_variable_value(include_dirs), "PUBLIC_HEADER_FILE_LIST": path_patterns_as_variable_value(public_header_files), "SOURCE_FILE_LIST": path_patterns_as_variable_value(source_files), "TEST_SOURCE_FILE_LIST": path_patterns_as_variable_value(test_source_files), "TEST_RESOURCE_FILE_LIST": path_patterns_as_variable_value(test_resource_files), } podspec_template = _script_dir / "onnxruntime-mobile-objc.podspec.template" podspec = staging_dir / "onnxruntime-mobile-objc.podspec" gen_file_from_template(podspec_template, podspec, variable_substitutions) return 0