Clean all paths to make them work on Windows.

This commit is contained in:
Chris Johns
2012-10-31 20:47:57 +11:00
parent ba8a935b28
commit ab8319af6d
6 changed files with 261 additions and 165 deletions

View File

@@ -30,9 +30,10 @@ import build
import defaults
import error
import log
import path
#
# Version of Tools Builder CrossGCC Builder.
# Version of Source Builder Set Builder.
#
version = '0.1'
@@ -46,33 +47,31 @@ def _notice(opts, text):
log.output(text)
log.flush()
class crossgcc:
"""Build a Cross GCC Compiler tool suite."""
class buildset:
"""Build a set builds a set of packages."""
_order = { 'binutils': 0,
'gcc' : 1,
'gdb' : 2 }
def __init__(self, toolset, _defaults, opts):
_trace(opts, '_cgcc:%s: init' % (toolset))
def __init__(self, bset, _defaults, opts):
_trace(opts, '_bset:%s: init' % (bset))
self.opts = opts
self.defaults = _defaults
self.toolset = toolset
self.toolset_pkg = '%s-%s-tools' % (self.opts.expand('%{_target}', _defaults),
self.toolset)
self.bset = bset
self.bset_pkg = '%s-%s-set' % (self.opts.expand('%{_target}', _defaults),
self.bset)
def _output(self, text):
if not self.opts.quiet():
log.output(text)
def copy(self, src, dst):
if os.path.isdir(src):
if os.path.isdir(path.host(src)):
topdir = self.opts.expand('%{_topdir}', self.defaults)
what = '%s -> %s' % (src[len(topdir) + 1:], dst[len(topdir) + 1:])
what = '%s -> %s' % \
(path.host(src[len(topdir) + 1:]), path.host(dst[len(topdir) + 1:]))
_notice(self.opts, 'installing: %s' % (what))
if not self.opts.dry_run():
try:
files = distutils.dir_util.copy_tree(src, dst)
files = distutils.dir_util.copy_tree(path.host(src),
path.host(dst))
for f in files:
self._output(f)
except IOError, err:
@@ -81,34 +80,33 @@ class crossgcc:
raise error.general('installing tree: %s' % (str(err)))
def first_package(self, _build):
tmproot = os.path.abspath(_build.config.expand('%{_tmproot}'))
tmproot = path.abspath(_build.config.expand('%{_tmproot}'))
_build.rmdir(tmproot)
_build.mkdir(tmproot)
prefix = _build.config.expand('%{_prefix}')
if prefix[0] == os.sep:
prefix = prefix[1:]
tmpprefix = os.path.join(tmproot, prefix)
tmpbindir = os.path.join(tmpprefix, 'bin')
os.environ['SB_TMPPREFIX'] = tmpprefix
os.environ['SB_TMPBINDIR'] = tmpbindir
os.environ['PATH'] = tmpbindir + os.pathsep + os.environ['PATH']
tmpprefix = path.join(tmproot, prefix)
tmpbindir = path.join(tmpprefix, 'bin')
# exporting to the environment
os.environ['SB_TMPPREFIX'] = path.host(tmpprefix)
os.environ['SB_TMPBINDIR'] = path.host(tmpbindir)
os.environ['PATH'] = path.host(tmpbindir) + os.pathsep + os.environ['PATH']
self._output('path: ' + os.environ['PATH'])
# shell format
return tmproot
def every_package(self, _build, path):
self.copy(_build.config.abspath('%{buildroot}'), path)
def every_package(self, _build, tmproot):
self.copy(_build.config.abspath('%{buildroot}'), tmproot)
def last_package(self, _build, path):
tar = os.path.join(_build.config.expand('%{_tardir}'),
_build.config.expand('%s.tar.bz2' % (self.toolset_pkg)))
_notice(self.opts, 'tarball: %s' % (tar))
def last_package(self, _build, tmproot):
tar = path.join(_build.config.expand('%{_tardir}'),
_build.config.expand('%s.tar.bz2' % (self.bset_pkg)))
_notice(self.opts, 'tarball: %s' % path.host(tar))
if not self.opts.dry_run():
cmd = _build.config.expand("'cd " + path + \
cmd = _build.config.expand("'cd " + tmproot + \
" && %{__tar} -cf - . | %{__bzip2} > " + tar + "'")
_build.run(cmd, shell_opts = '-c', cwd = path)
#if not self.opts.no_clean():
# _build.rmdir(path)
_build.run(cmd, shell_opts = '-c', cwd = tmproot)
def load(self):
@@ -119,40 +117,40 @@ class crossgcc:
line = line[1:b]
return line.strip()
extoolset = self.opts.expand(self.toolset, self.defaults)
exbset = self.opts.expand(self.bset, self.defaults)
self.defaults['_toolset'] = extoolset
self.defaults['_bset'] = exbset
root, ext = os.path.splitext(extoolset)
root, ext = path.splitext(exbset)
if extoolset.endswith('.cfg'):
toolsetcfg = extoolset
if exbset.endswith('.cfg'):
bsetcfg = exbset
else:
toolsetcfg = '%s.cfg' % (extoolset)
bsetcfg = '%s.cfg' % (exbset)
toolsetname = toolsetcfg
bsetname = bsetcfg
if not os.path.exists(toolsetname):
if not path.exists(bsetname):
for cp in self.opts.expand('%{_configdir}', self.defaults).split(':'):
configdir = os.path.abspath(cp)
toolsetname = os.path.join(configdir, toolsetcfg)
if os.path.exists(toolsetname):
configdir = path.abspath(cp)
bsetname = path.join(configdir, bsetcfg)
if path.exists(bsetname):
break
toolsetname = None
if toolsetname is None:
raise error.general('no tool set file found: %s' % (toolsetcfg))
bsetname = None
if bsetname is None:
raise error.general('no build set file found: %s' % (bsetcfg))
try:
if self.opts.trace():
print '_cgcc:%s: open: %s' % (self.toolset, toolsetname)
toolset = open(toolsetname, 'r')
print '_bset:%s: open: %s' % (self.bset, bsetname)
bset = open(path.host(bsetname), 'r')
except IOError, err:
raise error.general('error opening toolset file: %s' + toolsetname)
raise error.general('error opening bset file: %s' % (bsetname))
configs = []
try:
lc = 0
for l in toolset:
for l in bset:
lc += 1
l = _clean(l)
if len(l) == 0:
@@ -162,44 +160,32 @@ class crossgcc:
if ':' in l:
ls = l.split(':')
if ls[0].strip() == 'package':
self.toolset_pkg = self.opts.expand(ls[1].strip(), self.defaults)
self.defaults['package'] = self.toolset_pkg
self.bset_pkg = self.opts.expand(ls[1].strip(), self.defaults)
self.defaults['package'] = self.bset_pkg
elif l[0] == '%':
if l.startswith('%define'):
ls = l.split()
self.defaults[ls[1].strip()] = ls[2].strip()
else:
raise error.general('invalid directive in tool set files: %s' % (l))
raise error.general('invalid directive in build set files: %s' % (l))
else:
configs += [l.strip()]
except:
toolset.close()
bset.close()
raise
toolset.close()
bset.close()
return configs
def make(self):
def _sort(configs):
_configs = {}
for config in configs:
for order in crossgcc._order:
if config.lower().find(order) >= 0:
_configs[config] = crossgcc._order[order]
sorted_configs = sorted(_configs.iteritems(), key = operator.itemgetter(1))
configs = []
for s in range(0, len(sorted_configs)):
configs.append(sorted_configs[s][0])
return configs
_trace(self.opts, '_cgcc:%s: make' % (self.toolset))
_notice(self.opts, 'toolset: %s' % (self.toolset))
_trace(self.opts, '_bset:%s: make' % (self.bset))
_notice(self.opts, 'bset: %s' % (self.bset))
configs = self.load()
_trace(self.opts, '_cgcc:%s: configs: %s' % (self.toolset, ','.join(configs)))
_trace(self.opts, '_bset:%s: configs: %s' % (self.bset, ','.join(configs)))
current_path = os.environ['PATH']
try:
@@ -207,11 +193,11 @@ class crossgcc:
for s in range(0, len(configs)):
b = build.build(configs[s], _defaults = self.defaults, opts = self.opts)
if s == 0:
path = self.first_package(b)
b.make(path)
self.every_package(b, path)
tmproot = self.first_package(b)
b.make()
self.every_package(b, tmproot)
if s == len(configs) - 1:
self.last_package(b, path)
self.last_package(b, tmproot)
builds += [b]
if not self.opts.no_clean():
for b in builds:
@@ -229,9 +215,9 @@ def run():
try:
opts, _defaults = defaults.load(sys.argv)
log.default = log.log(opts.logfiles())
_notice(opts, 'Tools Builder - CrossGCC Tool Sets, v%s' % (version))
for toolset in opts.params():
c = crossgcc(toolset, _defaults = _defaults, opts = opts)
_notice(opts, 'Source Builder - Set Builder, v%s' % (version))
for bset in opts.params():
c = buildset(bset, _defaults = _defaults, opts = opts)
c.make()
del c
except error.general, gerr: