• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2
3import os
4import shutil
5import zipfile
6import argparse
7
8def extract_source(in_zip_path, out_src_path):
9    "depress source code form release package"
10    print('Extracting zipped release package...')
11    f = zipfile.ZipFile(in_zip_path, "r")
12    f.extractall(path=out_src_path)
13    old_src_dir = out_src_path + "/mindspore-v1.8.1/"
14    new_src_dir = out_src_path + "/source/"
15    os.rename(old_src_dir, new_src_dir)
16    print("Done extraction.")
17
18def do_patch(patch_dir, target_dir):
19    patches = [
20        '0001-generate-schema-headers-manually.patch',
21        '0002-generate-nnacl-simd-headers-manually.patch',
22        '0003-implement-mindir-module-and-support-nnrt-delegate.patch',
23        '0004-adapt-build-gn-and-provide-C-API-for-OHOS.patch',
24        '0005-mindir-add-custom-op.patch',
25        '0006-Support-converting-THIRDPARTY-model-in-MSLite.patch',
26        '0007-support-third-party-model-in-mslite-runtime.patch',
27        '0008-add-js-api.patch',
28        '0009-adapt-nnrt-v2_0.patch',
29        '0010-nnrt-delegate-supports-heterogeneous-predition.patch',
30        '0011-replace-memcpy-with-memcpy_s-in-mindir.patch',
31        '0012-add-secure-option.patch',
32        '0013-train-0001.patch',
33        '0014-train-0002.patch',
34        '0015-train-0003.patch',
35        '0016-fix-train-bug.patch',
36        '0017-support-build-training-lib.patch',
37        '0018-mindir-MaxPoolFusion-add-roundMode.patch',
38        '0019-change-nnrt-as-external_dep-in-mindir.patch',
39        '0020-add-ohos-js-callback-api-and-bugfix.patch',
40        '0021-js-namespace-bugfix.patch',
41        '0022-support-cross-compile-with-ohos-ndk.patch',
42        '0023-js-info-bugfix.patch',
43        '0024-js-info2-bugfix.patch',
44        '0025-js-callback-bugfix.patch',
45        '0026-js-buffer-add-bugfix.patch',
46        '0027-js-buffer-leakage-bugfix.patch',
47        '0028-modify-ext_dep-hilog.patch',
48        '0029-change-subsystem-name-to-thirdparty.patch',
49        '0030-fix-core-binding-in-ohos.patch',
50        '0031-backport-CVE-2023-2970.patch',
51        '0032-js-enable-enum.patch',
52        '0033-support-fp16-for-arm64-arch.patch',
53        '0034-splite-ndk-so.patch',
54        '0035-nnrt-delegate-support-metagraph.patch',
55        '0036-new-dynamic-quant-algorigthm-and-init-packed.patch',
56        '0037-npu-support-custom-model.patch',
57        '0038-adapt-nnrt-ext-deps.patch',
58        '0039-fix-double-destry-nnrt-mode.patch',
59    ]
60
61    cwd = os.getcwd()
62    os.chdir(target_dir)
63    print('Change dir to', os.getcwd())
64    os.system('git init .')
65    os.system('git add .; git commit -m "init"')
66
67    for patch in patches:
68        print('Applying ', patch, '...')
69        ret = os.system('git apply ' + patch_dir + '/' + patch)
70        if ret != 0:
71            raise Exception("Apply patch {} failed.".format(patch))
72        os.system('git add .; git commit -m "auto-apply ' + patch + '"')
73        print('Done')
74    os.chdir(cwd)
75
76def create_status_file(out_src_path):
77    f = open(out_src_path + '/.status', 'w')
78    f.write('ok')
79    f.close
80
81
82def main_work():
83    parser = argparse.ArgumentParser(description="mindspore build helper")
84    parser.add_argument('--in_zip_path')
85    parser.add_argument('--out_src_path')
86    parser.add_argument('--patch_dir')
87    args = vars(parser.parse_args())
88
89    in_zip_path = os.path.realpath(args['in_zip_path'])
90    out_src_path = args['out_src_path']
91    patch_dir = os.path.realpath(args['patch_dir'])
92
93    if os.path.exists(out_src_path):
94        shutil.rmtree(out_src_path)
95
96    os.mkdir(out_src_path)
97    out_src_path = os.path.realpath(out_src_path)
98
99    extract_source(in_zip_path, out_src_path)
100
101    do_patch(patch_dir, out_src_path + '/source/')
102
103    create_status_file(out_src_path)
104
105if __name__ == "__main__":
106    main_work()
107
108