From e87835c61d3f02af9569282125e0c7742cd24791 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 19 Jun 2018 10:55:00 +0200 Subject: [PATCH] Correctly set the environment. When running command without `shell=True`, python's subproccess will look for variable `"PATH"` and `b"PATH"` and will complain if both are set. So the defaultdict should not return something for `b"PATH"`. We also escape space ` ` in the environment variables to not break everything with directory containing space. --- kiwixbuild/buildenv.py | 33 ++++++++++++++++++++--------- kiwixbuild/dependencies/base.py | 2 +- kiwixbuild/dependencies/libmagic.py | 2 +- kiwixbuild/utils.py | 19 ++++++++++++++--- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/kiwixbuild/buildenv.py b/kiwixbuild/buildenv.py index 97719cf..2652b41 100644 --- a/kiwixbuild/buildenv.py +++ b/kiwixbuild/buildenv.py @@ -4,7 +4,7 @@ import subprocess import platform import distro -from .utils import pj, download_remote, Defaultdict +from .utils import pj, download_remote, escape_path from ._global import neutralEnv, option @@ -125,21 +125,34 @@ class BuildEnv: pkgconfig_path = pj(self.install_dir, self.libprefix, 'pkgconfig') env['PKG_CONFIG_PATH'] = ':'.join([env['PKG_CONFIG_PATH'], pkgconfig_path]) - env['PATH'] = ':'.join([pj(self.install_dir, 'bin'), env['PATH']]) + env['PATH'] = ':'.join([ + escape_path(pj(self.install_dir, 'bin')), + env['PATH'] + ]) env['LD_LIBRARY_PATH'] = ':'.join([env['LD_LIBRARY_PATH'], pj(self.install_dir, 'lib'), pj(self.install_dir, self.libprefix) ]) - env['QMAKE_CXXFLAGS'] = " ".join(['-I'+pj(self.install_dir, 'include'), env['QMAKE_CXXFLAGS']]) - env['CPPFLAGS'] = " ".join(['-I'+pj(self.install_dir, 'include'), env['CPPFLAGS']]) - env['QMAKE_LFLAGS'] = " ".join(['-L'+pj(self.install_dir, 'lib'), - '-L'+pj(self.install_dir, self.libprefix), - env['QMAKE_LFLAGS']]) - env['LDFLAGS'] = " ".join(['-L'+pj(self.install_dir, 'lib'), - '-L'+pj(self.install_dir, self.libprefix), - env['LDFLAGS']]) + env['QMAKE_CXXFLAGS'] = " ".join([ + escape_path('-I'+pj(self.install_dir, 'include')), + env['QMAKE_CXXFLAGS'] + ]) + env['CPPFLAGS'] = " ".join([ + escape_path('-I'+pj(self.install_dir, 'include')), + env['CPPFLAGS'] + ]) + env['QMAKE_LFLAGS'] = " ".join([ + escape_path('-L'+pj(self.install_dir, 'lib')), + escape_path('-L'+pj(self.install_dir, self.libprefix)), + env['QMAKE_LFLAGS'] + ]) + env['LDFLAGS'] = " ".join([ + escape_path('-L'+pj(self.install_dir, 'lib')), + escape_path('-L'+pj(self.install_dir, self.libprefix)), + env['LDFLAGS'] + ]) if cross_comp_flags: self.platformInfo.set_comp_flags(env) diff --git a/kiwixbuild/dependencies/base.py b/kiwixbuild/dependencies/base.py index d57102c..49c4176 100644 --- a/kiwixbuild/dependencies/base.py +++ b/kiwixbuild/dependencies/base.py @@ -3,7 +3,7 @@ import os import shutil import time -from kiwixbuild.utils import pj, Context, SkipCommand, WarningMessage, extract_archive, Defaultdict, StopBuild, run_command, colorize, copy_tree +from kiwixbuild.utils import pj, Context, SkipCommand, WarningMessage, extract_archive, StopBuild, run_command, colorize, copy_tree from kiwixbuild.versions import main_project_versions, base_deps_versions from kiwixbuild._global import neutralEnv, option, get_target_step diff --git a/kiwixbuild/dependencies/libmagic.py b/kiwixbuild/dependencies/libmagic.py index 53f3302..01c72ec 100644 --- a/kiwixbuild/dependencies/libmagic.py +++ b/kiwixbuild/dependencies/libmagic.py @@ -6,7 +6,7 @@ from .base import ( MakeBuilder, ) -from kiwixbuild.utils import Remotefile, pj, Defaultdict, SkipCommand, run_command +from kiwixbuild.utils import Remotefile, pj, SkipCommand, run_command from kiwixbuild._global import get_target_step class LibMagic(Dependency): diff --git a/kiwixbuild/utils.py b/kiwixbuild/utils.py index c0c0b4a..d9feefd 100644 --- a/kiwixbuild/utils.py +++ b/kiwixbuild/utils.py @@ -8,6 +8,7 @@ import urllib.request import urllib.error import ssl import subprocess +import re from collections import namedtuple, defaultdict from kiwixbuild._global import neutralEnv, option @@ -39,13 +40,25 @@ def xrun_find(name): return output[:-1].decode() +regex_space = re.compile(r'((?