-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rachguo
authored and
rachguo
committed
Nov 16, 2023
1 parent
b653bd6
commit 2273c98
Showing
3 changed files
with
23 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import shutil | ||
import subprocess | ||
import sys | ||
from collections import defaultdict | ||
|
||
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
REPO_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", "..", "..", "..")) | ||
|
@@ -100,6 +101,17 @@ def _build_for_osx_sysroot( | |
|
||
return framework_dir | ||
|
||
def _merge_json_lists(files, output_file): | ||
merged_data = defaultdict(dict) | ||
|
||
for file in files: | ||
with open(file, 'r') as f: | ||
Check warning Code scanning / lintrunner RUFF/UP015 Warning
Unnecessary open mode parameters.
See https://beta.ruff.rs/docs/rules/ |
||
data = json.load(f) | ||
for platform, values in data.items(): | ||
merged_data[platform].update(values) | ||
|
||
with open(output_file, 'w') as f: | ||
json.dump(merged_data, f, indent=2) | ||
|
||
def _build_package(args): | ||
build_settings = _parse_build_settings(args) | ||
|
@@ -112,7 +124,7 @@ def _build_package(args): | |
# build framework for individual sysroot | ||
base_build_command = [] | ||
framework_dirs = [] | ||
framework_info_path = "" | ||
framework_info_files_to_merge = [] | ||
public_headers_path = "" | ||
for sysroot in build_settings["build_osx_archs"]: | ||
base_build_command = [sys.executable, BUILD_PY] + build_settings["build_params"][sysroot] + ["--config=" + build_config] | ||
|
@@ -132,17 +144,20 @@ def _build_package(args): | |
args.build_dynamic_framework, | ||
) | ||
framework_dirs.append(framework_dir) | ||
# podspec and headers for each sysroot are the same, pick one of them | ||
if not framework_info_path: | ||
framework_info_path = os.path.join(os.path.dirname(framework_dir), "framework_info.json") | ||
|
||
curr_framework_info_path = os.path.join(os.path.dirname(framework_dir), "framework_info.json") | ||
framework_info_files_to_merge.append(curr_framework_info_path) | ||
|
||
# headers for each sysroot are the same, pick one of them | ||
if not public_headers_path: | ||
public_headers_path = os.path.join(os.path.dirname(framework_dir), "onnxruntime.framework", "Headers") | ||
|
||
# create the folder for xcframework and copy the LICENSE and podspec file | ||
# create the folder for xcframework and copy the LICENSE and framework_info.json file | ||
xcframework_dir = os.path.join(build_dir, "framework_out") | ||
pathlib.Path(xcframework_dir).mkdir(parents=True, exist_ok=True) | ||
shutil.copy(os.path.join(REPO_DIR, "LICENSE"), xcframework_dir) | ||
shutil.copytree(public_headers_path, os.path.join(xcframework_dir, "Headers"), dirs_exist_ok=True) | ||
shutil.copy(framework_info_path, build_dir) | ||
_merge_json_lists(framework_info_files_to_merge, os.path.join(build_dir, "framework_info.json")) | ||
|
||
# remove existing xcframework if any | ||
xcframework_path = os.path.join(xcframework_dir, "onnxruntime.xcframework") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters