|
10 | 10 |
|
11 | 11 | from .log import log, LogLevel
|
12 | 12 | from .qtinfo import QtInfo
|
13 |
| -from .utils import memoize, which |
| 13 | +from .utils import memoize, which, Singleton |
14 | 14 |
|
15 | 15 | _AVAILABLE_MKSPECS = ["ninja", "msvc", "mingw"] if sys.platform == "win32" else ["ninja", "make"]
|
16 | 16 |
|
@@ -41,7 +41,7 @@ def _warn_deprecated_option(option, replacement=None):
|
41 | 41 | log.warning(w)
|
42 | 42 |
|
43 | 43 |
|
44 |
| -class Options(object): |
| 44 | +class Options(object, metaclass=Singleton): |
45 | 45 | def __init__(self):
|
46 | 46 |
|
47 | 47 | # Dictionary containing values of all the possible options.
|
@@ -103,86 +103,82 @@ def option_value(self, name, short_option_name=None, remove=True):
|
103 | 103 | self.dict[name] = value
|
104 | 104 | return value
|
105 | 105 |
|
| 106 | + def find_qtpaths(self): |
| 107 | + # Skip the first run that will trigger the three different build |
| 108 | + # stated of the setup process |
| 109 | + if self.dict["internal-build-type"] is None: |
| 110 | + return None |
| 111 | + # for these command --qtpaths should not be required |
| 112 | + no_qtpaths_commands = ["--help", "--help-commands", "--qt-target-path", "build_base_docs"] |
106 | 113 |
|
107 |
| -options = Options() |
108 |
| - |
109 |
| - |
110 |
| -def has_option(*args, **kwargs): |
111 |
| - return options.has_option(*args, **kwargs) |
112 |
| - |
113 |
| - |
114 |
| -def option_value(*args, **kwargs): |
115 |
| - return options.option_value(*args, **kwargs) |
116 |
| - |
| 114 | + for no_qtpaths_command in no_qtpaths_commands: |
| 115 | + if any(no_qtpaths_command in argument for argument in sys.argv): |
| 116 | + return None |
117 | 117 |
|
118 |
| -def _jobs_option_value(): |
119 |
| - """Option value for parallel builds.""" |
120 |
| - value = option_value('parallel', short_option_name='j') |
121 |
| - if value: |
122 |
| - return f"-j{value}" if not value.startswith('-j') else value |
123 |
| - return '' |
| 118 | + qtpaths = self.option_value("qtpaths") |
| 119 | + if qtpaths is not None: |
| 120 | + return qtpaths |
124 | 121 |
|
| 122 | + # if qtpaths is not given as cli option, try to find it in PATH |
| 123 | + qtpaths = which("qtpaths6") |
| 124 | + if qtpaths is not None: |
| 125 | + return str(Path(qtpaths).resolve()) |
125 | 126 |
|
126 |
| -def find_qtpaths(): |
127 |
| - # for these command --qtpaths should not be required |
128 |
| - no_qtpaths_commands = ["--help", "--help-commands", "--qt-target-path", "build_base_docs"] |
| 127 | + qtpaths = which("qtpaths") |
| 128 | + if qtpaths is not None: |
| 129 | + return str(Path(qtpaths).resolve()) |
129 | 130 |
|
130 |
| - for no_qtpaths_command in no_qtpaths_commands: |
131 |
| - if any(no_qtpaths_command in argument for argument in sys.argv): |
132 |
| - return None |
| 131 | + if qtpaths is None: |
| 132 | + sys.exit(-1) |
133 | 133 |
|
134 |
| - qtpaths = option_value("qtpaths") |
135 |
| - if qtpaths: |
136 | 134 | return qtpaths
|
137 | 135 |
|
138 |
| - # if qtpaths is not given as cli option, try to find it in PATH |
139 |
| - qtpaths = which("qtpaths6") |
140 |
| - if qtpaths: |
141 |
| - return str(qtpaths.resolve()) |
142 |
| - |
143 |
| - qtpaths = which("qtpaths") |
144 |
| - if qtpaths: |
145 |
| - return str(qtpaths.resolve()) |
146 |
| - |
147 |
| - return qtpaths |
148 |
| - |
149 |
| - |
150 |
| -# Declare options which need to be known when instantiating the setuptools |
151 |
| -# commands or even earlier during SetupRunner.run(). |
152 |
| -OPTION = { |
153 |
| - "BUILD_TYPE": option_value("build-type"), |
154 |
| - "INTERNAL_BUILD_TYPE": option_value("internal-build-type"), |
155 |
| - # number of parallel build jobs |
156 |
| - "JOBS": _jobs_option_value(), |
157 |
| - # Legacy, not used any more. |
158 |
| - "JOM": has_option('jom'), |
159 |
| - "MACOS_USE_LIBCPP": has_option("macos-use-libc++"), |
160 |
| - "LOG_LEVEL": option_value("log-level", remove=False), |
161 |
| - "QUIET": has_option('quiet'), |
162 |
| - "VERBOSE_BUILD": has_option('verbose-build'), |
163 |
| - "SNAPSHOT_BUILD": has_option("snapshot-build"), |
164 |
| - "LIMITED_API": option_value("limited-api"), |
165 |
| - "UNOPTIMIZE": option_value("unoptimize"), |
166 |
| - "DISABLE_PYI": has_option("disable-pyi"), |
167 |
| - "SKIP_MYPY_TEST": has_option("skip-mypy-test"), |
168 |
| - "PACKAGE_TIMESTAMP": option_value("package-timestamp"), |
169 |
| - # This is used automatically by setuptools.command.install object, to |
170 |
| - # specify the final installation location. |
171 |
| - "FINAL_INSTALL_PREFIX": option_value("prefix", remove=False), |
172 |
| - "CMAKE_TOOLCHAIN_FILE": option_value("cmake-toolchain-file"), |
173 |
| - "SHIBOKEN_HOST_PATH": option_value("shiboken-host-path"), |
174 |
| - "SHIBOKEN_HOST_PATH_QUERY_FILE": option_value("internal-shiboken-host-path-query-file"), |
175 |
| - "QT_HOST_PATH": option_value("qt-host-path"), |
176 |
| - # This is used to identify the template for doc builds |
177 |
| - "QTPATHS": find_qtpaths() |
178 |
| - # This is an optional command line option. If --qtpaths is not provided via command-line, |
179 |
| - # then qtpaths is checked inside PATH variable |
180 |
| -} |
181 |
| - |
182 |
| -_deprecated_option_jobs = option_value('jobs') |
183 |
| -if _deprecated_option_jobs: |
184 |
| - _warn_deprecated_option('jobs', 'parallel') |
185 |
| - OPTION["JOBS"] = _deprecated_option_jobs |
| 136 | + def _jobs_option_value(self): |
| 137 | + """Option value for parallel builds.""" |
| 138 | + value = self.option_value('parallel', short_option_name='j') |
| 139 | + |
| 140 | + _deprecated_option_jobs = self.option_value('jobs') |
| 141 | + if _deprecated_option_jobs: |
| 142 | + _warn_deprecated_option('jobs', 'parallel') |
| 143 | + value = _deprecated_option_jobs |
| 144 | + |
| 145 | + if value: |
| 146 | + return f"-j{value}" if not value.startswith('-j') else value |
| 147 | + return '' |
| 148 | + |
| 149 | + def resolve(self): |
| 150 | + return { |
| 151 | + "BUILD_TYPE": self.option_value("build-type"), |
| 152 | + "INTERNAL_BUILD_TYPE": self.option_value("internal-build-type"), |
| 153 | + # number of parallel build jobs |
| 154 | + "JOBS": self._jobs_option_value(), |
| 155 | + # Legacy, not used any more. |
| 156 | + "JOM": self.has_option('jom'), |
| 157 | + "MACOS_USE_LIBCPP": self.has_option("macos-use-libc++"), |
| 158 | + "LOG_LEVEL": self.option_value("log-level", remove=False), |
| 159 | + "QUIET": self.has_option('quiet'), |
| 160 | + "VERBOSE_BUILD": self.has_option('verbose-build'), |
| 161 | + "SNAPSHOT_BUILD": self.has_option("snapshot-build"), |
| 162 | + "LIMITED_API": self.option_value("limited-api"), |
| 163 | + "UNOPTIMIZE": self.option_value("unoptimize"), |
| 164 | + "DISABLE_PYI": self.has_option("disable-pyi"), |
| 165 | + "SKIP_MYPY_TEST": self.has_option("skip-mypy-test"), |
| 166 | + "PACKAGE_TIMESTAMP": self.option_value("package-timestamp"), |
| 167 | + # This is used automatically by setuptools.command.install object, to |
| 168 | + # specify the final installation location. |
| 169 | + "FINAL_INSTALL_PREFIX": self.option_value("prefix", remove=False), |
| 170 | + "CMAKE_TOOLCHAIN_FILE": self.option_value("cmake-toolchain-file"), |
| 171 | + "SHIBOKEN_HOST_PATH": self.option_value("shiboken-host-path"), |
| 172 | + "SHIBOKEN_HOST_PATH_QUERY_FILE": self.option_value( |
| 173 | + "internal-shiboken-host-path-query-file" |
| 174 | + ), |
| 175 | + "QT_HOST_PATH": self.option_value("qt-host-path"), |
| 176 | + # This is used to identify the template for doc builds |
| 177 | + "QTPATHS": self.find_qtpaths() |
| 178 | + # This is an optional command line option. |
| 179 | + # If --qtpaths is not provided via command-line, |
| 180 | + # then qtpaths is checked inside PATH variable |
| 181 | + } |
186 | 182 |
|
187 | 183 |
|
188 | 184 | class CommandMixin(object):
|
@@ -499,12 +495,11 @@ def _do_finalize(self):
|
499 | 495 | except Exception as e:
|
500 | 496 | if not self.qt_target_path:
|
501 | 497 | log.error(
|
502 |
| - "\nCould not find Qt. You can pass the --qt-target-path=<qt-dir> option " |
503 |
| - "as a hint where to find Qt. Error was:\n\n\n") |
| 498 | + "Could not find Qt. You can pass the --qt-target-path=<qt-dir> option " |
| 499 | + "as a hint where to find Qt.\n") |
504 | 500 | else:
|
505 |
| - log.error( |
506 |
| - f"\nCould not find Qt via provided option --qt-target-path={qt_target_path}" |
507 |
| - "Error was:\n\n\n") |
| 501 | + log.error("Could not find Qt via provided option " |
| 502 | + f"--qt-target-path={qt_target_path}\n") |
508 | 503 | raise e
|
509 | 504 |
|
510 | 505 | OPTION['CMAKE'] = self.cmake.resolve()
|
@@ -629,3 +624,7 @@ def _determine_defaults_and_check(self):
|
629 | 624 | return False
|
630 | 625 |
|
631 | 626 | return True
|
| 627 | + |
| 628 | + |
| 629 | +# OPTION dictionary that will be imported in other build_scripts |
| 630 | +OPTION = Options().resolve() |
0 commit comments