Fix support for Windows (MinGW) native builds using MSYS.

Fix paths that need to be coverted to host format.

The shell expansion needs to invoke a shell on Windows as cmd.exe
will not work.

Munch the paths into smaller sizes for Windows due to the limited
path size.
This commit is contained in:
Chris Johns 2013-05-13 14:44:49 +10:00
parent e2266055bc
commit 5237f1ccb7
7 changed files with 51 additions and 12 deletions

View File

@ -43,12 +43,16 @@ _bset: none, none, ''
name: none, none, '' name: none, none, ''
version: none, none, '' version: none, none, ''
release: none, none, '' release: none, none, ''
buildname: none, none, '%{name}'
# GNU triples needed to build packages # GNU triples needed to build packages
_host: triplet, required, '' _host: triplet, required, ''
_build: triplet, required, '%{_host}' _build: triplet, required, '%{_host}'
_target: none, optional, '' _target: none, optional, ''
# The user
_uid: none, convert, '%(%{__id_u} -n)'
# Paths # Paths
_host_platform: none, none, '%{_host_cpu}-%{_host_vendor}-%{_host_os}%{?_gnu}' _host_platform: none, none, '%{_host_cpu}-%{_host_vendor}-%{_host_os}%{?_gnu}'
_arch: none, none, '%{_host_arch}' _arch: none, none, '%{_host_arch}'
@ -57,14 +61,14 @@ _configdir: dir, optional, '%{_topdir}/config:%{_sbdir}/config'
_tardir: dir, optional, '%{_topdir}/tar' _tardir: dir, optional, '%{_topdir}/tar'
_sourcedir: dir, optional, '%{_topdir}/sources' _sourcedir: dir, optional, '%{_topdir}/sources'
_patchdir: dir, optional, '%{_topdir}/patches:%{_sbdir}/patches' _patchdir: dir, optional, '%{_topdir}/patches:%{_sbdir}/patches'
_builddir: dir, optional, '%{_topdir}/build/%{name}-%{version}-%{release}' _builddir: dir, optional, '%{_topdir}/build/%{buildname}'
_buildcxcdir: dir, optional, '%{_topdir}/build/%{name}-%{version}-%{release}-cxc' _buildcxcdir: dir, optional, '%{_topdir}/build/%{buildname}-cxc'
_docdir: dir, none, '%{_defaultdocdir}' _docdir: dir, none, '%{_defaultdocdir}'
_tmppath: dir, none, '%{_topdir}/build/tmp' _tmppath: dir, none, '%{_topdir}/build/tmp'
_tmproot: dir, none, '%{_tmppath}/source-build-%(%{__id_u} -n)/%{_bset}' _tmproot: dir, none, '%{_tmppath}/sb-%{_uid}/%{_bset}'
_tmpcxcroot: dir, none, '%{_tmppath}/source-build-%(%{__id_u} -n)-cxc/%{_bset}' _tmpcxcroot: dir, none, '%{_tmppath}/sb-%{_uid}-cxc/%{_bset}'
buildroot: dir, none, '%{_tmppath}/%{name}-root-%(%{__id_u} -n)' buildroot: dir, none, '%{_tmppath}/%{buildname}-%{_uid}'
buildcxcroot: dir, none, '%{_tmppath}/%{name}-root-%(%{__id_u} -n)-cxc' buildcxcroot: dir, none, '%{_tmppath}/%{buildname}-%{_uid}-cxc'
_datadir: dir, none, '%{_prefix}/share' _datadir: dir, none, '%{_prefix}/share'
_defaultdocdir: dir, none, '%{_prefix}/share/doc' _defaultdocdir: dir, none, '%{_prefix}/share/doc'
_exeext: none, none, '' _exeext: none, none, ''
@ -175,6 +179,7 @@ SB_DOC_DIR="%{_docdir}"
export SB_DOC_DIR export SB_DOC_DIR
# Packages # Packages
SB_PACKAGE_NAME="%{name}" SB_PACKAGE_NAME="%{name}"
SB_PACKAGE_BUILDNAME="%{buildname}"
SB_PACKAGE_VERSION="%{version}" SB_PACKAGE_VERSION="%{version}"
SB_PACKAGE_RELEASE="%{release}" SB_PACKAGE_RELEASE="%{release}"
export SB_PACKAGE_NAME SB_PACKAGE_VERSION SB_PACKAGE_RELEASE export SB_PACKAGE_NAME SB_PACKAGE_VERSION SB_PACKAGE_RELEASE

View File

@ -90,6 +90,23 @@ class script:
class build: class build:
"""Build a package given a config file.""" """Build a package given a config file."""
def _name_(self, name):
#
# If on Windows use shorter names to keep the build paths.
#
if options.host_windows:
buildname = ''
add = True
for c in name:
if c == '-':
add = True
elif add:
buildname += c
add = False
return buildname
else:
return name
def __init__(self, name, create_tar_files, opts, macros = None): def __init__(self, name, create_tar_files, opts, macros = None):
self.opts = opts self.opts = opts
if macros is None: if macros is None:
@ -100,6 +117,7 @@ class build:
log.notice('config: ' + name) log.notice('config: ' + name)
self.config = config.file(name, opts, self.macros) self.config = config.file(name, opts, self.macros)
self.script = script() self.script = script()
self.macros['buildname'] = self._name_(self.macros['name'])
def rmdir(self, rmpath): def rmdir(self, rmpath):
log.output('removing: %s' % (path.host(rmpath))) log.output('removing: %s' % (path.host(rmpath)))
@ -214,6 +232,7 @@ class build:
name = source['name'] name = source['name']
else: else:
raise error.general('setup source tag not found: %d' % (source_tag)) raise error.general('setup source tag not found: %d' % (source_tag))
name = self._name_(name)
self.script.append(self.config.expand('cd %{_builddir}')) self.script.append(self.config.expand('cd %{_builddir}'))
if delete_before_unpack: if delete_before_unpack:
self.script.append(self.config.expand('%{__rm} -rf ' + name)) self.script.append(self.config.expand('%{__rm} -rf ' + name))

View File

@ -353,7 +353,11 @@ class file:
if len(sl): if len(sl):
e = execute.capture_execution() e = execute.capture_execution()
for s in sl: for s in sl:
exit_code, proc, output = e.shell(s[2:-1]) if options.host_windows:
cmd = '%s -c "%s"' % (self.macros.expand('%{__sh}'), s[2:-1])
else:
cmd = s[2:-1]
exit_code, proc, output = e.shell(cmd)
if exit_code == 0: if exit_code == 0:
line = line.replace(s, output) line = line.replace(s, output)
else: else:

View File

@ -68,7 +68,7 @@ class repo:
raise error.general('cvs path needs to exist: %s' % (cwd)) raise error.general('cvs path needs to exist: %s' % (cwd))
cmd = [self.cvs, '-z', '9', '-q'] + args cmd = [self.cvs, '-z', '9', '-q'] + args
log.output('cmd: (%s) %s' % (str(cwd), ' '.join(cmd))) log.output('cmd: (%s) %s' % (str(cwd), ' '.join(cmd)))
exit_code, proc, output = e.spawn(cmd, cwd = cwd) exit_code, proc, output = e.spawn(cmd, cwd = path.host(cwd))
log.trace(output) log.trace(output)
if check: if check:
self._cvs_exit_code(cmd, exit_code, output) self._cvs_exit_code(cmd, exit_code, output)

View File

@ -44,7 +44,7 @@ class repo:
cwd = None cwd = None
cmd = [self.git] + args cmd = [self.git] + args
log.trace('cmd: (%s) %s' % (str(cwd), ' '.join(cmd))) log.trace('cmd: (%s) %s' % (str(cwd), ' '.join(cmd)))
exit_code, proc, output = e.spawn(cmd, cwd = cwd) exit_code, proc, output = e.spawn(cmd, cwd = path.host(cwd))
log.trace(output) log.trace(output)
if check: if check:
self._git_exit_code(exit_code) self._git_exit_code(exit_code)
@ -69,8 +69,8 @@ class repo:
raise error.general('invalid version number from git: %s' % (gvs[2])) raise error.general('invalid version number from git: %s' % (gvs[2]))
return (int(vs[0]), int(vs[1]), int(vs[2]), int(vs[3])) return (int(vs[0]), int(vs[1]), int(vs[2]), int(vs[3]))
def clone(self, url, path): def clone(self, url, _path):
ec, output = self._run(['clone', url, path], check = True) ec, output = self._run(['clone', url, path.host(_path)], check = True)
def fetch(self): def fetch(self):
ec, output = self._run(['fetch'], check = True) ec, output = self._run(['fetch'], check = True)

View File

@ -145,8 +145,11 @@ class macros:
raise TypeError('bad value tuple value field: %s' % (type(value[2]))) raise TypeError('bad value tuple value field: %s' % (type(value[2])))
if value[0] not in ['none', 'triplet', 'dir', 'file', 'exe']: if value[0] not in ['none', 'triplet', 'dir', 'file', 'exe']:
raise TypeError('bad value tuple (type field): %s' % (value[0])) raise TypeError('bad value tuple (type field): %s' % (value[0]))
if value[1] not in ['none', 'optional', 'required', 'override', 'undefine']: if value[1] not in ['none', 'optional', 'required',
'override', 'undefine', 'convert']:
raise TypeError('bad value tuple (attrib field): %s' % (value[1])) raise TypeError('bad value tuple (attrib field): %s' % (value[1]))
if value[1] == 'convert':
value = self.expand(value)
self.macros[self.write_map][self.key_filter(key)] = value self.macros[self.write_map][self.key_filter(key)] = value
def __delitem__(self, key): def __delitem__(self, key):

View File

@ -37,6 +37,11 @@ import sys
basepath = 'sb' basepath = 'sb'
#
# Save the host state.
#
host_windows = False
class command_line: class command_line:
"""Process the command line in a common way for all Tool Builder commands.""" """Process the command line in a common way for all Tool Builder commands."""
@ -460,6 +465,8 @@ def load(args, optargs = None, defaults = '%{_sbdir}/defaults.mc'):
command line. command line.
""" """
global host_windows
# #
# The path to this command. # The path to this command.
# #
@ -482,6 +489,7 @@ def load(args, optargs = None, defaults = '%{_sbdir}/defaults.mc'):
try: try:
import windows import windows
overrides = windows.load() overrides = windows.load()
host_windows = True
except: except:
raise error.general('failed to load Windows host support') raise error.general('failed to load Windows host support')
elif os.name == 'posix': elif os.name == 'posix':