1# Copyright (c) 2020, Riverbank Computing Limited
2# All rights reserved.
3#
4# This copy of PyQt-builder is licensed for use under the terms of the SIP
5# License Agreement.  See the file LICENSE for more details.
6#
7# This copy of PyQt-builder may also used under the terms of the GNU General
8# Public License v2 or v3 as published by the Free Software Foundation which
9# can be found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this
10# package.
11#
12# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
13# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
16# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22# POSSIBILITY OF SUCH DAMAGE.
23
24
25import os
26import shutil
27
28from ..abstract_package import AbstractPackage
29from ..verbose import verbose
30
31
32# The directory containing the DLLs.
33_DLLS_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'dlls')
34
35
36class PyQt(AbstractPackage):
37    """ The base PyQt package. """
38
39    def bundle_msvc_runtime(self, target_qt_dir, arch):
40        """ Bundle the MSVC runtime. """
41
42        verbose("Bundling the MSVC runtime")
43
44        self._bundle_dlls(target_qt_dir,
45                os.path.join(_DLLS_DIR,
46                        'msvc-64' if arch == 'win_amd64' else 'msvc-32'))
47
48    def bundle_openssl(self, target_qt_dir, openssl_dir, arch):
49        """ Bundle the OpenSSL DLLs. """
50
51        if openssl_dir:
52            verbose(
53                    "Bundling the OpenSSL libraries from '{0}'".format(
54                            openssl_dir))
55        else:
56            verbose("Bundling the default OpenSSL libraries")
57
58            openssl_dir = os.path.join(_DLLS_DIR,
59                    'openssl-64' if arch == 'win_amd64' else 'openssl-32')
60
61        self._bundle_dlls(target_qt_dir, openssl_dir)
62
63    @staticmethod
64    def _bundle_dlls(target_qt_dir, dlls_dir):
65        """ Bundle the DLLs in a directory. """
66
67        bin_dir = os.path.join(target_qt_dir, 'bin')
68        os.makedirs(bin_dir, exist_ok=True)
69
70        for dll in os.listdir(dlls_dir):
71            shutil.copy2(os.path.join(dlls_dir, dll), bin_dir)
72