Commit fbaf3bc4 authored by Nirbheek Chauhan's avatar Nirbheek Chauhan 🐜
Browse files

cerbero/build: Workaround MSYS trying to be too smart

Finally figured out the actual issue that I was trying to solve in
f38df32d and 78f06dd4. Paths like `c:/foobar` (lowercase drive
letter) are considered to be a POSIX path list, so `c:/foobar/`
becomes `c;C:\foobar`:

http://mingw.org/wiki/Posix_path_conversion

This will happen anytime we try to pass a path as a command-line
argument. We used to work-around this by using `to_unixpath()`,
but that's just sinking deeper into dependence on broken shell
behaviour. This happens now because we're passing includes in CFLAGS,
CXXFLAGS, CPPFLAGS, etc.

So let's just bypass the shell entirely by constructing a list. As
a side-effect, this is another step towards being able to run Cerbero
from a directory with spaces in it.

For now, we'll convert `config_sh` to a list when not using an
Autotools configure. Luckily, we don't need to pass any paths as
arguments to it anyway. When running other stages, we now always use
a list instead of a string. Hopefully the fallout is small and obvious
for people using forks of Cerbero.
parent 151e8c47
......@@ -364,13 +364,15 @@ class MakefilesBase (Build, ModifyEnvBase):
config_sh = ''
configure_tpl = ''
configure_options = ''
make = 'make V=1'
make_install = 'make install'
make = None
make_install = None
make_check = None
make_clean = 'make clean'
make_clean = None
allow_parallel_build = True
srcdir = '.'
requires_non_src_build = False
# recipes often use shell constructs
config_sh_needs_shell = True
def __init__(self):
Build.__init__(self)
......@@ -384,9 +386,14 @@ class MakefilesBase (Build, ModifyEnvBase):
self.make_dir = os.path.join (self.config_src_dir, "cerbero-build-dir")
else:
self.make_dir = self.config_src_dir
self.make = self.make or ['make', 'V=1']
self.make_install = self.make_install or ['make', 'install']
self.make_clean = self.make_clean or ['make', 'clean']
if self.config.allow_parallel_build and self.allow_parallel_build \
and self.config.num_of_cpus > 1:
self.make += ' -j%d' % self.config.num_of_cpus
self.make += ['-j%d' % self.config.num_of_cpus]
# Make sure user's env doesn't mess up with our build.
self.set_env('MAKEFLAGS', when='now')
......@@ -423,16 +430,31 @@ class MakefilesBase (Build, ModifyEnvBase):
if self.using_msvc():
self.unset_toolchain_env()
configure_cmd = self.configure_tpl % {
substs = {
'config-sh': self.config_sh,
'prefix': to_unixpath(self.config.prefix),
'libdir': to_unixpath(self.config.libdir),
'prefix': self.config.prefix,
'libdir': self.config.libdir,
'host': self.config.host,
'target': self.config.target,
'build': self.config.build,
'options': self.configure_options,
'build_dir': to_unixpath(self.build_dir),
'make_dir': to_unixpath(self.make_dir)}
'build_dir': self.build_dir,
'make_dir': self.make_dir,
}
# Construct a command list when possible
if not self.config_sh_needs_shell:
configure_cmd = []
for arg in self.configure_tpl.split():
if arg == '%(options)s':
options = self.configure_options
if isinstance(options, str):
options = options.split()
configure_cmd += options
else:
configure_cmd.append(arg % substs)
else:
configure_cmd = self.configure_tpl % substs
self.maybe_add_system_libs(step='configure')
......@@ -486,13 +508,16 @@ class Autotools (MakefilesBase):
config_sh = './configure'
configure_tpl = "%(config-sh)s --prefix %(prefix)s "\
"--libdir %(libdir)s"
make_check = 'make check'
add_host_build_target = True
can_use_configure_cache = True
supports_cache_variables = True
disable_introspection = False
override_libtool = True
def __init__(self):
MakefilesBase.__init__(self)
self.make_check = self.make_check or ['make', 'check']
@async_modify_environment
async def configure(self):
# Build with PIC for static linking
......@@ -570,6 +595,7 @@ class CMake (MakefilesBase):
Build handler for cmake projects
'''
config_sh_needs_shell = False
config_sh = 'cmake'
configure_tpl = '%(config-sh)s -DCMAKE_INSTALL_PREFIX=%(prefix)s ' \
'-H%(build_dir)s ' \
......@@ -599,24 +625,29 @@ class CMake (MakefilesBase):
cc = cc.split(' ')[0]
cxx = cxx.split(' ')[0]
if self.configure_options:
self.configure_options = self.configure_options.split()
if self.config.target_platform == Platform.WINDOWS:
self.configure_options += ' -DCMAKE_SYSTEM_NAME=Windows '
self.configure_options += ['-DCMAKE_SYSTEM_NAME=Windows']
elif self.config.target_platform == Platform.ANDROID:
self.configure_options += ' -DCMAKE_SYSTEM_NAME=Linux '
self.configure_options += ['-DCMAKE_SYSTEM_NAME=Linux']
if self.config.platform == Platform.WINDOWS:
self.configure_options += ' -G"Unix Makefiles"'
self.configure_options += ['-G', 'Unix Makefiles']
# FIXME: Maybe export the sysroot properly instead of doing regexp magic
if self.config.target_platform in [Platform.DARWIN, Platform.IOS]:
r = re.compile(r".*-isysroot ([^ ]+) .*")
sysroot = r.match(cflags).group(1)
self.configure_options += ' -DCMAKE_OSX_SYSROOT=%s' % sysroot
self.configure_options += ['-DCMAKE_OSX_SYSROOT=' + sysroot]
self.configure_options += ' -DCMAKE_C_COMPILER=%s ' % cc
self.configure_options += ' -DCMAKE_CXX_COMPILER=%s ' % cxx
self.configure_options += ' -DCMAKE_C_FLAGS="%s"' % cflags
self.configure_options += ' -DCMAKE_CXX_FLAGS="%s"' % cxxflags
self.configure_options += ' -DLIB_SUFFIX=%s ' % self.config.lib_suffix
self.configure_options += [
'-DCMAKE_C_COMPILER=' + cc,
'-DCMAKE_CXX_COMPILER=' + cxx,
'-DCMAKE_C_FLAGS=' + cflags,
'-DCMAKE_CXX_FLAGS=' + cxxflags,
'-DLIB_SUFFIX=' + self.config.lib_suffix,
]
cmake_cache = os.path.join(self.make_dir, 'CMakeCache.txt')
cmake_files = os.path.join(self.make_dir, 'CMakeFiles')
......@@ -624,7 +655,7 @@ class CMake (MakefilesBase):
os.remove(cmake_cache)
if os.path.exists(cmake_files):
shutil.rmtree(cmake_files)
self.make += ' VERBOSE=1 '
self.make += ['VERBOSE=1']
await MakefilesBase.configure(self)
......@@ -662,6 +693,7 @@ class Meson (Build, ModifyEnvBase) :
make_install = None
make_check = None
make_clean = None
meson_sh = None
meson_options = None
meson_cross_properties = None
......@@ -690,13 +722,13 @@ class Meson (Build, ModifyEnvBase) :
# Find ninja
if not self.make:
self.make = 'ninja -v -d keeprsp'
self.make = ['ninja', '-v', '-d', 'keeprsp']
if not self.make_install:
self.make_install = self.make + ' install'
self.make_install = self.make + ['install']
if not self.make_check:
self.make_check = self.make + ' test'
self.make_check = self.make + ['test']
if not self.make_clean:
self.make_clean = self.make + ' clean'
self.make_clean = self.make + ['clean']
@staticmethod
def _get_option_value(opt_type, value):
......
......@@ -22,7 +22,7 @@ class Recipe(recipe.Recipe):
sysroot = os.path.join(self.config.prefix, self.host, 'sysroot')
self.configure_options += ' --host=%s' % self.host
self.configure_options += ' --with-sysroot=%s ' % sysroot
self.make_install = 'make install DESTDIR=%s' % sysroot
self.make_install = ['make', 'install', 'DESTDIR=' + sysroot]
self.build_dir = os.path.join(self.config.sources,
'mingw-w64-%s' % self.version)
self.make_dir = os.path.join(self.build_dir, 'mingw-w64-crt')
......
......@@ -16,7 +16,7 @@ class Recipe(recipe.Recipe):
self._sysroot = os.path.join(self.config.prefix, self.host, 'sysroot')
self.configure_options += ' --host=%s' % self.host
self.configure_options += ' --with-sysroot=%s ' % self._sysroot
self.make_install = 'make install DESTDIR=%s' % self._sysroot
self.make_install = ['make', 'install', 'DESTDIR=' + self._sysroot]
self.build_dir = os.path.join(self.config.sources,
'mingw-w64-%s' % self.version)
self.make_dir = os.path.join(self.build_dir, 'mingw-w64-headers')
......
......@@ -39,7 +39,7 @@ class Recipe(recipe.Recipe):
self.host = 'x86_64-w64-mingw32'
self.sysroot = os.path.join(self.config.prefix, self.host, 'sysroot')
self.configure_options += ' --with-sysroot=%s ' % self.sysroot
self.make_install = 'make install DESTDIR=%s' % self.sysroot
self.make_install = ['make', 'install', 'DESTDIR=' + self.sysroot]
self.build_dir = os.path.join(self.config.sources,
'mingw-w64-%s' % self.version)
self.make_dir = os.path.join(self.config.sources,
......@@ -62,7 +62,7 @@ class Recipe(recipe.Recipe):
"RCFLAGS='-F pe-i386' DLLTOOLFLAGS='-m i386'"
host = 'i386-w64-mingw32'
libdir = "/usr/%s/lib32" % self.host
shell.call('%s ../configure --bindir=%s --libdir=%s --prefix=/usr/%s --host=%s %s' %\
shell.new_call('%s ../configure --bindir=%s --libdir=%s --prefix=/usr/%s --host=%s %s' %\
(flags, libdir, libdir, host, host, self.configure_options),
self.build_dir_32)
......@@ -74,13 +74,13 @@ class Recipe(recipe.Recipe):
"LD=x86_64-w64-mingw32-ld LDFLAGS=' -m64' CFLAGS=' -m64' CXXFLAGS=' -m64' "
host = 'x86_64-w64-mingw32'
libdir = "/usr/%s/lib" % self.host
shell.call('%s ../configure --bindir=%s --libdir=%s --prefix=/usr/%s --host=%s %s' %\
shell.new_call('%s ../configure --bindir=%s --libdir=%s --prefix=/usr/%s --host=%s %s' %\
(flags, libdir, libdir, host, host, self.configure_options),
self.build_dir_64)
def compile(self):
shell.call(self.make, self.build_dir_32)
shell.call(self.make, self.build_dir_64)
shell.new_call(self.make, self.build_dir_32)
shell.new_call(self.make, self.build_dir_64)
@modify_environment
def install(self):
......@@ -88,11 +88,11 @@ class Recipe(recipe.Recipe):
(self.sysroot, self.host)
libdir = "%s/usr/%s/lib32/" % (self.sysroot, self.host)
dest_winpthread_dll = os.path.join(libdir, "libwinpthread-1.dll")
shell.call(self.make_install, self.build_dir_32)
shell.new_call(self.make_install, self.build_dir_32)
if os.path.exists(dest_winpthread_dll):
os.remove(dest_winpthread_dll)
shutil.move(src_winpthread_dll, dest_winpthread_dll)
shell.call(self.make_install, self.build_dir_64)
shell.new_call(self.make_install, self.build_dir_64)
libdir = "%s/usr/%s/lib/" % (self.sysroot, self.host)
dest_winpthread_dll = os.path.join(libdir, "libwinpthread-1.dll")
if os.path.exists(dest_winpthread_dll):
......
......@@ -96,7 +96,7 @@ class Recipe(recipe.Recipe):
# On Windows, make fails if V=1 is passed with:
# `couldn't commit memory for cygwin heap, Win32 error 0`
if self.config.platform == Platform.WINDOWS:
self.make = 'make '
self.make = ['make']
async def configure(self):
await super(recipe.Recipe, self).configure()
......
# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
import shlex
from cerbero.tools.libtool import LibtoolLibrary
......@@ -28,14 +27,14 @@ class Recipe(recipe.Recipe):
if self.config.target_platform in [Platform.LINUX, Platform.ANDROID]:
system = 'posix'
# LDFLAGS are passed via XLDFLAGS, and are needed for at least Android
cc = shlex.quote(self.get_env('CC'))
ld = shlex.quote(self.get_env('LD'))
prefix = shlex.quote(self.config.prefix)
cflags = shlex.quote(self.get_env('CFLAGS'))
ldflags = shlex.quote(self.get_env('LDFLAGS'))
self.make += ' SYS={} prefix={} CRYPTO=GNUTLS XCFLAGS={} XLDFLAGS={} CC={} LD={}' \
''.format(system, prefix, cflags, ldflags, cc, ld)
self.make_install = self.make + ' install'
cc = self.get_env('CC')
ld = self.get_env('LD')
prefix = self.config.prefix
cflags = self.get_env('CFLAGS')
ldflags = self.get_env('LDFLAGS')
self.make += ['SYS=' + system, 'prefix=' + prefix, 'CRYPTO=GNUTLS', 'XCFLAGS=' + cflags,
'XLDFLAGS=' + ldflags, 'CC=' + cc, 'LD=' + ld]
self.make_install = self.make + ['install']
def post_install(self):
soversion = 1
......
......@@ -8,6 +8,7 @@ class Recipe(recipe.Recipe):
name = 'libsrtp'
version = '2.2.0'
stype = SourceType.TARBALL
make = ['make', 'all', 'shared_library']
url = 'https://github.com/cisco/%(name)s/archive/v%(version)s.tar.gz'
tarball_checksum = '44fd7497bce78767e96b54a11bca520adb2ad32effd515f04bce602b60a1a50b'
licenses = [{License.BSD_like: ['LICENSE']}]
......@@ -19,7 +20,6 @@ class Recipe(recipe.Recipe):
def prepare(self):
# Don't accidentially build with pcap support
self.set_env('ac_cv_lib_pcap_pcap_create', 'no')
self.make += ' all shared_library'
async def install(self):
await super(Recipe, self).install()
......
......@@ -22,7 +22,7 @@ class Recipe(recipe.Recipe):
add_host_build_target = False
supports_cache_variables = False
can_use_configure_cache = False
make = 'make HAVE_GNU_STRIP=no'
make = ['make', 'HAVE_GNU_STRIP=no']
# The shell-based build system magically supports Visual Studio with the
# power of awesome hacks
can_msvc = True
......
......@@ -19,57 +19,56 @@ class Recipe(recipe.Recipe):
def prepare(self):
make = self.make
if self.config.target_platform == Platform.IOS:
make += ' OS=ios '
make += ['OS=ios']
if self.config.target_arch == Architecture.X86:
make += ' ARCH=i386'
make += ['ARCH=i386']
elif self.config.target_arch == Architecture.X86_64:
make += ' ARCH=x86_64'
make += ['ARCH=x86_64']
elif self.config.target_arch == Architecture.ARMv7:
make += ' ARCH=armv7'
make += ['ARCH=armv7']
elif self.config.target_arch == Architecture.ARMv7S:
make += ' ARCH=armv7s'
make += ['ARCH=armv7s']
elif self.config.target_arch == Architecture.ARM:
make += ' ARCH=arm APP_ABI=armeabi'
make += ['ARCH=arm', 'APP_ABI=armeabi']
elif self.config.target_arch == Architecture.ARM64:
make += ' ARCH=arm64'
make += ['ARCH=arm64']
elif self.config.target_platform == Platform.DARWIN:
make += ' OS=darwin '
make += ['OS=darwin']
if self.config.target_arch == Architecture.X86:
make += ' ARCH=x86'
make += ['ARCH=x86']
elif self.config.target_arch == Architecture.X86_64:
make += ' ARCH=x86_64'
make += ['ARCH=x86_64']
elif self.config.target_platform == Platform.ANDROID:
v = DistroVersion.get_android_api_version(self.config.target_distro_version)
make += ' OS=android TARGET=android-' + str(v) + ' NDKLEVEL=' + str(v)
make += ' NDKROOT=' + self.config.toolchain_prefix
make += ['OS=android', 'TARGET=android-' + str(v), 'NDKLEVEL=' + str(v)]
make += ['NDKROOT=' + self.config.toolchain_prefix]
if self.config.target_arch == Architecture.X86:
make += ' ARCH=x86'
# According to https://github.com/cisco/openh264/issues/2263
# to fix text relocations
make += ' ENABLEPIC=Yes'
# need to pass ENABLEPIC=Yes to fix text relocations
make += ['ARCH=x86', 'ENABLEPIC=Yes']
elif self.config.target_arch == Architecture.ARM64:
make += ' ARCH=arm64'
make += ['ARCH=arm64']
elif self.config.target_arch == Architecture.X86_64:
make += ' ARCH=x86_64'
make += ['ARCH=x86_64']
elif self.config.target_platform == Platform.WINDOWS:
make += ' OS=mingw_nt'
make += ['OS=mingw_nt']
if self.config.target_arch == Architecture.X86:
make += ' ARCH=x86'
make += ['ARCH=x86']
elif self.config.target_arch == Architecture.X86_64:
make += ' ARCH=x86_64'
make += ['ARCH=x86_64']
elif self.config.target_platform == Platform.LINUX:
if self.config.target_arch == Architecture.ARMv7:
make += ' ARCH=armv7'
make += ['ARCH=armv7']
elif self.config.target_arch == Architecture.ARMv7S:
make += ' ARCH=armv7s'
make += ['ARCH=armv7s']
elif self.config.target_arch == Architecture.ARM:
make += ' ARCH=arm APP_ABI=armeabi'
make += ['ARCH=arm', 'APP_ABI=armeabi']
elif self.config.target_arch == Architecture.ARM64:
make += ' ARCH=arm64'
make += ['ARCH=arm64']
self.make = make + ' libraries'
self.make = make + ['libraries']
# `make install` also needs the exact same parameters as `make`
self.make_install = make + ' install'
self.make_install = make + ['install']
def configure(self):
if self.config.platform == Platform.WINDOWS:
......
# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
import shlex
from cerbero.build.build import async_modify_environment
from cerbero.tools.libtool import LibtoolLibrary
from cerbero.utils import shell, messages
......@@ -17,6 +16,8 @@ class Recipe(recipe.Recipe):
deps = ['zlib']
# Parallel make fails randomly due to undefined macros, probably races
allow_parallel_build = False
# Configure script is perl, not shell
config_sh_needs_shell = False
files_bins = ['openssl']
files_libs = ['libcrypto', 'libssl']
......@@ -52,7 +53,7 @@ class Recipe(recipe.Recipe):
else:
raise NotImplementedError
self.make += ' CROSS_SYSROOT="{0}"'.format(self.config.sysroot)
self.make += ['CROSS_SYSROOT=' + self.config.sysroot]
elif self.config.target_platform == Platform.DARWIN:
if self.config.target_arch == Architecture.X86:
self.openssl_platform = 'darwin-i386-cc'
......@@ -80,33 +81,31 @@ class Recipe(recipe.Recipe):
self.openssl_platform = 'mingw64'
else:
raise NotImplementedError
cflags = shlex.quote(self.get_env('CFLAGS') + '-fPIC -DOPENSSL_PIC')
ldflags = shlex.quote(self.get_env('LDFLAGS') + '-fPIC')
ranlib = shlex.quote(self.get_env('RANLIB'))
ar = shlex.quote(self.get_env('AR'))
cflags = self.get_env('CFLAGS') + '-fPIC -DOPENSSL_PIC'
ldflags = self.get_env('LDFLAGS') + '-fPIC'
ranlib = self.get_env('RANLIB')
ar = self.get_env('AR')
# Need to add CFLAGS to CC because CFLAG is not used everywhere in the
# build, and we can't pass arguments via Configure because on Darwin,
# Configure reads the `-arch x86_64` as meaning that you want to use
# `x86_64` as the platform, and errors out about a redefined platform.
cc = shlex.quote(self.get_env('CC') + ' ' + self.get_env('CFLAGS'))
ld = shlex.quote(self.get_env('LD') + ' ' + self.get_env('LDFLAGS'))
cc = self.get_env('CC') + ' ' + self.get_env('CFLAGS')
ld = self.get_env('LD') + ' ' + self.get_env('LDFLAGS')
# NOTE: CFLAG and LDFLAG are not typos!
self.make += ' AR={} RANLIB={} CC={} LD={} CFLAG={} LDFLAG={}' \
''.format(ar, ranlib, cc, ld, cflags, ldflags)
self.make_install = 'make install_sw RANLIB={}'.format(ranlib)
self.make += ['AR=' + ar, 'RANLIB=' + ranlib, 'CC=' + cc, 'LD=' + ld,
'CFLAG=' + cflags, 'LDFLAG=' + ldflags]
self.make_install = ['make', 'install_sw', 'RANLIB=' + ranlib]
# We probably don't need and can't use the tools on these platforms
if self.config.target_platform in (Platform.IOS, Platform.ANDROID):
self.make += ' build_libs openssl.pc libssl.pc libcrypto.pc'
self.make_install = 'make install_dev RANLIB={}'.format(ranlib)
self.make += ['build_libs', 'openssl.pc', 'libssl.pc', 'libcrypto.pc']
self.make_install = ['make', 'install_dev', 'RANLIB=' + ranlib]
if self.config.platform == Platform.WINDOWS:
# Msys ships with a too-old perl, so we modify PATH to use the
# mingw-perl that was downloaded and installed by bootstrap.
openssl_path = os.path.join(self.config.mingw_perl_prefix, 'bin')
self.prepend_env('PATH', openssl_path, sep=';')
self.make = self.make.replace('"', '\\"')
self.make_install = self.make_install.replace('"', '\\"')
@async_modify_environment
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment