Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCons: Decode stdout from subprocess #2201

Merged
merged 13 commits into from
Aug 23, 2019
Merged
30 changes: 20 additions & 10 deletions build/depends.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-

import os
import subprocess

from . import util
from .mixxx import Dependence, Feature
import SCons.Script as SCons
Expand Down Expand Up @@ -197,15 +199,19 @@ def uic(build):
@staticmethod
def find_framework_libdir(qtdir):
# Try pkg-config on Linux
import sys
if sys.platform.startswith('linux') or sys.platform.find('bsd') >= 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we musn't remove this line, because it makes the MacOS build fail...

if any(os.access(os.path.join(path, 'pkg-config'), os.X_OK) for path in os.environ["PATH"].split(os.pathsep)):
import subprocess
try:
core = subprocess.Popen(["pkg-config", "--variable=libdir", "Qt5Core"], stdout = subprocess.PIPE).communicate()[0].rstrip().decode()
finally:
if os.path.isdir(core):
return core
pkg_config_cmd = ['pkg-config', '--variable=libdir', 'Qt5Core']
try:
output = subprocess.check_output(pkg_config_cmd)
except OSError:
# pkg-config is not installed
pass
except subprocess.CalledProcessError:
# pkg-config failed to find Qt5Core
pass
else:
core = output.decode('utf-8').rstrip()
if os.path.isdir(core):
return core

for d in (os.path.join(qtdir, x) for x in ['', 'Frameworks', 'lib']):
core = os.path.join(d, 'QtCore.framework')
Expand Down Expand Up @@ -1294,7 +1300,11 @@ def sources(self, build):
'src/preferences/dialog/dlgprefvinyldlg.ui',
'src/preferences/dialog/dlgprefwaveformdlg.ui',
]
map(Qt.uic(build), ui_files)

# In Python 3.x, map() returns a "map object" (instead of a list),
# which is evaluated on-demand rather than at once. To invoke uic
# for all *.ui files at once, we need to cast it to a list here.
list(map(Qt.uic(build), ui_files))

if build.platform_is_windows:
# Add Windows resource file with icons and such
Expand Down
72 changes: 45 additions & 27 deletions build/mixxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from __future__ import with_statement

import logging
import platform
import sys
import os
import platform
import re
import shlex
import shutil
import subprocess
import sys

import SCons
from SCons import Script
Expand Down Expand Up @@ -123,6 +125,15 @@ def __init__(self, target, machine, build, toolchain, available_features):
self.bundle_pdbs = self.platform_is_windows and (
self.build_is_debug or Script.ARGUMENTS.get('bundle_pdbs', '') in ('yes', 'y', '1'))

self.scons_version = (
'unknown' if SCons.__version__.startswith('__VERSION')
else '%s (%s, %s)' % (
SCons.__version__,
SCons.__build__,
SCons.__date__,
))
logging.info("SCons version: %s" % self.scons_version)
logging.info("Python version: %s" % sys.version.replace('\n', ''))
logging.info("Target Platform: %s" % self.platform)
logging.info("Target Machine: %s" % self.machine)
logging.info("Build: %s" % self.build)
Expand Down Expand Up @@ -156,16 +167,21 @@ def __init__(self, target, machine, build, toolchain, available_features):

# Try fallback to pkg-config on Linux
if not os.path.isdir(default_qtdir) and self.platform == 'linux':
if any(os.access(os.path.join(path, 'pkg-config'), os.X_OK) for path in os.environ["PATH"].split(os.pathsep)):
import subprocess
try:
default_qtdir = subprocess.Popen(["pkg-config", "--variable=includedir", "Qt5Core"], stdout = subprocess.PIPE).communicate()[0].rstrip().decode()
finally:
pass
pkg_config_cmd = ['pkg-config', '--variable=includedir', 'Qt5Core']
try:
output = subprocess.check_output(pkg_config_cmd)
except OSError:
# pkg-config is not installed
pass
except subprocess.CalledProcessError:
# pkg-config failed to find Qt5Core
pass
else:
default_qtdir = output.decode('utf-8').rstrip()

# Ugly hack to check the qtdir argument
qtdir = Script.ARGUMENTS.get('qtdir',
os.environ.get('QTDIR', default_qtdir))
qtdir = Script.ARGUMENTS.get(
'qtdir', os.environ.get('QTDIR', default_qtdir)).rstrip()

# Validate the specified qtdir exists
if not os.path.isdir(qtdir):
Expand Down Expand Up @@ -211,23 +227,25 @@ def __init__(self, target, machine, build, toolchain, available_features):
self.read_environment_variables()

# Now that environment variables have been read, we can detect the compiler.
import subprocess
process = subprocess.Popen("%s %s" %(self.env['CC'], '--version'), stdout=subprocess.PIPE, shell=True) # nosec
(stdout, stderr) = process.communicate()
self.compiler_is_gcc = 'gcc' in stdout.lower()
self.compiler_is_clang = 'clang' in stdout.lower()

# Determine the major compiler version (only GCC)
if self.compiler_is_gcc:
self.gcc_major_version = None
process = subprocess.Popen("%s %s" %(self.env['CC'], '-dumpversion'), stdout=subprocess.PIPE, shell=True) # nosec
(stdout, stderr) = process.communicate()
gcc_version = stdout
# If match is None we don't know the version.
if not gcc_version is None:
version_split = gcc_version.split('.')
if version_split:
self.gcc_major_version = int(version_split[0])
if self.toolchain_is_msvs:
self.compiler_is_gcc = False
self.compiler_is_clang = False
else:
cc_version_cmd = shlex.split(self.env['CC']) + ['--version']
cc_version = subprocess.check_output(cc_version_cmd).decode('utf-8')
self.compiler_is_gcc = 'gcc' in cc_version.lower()
self.compiler_is_clang = 'clang' in cc_version.lower()

# Determine the major compiler version (only GCC)
if self.compiler_is_gcc:
self.gcc_major_version = None
gcc_version_cmd = shlex.split(self.env['CC']) + ['-dumpversion']
gcc_version = subprocess.check_output(gcc_version_cmd).decode('utf-8')
# If match is None we don't know the version.
if not gcc_version is None:
version_split = gcc_version.split('.')
if version_split:
self.gcc_major_version = int(version_split[0])

self.virtualize_build_dir()

Expand Down
7 changes: 2 additions & 5 deletions build/osx/otool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import os
import subprocess
import sys


#This page is REALLY USEFUL: http://www.cocoadev.com/index.pl?ApplicationLinking
#question: why do dylibs embed their install name in themselves? that would seem to imply the system keeps a cache of all the "install names", but that's not what the docs seem to say.
Expand Down Expand Up @@ -34,10 +35,6 @@
#Assumption: the loadlinks inside of an embeddable framework are all relative


import sys,os



def system(s):
"wrap system() to give us feedback on what it's doing"
"anything using this call should be fixed to use SCons's declarative style (once you figure that out, right nick?)"
Expand Down
2 changes: 1 addition & 1 deletion build/protoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import SCons.Node.FS
import SCons.Util

from SCons.Script import File, Dir
from SCons.Script import Dir

import os.path
protocs = 'protoc'
Expand Down
6 changes: 3 additions & 3 deletions build/qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import os.path
import re
import subprocess
import sys

import SCons.Action
Expand Down Expand Up @@ -543,16 +544,15 @@ def _find_qtdirs(qt5dir, module):
QT5INCDIR = os.path.join(qt5dir,"includedir")
if sys.platform.startswith('linux'):
if any(os.access(os.path.join(path, 'pkg-config'), os.X_OK) for path in os.environ["PATH"].split(os.pathsep)):
import subprocess
try:
if not module in ["Qt5DBus", "Qt5Assistant"]:
module5 = module.replace('Qt','Qt5')
else:
module5 = module
if not os.path.isdir(QT5LIBDIR):
QT5LIBDIR = subprocess.Popen(["pkg-config", "--variable=libdir", module5], stdout = subprocess.PIPE).communicate()[0].rstrip().decode()
QT5LIBDIR = subprocess.Popen(["pkg-config", "--variable=libdir", module5], stdout = subprocess.PIPE).communicate()[0].rstrip().decode('utf-8')
if not os.path.isdir(QT5INCDIR):
QT5INCDIR = subprocess.Popen(["pkg-config", "--variable=includedir", module5], stdout = subprocess.PIPE).communicate()[0].rstrip().decode()
QT5INCDIR = subprocess.Popen(["pkg-config", "--variable=includedir", module5], stdout = subprocess.PIPE).communicate()[0].rstrip().decode('utf-8')
finally:
pass
return QT5LIBDIR, QT5INCDIR, os.path.join(QT5INCDIR,module)
Expand Down
2 changes: 0 additions & 2 deletions build/windows/signtool.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python

import os
import SCons
from SCons.Builder import Builder
from SCons.Script import *

def signtool_path(subject_name, path):
print("Running signtool: ", path)
Expand Down