13
13
def main ():
14
14
os .chdir (os .path .dirname (os .path .abspath (__file__ )))
15
15
16
- # These are needed for source fetching
16
+ CI_BUILD = os .environ .get ("CI_BUILD" , "False" )
17
+ is_CI_build = True if CI_BUILD == "True" else False
17
18
cmake_source_dir = "opencv"
18
19
minimum_supported_numpy = "1.13.1"
19
20
build_contrib = get_build_env_var_by_name ("contrib" )
20
- # headless flag to skip GUI deps if needed
21
21
build_headless = get_build_env_var_by_name ("headless" )
22
22
23
23
if sys .version_info [:2 ] >= (3 , 6 ):
@@ -30,11 +30,16 @@ def main():
30
30
numpy_version = "numpy>=%s" % minimum_supported_numpy
31
31
32
32
python_version = cmaker .CMaker .get_python_version ()
33
- python_lib_path = cmaker .CMaker .get_python_library (python_version ).replace ('\\ ' , '/' )
34
- python_include_dir = cmaker .CMaker .get_python_include_dir (python_version ).replace ('\\ ' , '/' )
33
+ python_lib_path = cmaker .CMaker .get_python_library (python_version ).replace (
34
+ "\\ " , "/"
35
+ )
36
+ python_include_dir = cmaker .CMaker .get_python_include_dir (python_version ).replace (
37
+ "\\ " , "/"
38
+ )
35
39
36
40
if os .path .exists (".git" ):
37
41
import pip ._internal .vcs .git as git
42
+
38
43
g = git .Git () # NOTE: pip API's are internal, this has to be refactored
39
44
40
45
g .run_command (["submodule" , "sync" ])
@@ -47,7 +52,9 @@ def main():
47
52
["submodule" , "update" , "--init" , "--recursive" , "opencv_contrib" ]
48
53
)
49
54
50
- package_version , build_contrib , build_headless = get_opencv_version (build_contrib , build_headless )
55
+ package_version , build_contrib , build_headless = get_opencv_version (
56
+ build_contrib , build_headless
57
+ )
51
58
52
59
# https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
53
60
x64 = sys .maxsize > 2 ** 32
@@ -86,7 +93,10 @@ def main():
86
93
# In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
87
94
# Naming conventions vary so widely between versions and OSes
88
95
# had to give up on checking them.
89
- ["python/cv2[^/]*%(ext)s" % {"ext" : re .escape (sysconfig .get_config_var ("EXT_SUFFIX" ))}],
96
+ [
97
+ "python/cv2[^/]*%(ext)s"
98
+ % {"ext" : re .escape (sysconfig .get_config_var ("EXT_SUFFIX" ))}
99
+ ],
90
100
"cv2.data" : [ # OPENCV_OTHER_INSTALL_PATH
91
101
("etc" if os .name == "nt" else "share/opencv4" ) + r"/haarcascades/.*\.xml"
92
102
],
@@ -96,12 +106,14 @@ def main():
96
106
# Raw paths relative to sourcetree root.
97
107
files_outside_package_dir = {"cv2" : ["LICENSE.txt" , "LICENSE-3RD-PARTY.txt" ]}
98
108
109
+ ci_cmake_generator = (
110
+ ["-G" , "Visual Studio 14" + (" Win64" if x64 else "" )]
111
+ if os .name == "nt"
112
+ else ["-G" , "Unix Makefiles" ]
113
+ )
114
+
99
115
cmake_args = (
100
- (
101
- ["-G" , "Visual Studio 14" + (" Win64" if x64 else "" )]
102
- if os .name == "nt"
103
- else ["-G" , "Unix Makefiles" ] # don't make CMake try (and fail) Ninja first
104
- )
116
+ (ci_cmake_generator if is_CI_build else [])
105
117
+ [
106
118
# skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
107
119
"-DPYTHON3_EXECUTABLE=%s" % sys .executable ,
@@ -131,33 +143,40 @@ def main():
131
143
)
132
144
)
133
145
134
- # OS-specific components
135
- if sys .platform .startswith ('linux' ) and not build_headless :
136
- cmake_args .append ("-DWITH_QT=4" )
137
-
138
- if sys .platform == 'darwin' and not build_headless :
139
- cmake_args .append ("-DWITH_QT=5" )
140
- rearrange_cmake_output_data ["cv2.qt.plugins.platforms" ] = [
141
- (r"lib/qt/plugins/platforms/libqcocoa\.dylib" )
142
- ]
143
-
144
146
if build_headless :
145
147
# it seems that cocoa cannot be disabled so on macOS the package is not truly headless
146
148
cmake_args .append ("-DWITH_WIN32UI=OFF" )
147
149
cmake_args .append ("-DWITH_QT=OFF" )
148
- cmake_args .append (
149
- "-DWITH_MSMF=OFF"
150
- ) # see: https://github.com/skvark/opencv-python/issues/263
150
+ cmake_args .append ("-DWITH_GTK=OFF" )
151
+ if is_CI_build :
152
+ cmake_args .append (
153
+ "-DWITH_MSMF=OFF"
154
+ ) # see: https://github.com/skvark/opencv-python/issues/263
155
+
156
+ # OS-specific components during CI builds
157
+ if is_CI_build :
158
+ if sys .platform .startswith ("linux" ) and not build_headless :
159
+ cmake_args .append ("-DWITH_QT=4" )
151
160
152
- if sys .platform .startswith ("linux" ):
153
- cmake_args .append ("-DWITH_V4L=ON" )
154
- cmake_args .append ("-DWITH_LAPACK=ON" )
155
- cmake_args .append ("-DENABLE_PRECOMPILED_HEADERS=OFF" )
161
+ if sys .platform == "darwin" and not build_headless :
162
+ cmake_args .append ("-DWITH_QT=5" )
163
+
164
+ if sys .platform .startswith ("linux" ):
165
+ cmake_args .append ("-DWITH_V4L=ON" )
166
+ cmake_args .append ("-DWITH_LAPACK=ON" )
167
+ cmake_args .append ("-DENABLE_PRECOMPILED_HEADERS=OFF" )
156
168
157
169
if sys .platform .startswith ("linux" ) and not x64 and "bdist_wheel" in sys .argv :
158
170
subprocess .check_call ("patch -p0 < patches/patchOpenEXR" , shell = True )
159
171
160
- if sys .platform == "darwin" and "bdist_wheel" in sys .argv :
172
+ if (
173
+ sys .platform == "darwin"
174
+ and "bdist_wheel" in sys .argv
175
+ and ("WITH_QT=5" in sys .argv or "WITH_QT=5" in cmake_args )
176
+ ):
177
+ rearrange_cmake_output_data ["cv2.qt.plugins.platforms" ] = [
178
+ (r"lib/qt/plugins/platforms/libqcocoa\.dylib" )
179
+ ]
161
180
subprocess .check_call ("patch -p1 < patches/patchQtPlugins" , shell = True )
162
181
163
182
# works via side effect
@@ -357,22 +376,25 @@ def _classify_installed_files_override(
357
376
cmake_install_dir = cmake_install_reldir ,
358
377
)
359
378
379
+
360
380
def get_opencv_version (contrib , headless ):
361
381
# cv2/version.py should be generated by running find_version.py
362
382
version = {}
363
383
here = os .path .abspath (os .path .dirname (__file__ ))
364
384
version_file = os .path .join (here , "cv2" , "version.py" )
365
385
366
- if not os .path .exists (version_file ):
367
- old_args = sys .argv .copy ()
368
- sys .argv = ['' , str (contrib ), str (headless )]
369
- runpy .run_path ("find_version.py" , run_name = "__main__" )
370
- sys .argv = old_args
386
+ # generate a fresh version.py always when Git repository exists
387
+ if os .path .exists (".git" ):
388
+ old_args = sys .argv .copy ()
389
+ sys .argv = ["" , str (contrib ), str (headless )]
390
+ runpy .run_path ("find_version.py" , run_name = "__main__" )
391
+ sys .argv = old_args
371
392
372
393
with open (version_file ) as fp :
373
394
exec (fp .read (), version )
374
395
375
- return version ['opencv_version' ], version ['contrib' ], version ['headless' ]
396
+ return version ["opencv_version" ], version ["contrib" ], version ["headless" ]
397
+
376
398
377
399
def get_build_env_var_by_name (flag_name ):
378
400
flag_set = False
@@ -390,6 +412,7 @@ def get_build_env_var_by_name(flag_name):
390
412
391
413
return flag_set
392
414
415
+
393
416
# This creates a list which is empty but returns a length of 1.
394
417
# Should make the wheel a binary distribution and platlib compliant.
395
418
class EmptyListWithLength (list ):
0 commit comments