OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2017 The Chromium Authors. All rights reserved. | 2 # Copyright 2017 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 # | 5 # |
6 # Script to download, package, update, and upload OpenCV (cv2). | 6 # Script to download, package, update, and upload OpenCV (cv2). |
| 7 # |
| 8 # Note: This has not been tested on Windows. The Windows cv2 binary in |
| 9 # Cloud Storage was created manually by the following process: |
| 10 # * Download |
| 11 # https://github.com/opencv/opencv/releases/download/2.4.13.2/opencv-2.4.13.2-
vc14.exe |
| 12 # * Open using 7-Zip (or just run the exe) |
| 13 # * Extract opencv/build/python/2.7/x64/cv2.pyd |
| 14 # * Create a zip file containing only cv2.pyd |
| 15 # * Rename cv2.zip to cv2_$(sha1sum cv2.zip) |
| 16 # * Upload to cloud storage at chromium-telemetry/binary_dependencies |
| 17 # * Add entry including hash and version number to cv2 win_AMD64 entry |
| 18 # in binary_dependencies.json |
7 | 19 |
8 DESCRIPTION = '''\ | 20 DESCRIPTION = '''\ |
9 Downloads + builds OpenCV (cv2), packages it as a zip, and updates \ | 21 Downloads + builds OpenCV (cv2), packages it as a zip, and updates \ |
10 binary_dependencies.json and Cloud Storage with the result.''' | 22 binary_dependencies.json and Cloud Storage with the result. (NOTE: \ |
| 23 Not tested on Windows. See comments for details.)''' |
11 | 24 |
12 import argparse | 25 import argparse |
13 import contextlib | 26 import contextlib |
14 import glob | 27 import glob |
15 import multiprocessing | 28 import multiprocessing |
16 import os | 29 import os |
17 import shutil | 30 import shutil |
18 import sys | 31 import sys |
19 import tarfile | 32 import tarfile |
20 import urllib | 33 import urllib |
(...skipping 15 matching lines...) Expand all Loading... |
36 NUMPY_PATH = glob.glob(NUMPY_GLOB) | 49 NUMPY_PATH = glob.glob(NUMPY_GLOB) |
37 if len(NUMPY_PATH) != 1: | 50 if len(NUMPY_PATH) != 1: |
38 raise ImportError("telemetry/third_party/numpy/lib/numpy_* is required. " | 51 raise ImportError("telemetry/third_party/numpy/lib/numpy_* is required. " |
39 "Ensure this by running fetch_telemetry_binary_dependencies. " | 52 "Ensure this by running fetch_telemetry_binary_dependencies. " |
40 "If a binary dependency for numpy is not available on this platform, " | 53 "If a binary dependency for numpy is not available on this platform, " |
41 "it must be configured before building cv2.") | 54 "it must be configured before building cv2.") |
42 NUMPY_PATH = NUMPY_PATH[0] | 55 NUMPY_PATH = NUMPY_PATH[0] |
43 # insert rather than append to make sure we don't get system numpy. | 56 # insert rather than append to make sure we don't get system numpy. |
44 sys.path.insert(1, NUMPY_PATH) | 57 sys.path.insert(1, NUMPY_PATH) |
45 | 58 |
| 59 class RollError(Exception): |
| 60 pass |
| 61 |
46 # Dependency update helper | 62 # Dependency update helper |
47 def update_dependency(dependency, path, version): | 63 def update_dependency(dependency, path, version): |
48 config = os.path.join(CATAPULT_ROOT, 'telemetry', 'telemetry', 'internal', | 64 config = os.path.join(CATAPULT_ROOT, 'telemetry', 'telemetry', 'internal', |
49 'binary_dependencies.json') | 65 'binary_dependencies.json') |
50 | 66 |
51 os_name = platform_module.GetHostPlatform().GetOSName() | 67 os_name = platform_module.GetHostPlatform().GetOSName() |
52 arch_name = platform_module.GetHostPlatform().GetArchName() | 68 arch_name = platform_module.GetHostPlatform().GetArchName() |
53 platform = "{}_{}".format(os_name, arch_name) | 69 platform = "{}_{}".format(os_name, arch_name) |
54 | 70 |
55 c = base_config.BaseConfig(config, writable=True) | 71 c = base_config.BaseConfig(config, writable=True) |
56 c.AddCloudStorageDependencyUpdateJob( | 72 try: |
57 dependency, platform, path, version=version, execute_job=True) | 73 old_version = c.GetVersion(dependency, platform) |
| 74 print 'Updating from version: {}'.format(old_version) |
| 75 except ValueError: |
| 76 raise RollError( |
| 77 ('binary_dependencies.json entry for {} missing or invalid; please add ' |
| 78 'it first! (need download_path and path_within_archive)') |
| 79 .format(platform)) |
| 80 |
| 81 if path: |
| 82 c.AddCloudStorageDependencyUpdateJob( |
| 83 dependency, platform, path, version=version, execute_job=True) |
| 84 |
| 85 def verify_dependency_entry(dependency): |
| 86 update_dependency(dependency, None, None) |
58 | 87 |
59 # Main | 88 # Main |
60 def main(version): | 89 def main(version): |
| 90 verify_dependency_entry('cv2') |
| 91 |
61 outdir = os.path.join(SCRIPT_DIR, 'lib') | 92 outdir = os.path.join(SCRIPT_DIR, 'lib') |
62 if os.path.exists(outdir): | 93 if os.path.exists(outdir): |
63 shutil.rmtree(outdir) | 94 shutil.rmtree(outdir) |
64 os.mkdir(outdir) | 95 os.mkdir(outdir) |
65 | 96 |
66 tarball_url = \ | 97 tarball_url = \ |
67 'https://codeload.github.com/opencv/opencv/tar.gz/{}'.format(version) | 98 'https://codeload.github.com/opencv/opencv/tar.gz/{}'.format(version) |
68 | 99 |
69 zip_full_base = os.path.join(outdir, 'cv2') | 100 zip_full_base = os.path.join(outdir, 'cv2') |
70 zip_result = None | 101 zip_result = None |
(...skipping 17 matching lines...) Expand all Loading... |
88 '-DCMAKE_INSTALL_PREFIX={}'.format(os.path.join('..', 'install')), | 119 '-DCMAKE_INSTALL_PREFIX={}'.format(os.path.join('..', 'install')), |
89 PYTHONPATH=NUMPY_PATH) | 120 PYTHONPATH=NUMPY_PATH) |
90 sh.CallProgram(['make'], | 121 sh.CallProgram(['make'], |
91 '-j{}'.format(multiprocessing.cpu_count()), | 122 '-j{}'.format(multiprocessing.cpu_count()), |
92 'install', | 123 'install', |
93 PYTHONPATH=NUMPY_PATH) | 124 PYTHONPATH=NUMPY_PATH) |
94 with sh.ScopedChangeDir('install'): | 125 with sh.ScopedChangeDir('install'): |
95 print 'Zipping result...' | 126 print 'Zipping result...' |
96 root_dir = glob.glob(os.path.join('lib', 'python2.*', '*-packages')) | 127 root_dir = glob.glob(os.path.join('lib', 'python2.*', '*-packages')) |
97 if len(root_dir) != 1: | 128 if len(root_dir) != 1: |
98 raise Exception( | 129 raise RollError( |
99 'Expected one glob match, found {}'.format(len(root_dir))) | 130 'Expected one glob match, found {}'.format(len(root_dir))) |
100 root_dir = root_dir[0] | 131 root_dir = root_dir[0] |
101 zip_result = shutil.make_archive( | 132 zip_result = shutil.make_archive( |
102 base_name=zip_full_base, | 133 base_name=zip_full_base, |
103 format='zip', | 134 format='zip', |
104 root_dir=root_dir, | 135 root_dir=root_dir, |
105 base_dir='.') # '.' gives us everything in the root_dir | 136 base_dir='.') # '.' gives us everything in the root_dir |
106 print 'Uploading zip...' | 137 print 'Uploading zip...' |
107 update_dependency('cv2', zip_result, version) | 138 update_dependency('cv2', zip_result, version) |
108 | 139 |
109 print '''\ | 140 print '''\ |
110 Don't forget to run: | 141 Don't forget to run: |
111 $ GYP_DEFINES=fetch_telemetry_dependencies=1 \ | 142 $ GYP_DEFINES=fetch_telemetry_dependencies=1 \ |
112 bin/fetch_telemetry_binary_dependencies | 143 bin/fetch_telemetry_binary_dependencies |
113 if you want to use the new dependency version locally!''' | 144 if you want to use the new dependency version locally!''' |
114 | 145 |
115 if __name__ == '__main__': | 146 if __name__ == '__main__': |
116 VERSION_HELP = '''\ | 147 VERSION_HELP = '''\ |
117 OpenCV package version, e.g. 2.4.13.2. For a release list, see \ | 148 OpenCV package version, e.g. 2.4.13.2. For a release list, see \ |
118 <https://github.com/opencv/opencv/releases>. \ | 149 <https://github.com/opencv/opencv/releases>. \ |
119 For version support, see \ | 150 For version support, see \ |
120 `telemetry/telemetry/internal/util/external_modules.py`.''' | 151 `telemetry/telemetry/internal/util/external_modules.py`.''' |
121 | 152 |
122 try: | 153 try: |
123 parser = argparse.ArgumentParser(description=DESCRIPTION) | 154 parser = argparse.ArgumentParser(description=DESCRIPTION) |
124 parser.add_argument('version', help=VERSION_HELP) | 155 parser.add_argument('version', help=VERSION_HELP) |
125 args = parser.parse_args() | 156 args = parser.parse_args() |
126 | 157 |
127 os.chdir(SCRIPT_DIR) | 158 os.chdir(SCRIPT_DIR) |
128 main(args.version) | 159 main(args.version) |
129 except Exception as e: | 160 except RollError as e: |
130 print '{}: {}'.format(type(e).__name__, e.message) | 161 print '{}: {}'.format(type(e).__name__, e.message) |
131 sys.exit(1) | 162 sys.exit(1) |
OLD | NEW |