diff options
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 109 |
1 files changed, 109 insertions, 0 deletions
@@ -1,3 +1,42 @@ +############################################################################# +## +## Copyright (C) 2017 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of PySide2. +## +## $QT_BEGIN_LICENSE:LGPL$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU Lesser General Public License Usage +## Alternatively, this file may be used under the terms of the GNU Lesser +## General Public License version 3 as published by the Free Software +## Foundation and appearing in the file LICENSE.LGPL3 included in the +## packaging of this file. Please review the following information to +## ensure the GNU Lesser General Public License version 3 requirements +## will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 2.0 or (at your option) the GNU General +## Public license version 3 or any later version approved by the KDE Free +## Qt Foundation. The licenses are as published by the Free Software +## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-2.0.html and +## https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + import sys import os import re @@ -7,6 +46,7 @@ import time import shutil import subprocess import fnmatch +import glob import itertools import popenasync import glob @@ -666,6 +706,75 @@ def osx_add_qt_rpath(library_path, qt_lib_dir, back_tick('install_name_tool -add_rpath {rpath} {library_path}'.format( rpath=qt_lib_dir, library_path=library_path)) +# Find an executable specified by a glob pattern ('foo*') in the OS path +def findGlobInPath(pattern): + result = [] + if sys.platform == 'win32': + pattern += '.exe' + + for path in os.environ.get('PATH', '').split(os.pathsep): + for match in glob.glob(os.path.join(path, pattern)): + result.append(match) + return result + +# Locate the most recent version of llvmConfig in the path. +def findLlvmConfig(): + versionRe = re.compile('(\d+)\.(\d+)\.(\d+)') + result = None + lastVersionString = '000000' + for llvmConfig in findGlobInPath('llvm-config*'): + try: + output = run_process_output([llvmConfig, '--version']) + if output: + match = versionRe.match(output[0]) + if match: + versionString = '%02d%02d%02d' % (int(match.group(1)), + int(match.group(2)), int(match.group(3))) + if (versionString > lastVersionString): + result = llvmConfig + lastVersionString = versionString + except OSError: + pass + return result + +# Add Clang to path for Windows for the shiboken ApiExtractor tests. +# Revisit once Clang is bundled with Qt. +def detectClang(): + source = 'LLVM_INSTALL_DIR' + clangDir = os.environ.get(source, None) + if not clangDir: + source = 'CLANG_INSTALL_DIR' + clangDir = os.environ.get(source, None) + if not clangDir: + source = findLlvmConfig() + try: + output = run_process_output([source, '--prefix']) + if output: + clangDir = output[0] + except OSError: + pass + if clangDir: + arch = '64' if sys.maxsize > 2**31-1 else '32' + clangDir = clangDir.replace('_ARCH_', arch) + return (clangDir, source) + +def download_and_extract_7z(fileurl, target): + """ Downloads 7z file from fileurl and extract to target """ + print("Downloading fileUrl %s " % fileurl) + info = "" + try: + localfile, info = urllib.urlretrieve(fileurl) + except: + print("Error downloading %r : %r" % (fileurl, info)) + raise RuntimeError(' Error downloading ' + fileurl) + + try: + outputDir = "-o" + target + print("calling 7z x %s %s" % (localfile, outputDir)) + subprocess.call(["7z", "x", "-y", localfile, outputDir]) + except: + raise RuntimeError(' Error extracting ' + localfile) + def split_and_strip(input): lines = [s.strip() for s in input.splitlines()] return lines |