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

@ -35,9 +35,10 @@ import defaults
import error
import execute
import log
import path
#
# Version of Tools Builder.
# Version of Sourcer Builder Build.
#
version = '0.1'
@ -72,10 +73,10 @@ class script:
def write(self, name, check_for_errors = False):
s = None
try:
s = open(name, 'w')
s = open(path.host(name), 'w')
s.write('\n'.join(self.body))
s.close()
os.chmod(name, stat.S_IRWXU | \
os.chmod(path.host(name), stat.S_IRWXU | \
stat.S_IRGRP | stat.S_IXGRP | \
stat.S_IROTH | stat.S_IXOTH)
except IOError, err:
@ -100,33 +101,33 @@ class build:
if not self.opts.quiet():
log.output(text)
def rmdir(self, path):
self._output('removing: ' + path)
def rmdir(self, rmpath):
self._output('removing: %s' % (path.host(rmpath)))
if not self.opts.dry_run():
if os.path.exists(path):
if path.exists(rmpath):
try:
shutil.rmtree(path)
shutil.rmtree(path.host(rmpath))
except IOError, err:
raise error.error('error removing: ' + path)
raise error.error('error removing: %s' % (path.host(rmpath)))
def mkdir(self, path):
self._output('making dir: ' + path)
def mkdir(self, mkpath):
self._output('making dir: %s' % (path.host(mkpath)))
if not self.opts.dry_run():
try:
os.makedirs(path)
os.makedirs(path.host(mkpath))
except IOError, err:
raise error.general('error creating path: ' + path)
raise error.general('error creating path: %s' % (path.host(path)))
def get_file(self, url, local):
if not os.path.isdir(os.path.dirname(local)):
if not path.isdir(path.dirname(local)):
if not self.opts.force():
raise error.general('source path not found: %s; (--force to create)' \
% (os.path.dirname(local)))
self.mkdir(os.path.dirname(local))
if not os.path.exists(local):
% (path.host(path.dirname(local))))
self.mkdir(path.host(path.dirname(local)))
if not path.exists(local):
#
# Not localy found so we need to download it. Check if a URL
# has been provided on the command line.
# Not localy found so we need to download it. Check if a URL has
# been provided on the command line.
#
url_bases = self.opts.urls()
urls = []
@ -150,20 +151,20 @@ class build:
#
if url.startswith('https://api.github.com'):
url = urlparse.urljoin(url, self.config.expand('tarball/%{version}'))
_notice(self.opts, 'download: ' + url + ' -> ' + local)
_notice(self.opts, 'download: %s -> %s' % (url, path.host(local)))
if not self.opts.dry_run():
failed = False
_in = None
_out = None
try:
_in = urllib2.urlopen(url)
_out = open(local, 'wb')
_out = open(path.host(local), 'wb')
_out.write(_in.read())
except IOError, err:
msg = 'download: %s: error: %s' % (url, str(err))
_notice(self.opts, msg)
if os.path.exists(local):
os.remove(local)
if path.exists(local):
os.remove(path.host(local))
failed = True
except:
print >> sys.stderr, msg
@ -175,8 +176,8 @@ class build:
if _in is not None:
del _in
if not failed:
if not os.path.isfile(local):
raise error.general('source is not a file: ' + local)
if not path.isfile(local):
raise error.general('source is not a file: %s' % (path.host(local)))
return
raise error.general('downloading %s: all paths have failed, giving up' % (url))
@ -186,14 +187,13 @@ class build:
#
source = {}
source['url'] = url
source['path'] = os.path.dirname(url)
source['file'] = os.path.basename(url)
source['name'], source['ext'] = os.path.splitext(source['file'])
source['path'] = path.dirname(url)
source['file'] = path.basename(url)
source['name'], source['ext'] = path.splitext(source['file'])
#
# Get the file. Checks the local source directory first.
#
source['local'] = os.path.join(self.config.abspath(pathkey),
source['file'])
source['local'] = path.join(self.config.abspath(pathkey), source['file'])
#
# Is the file compressed ?
#
@ -223,7 +223,7 @@ class build:
url = sources[s][0]
break
if url is None:
raise error.general('source tag not found: source' + str(source_tag))
raise error.general('source tag not found: source%d' % (source_tag))
source = self.parse_url(url, '_sourcedir')
self.get_file(source['url'], source['local'])
if 'compressed' in source:
@ -245,7 +245,7 @@ class build:
url = patches[p][0]
break
if url is None:
raise error.general('patch tag not found: ' + args[0])
raise error.general('patch tag not found: %s' % (args[0]))
#
# Parse the URL first in the source builder's patch directory.
#
@ -253,7 +253,7 @@ class build:
#
# If not in the source builder package check the source directory.
#
if not os.path.isfile(patch['local']):
if not path.isfile(patch['local']):
patch = self.parse_url(url, '_sourcedir')
self.get_file(patch['url'], patch['local'])
if 'compressed' in patch:
@ -264,7 +264,7 @@ class build:
self.script.append(self.config.expand(patch['script']))
def setup(self, package, args):
self._output('prep: ' + package.name() + ': ' + ' '.join(args))
self._output('prep: %s: %s' % (package.name(), ' '.join(args)))
opts, args = getopt.getopt(args[1:], 'qDcTn:b:a:')
source_tag = 0
quiet = False
@ -287,7 +287,7 @@ class build:
elif o[0] == '-b':
unpack_before_chdir = True
if not o[1].isdigit():
raise error.general('setup source tag no a number: ' + o[1])
raise error.general('setup source tag no a number: %s' % (o[1]))
source_tag = int(o[1])
elif o[0] == '-a':
unpack_before_chdir = False
@ -328,7 +328,7 @@ class build:
e = execute.capture_execution(log = log.default, dump = self.opts.quiet())
cmd = self.config.expand('%{___build_shell} -ex ' + shell_opts + ' ' + command)
self._output('run: ' + cmd)
exit_code, proc, output = e.shell(cmd, cwd = cwd)
exit_code, proc, output = e.shell(cmd, cwd = path.host(cwd))
if exit_code != 0:
raise error.general('shell cmd failed: ' + cmd)
@ -369,12 +369,12 @@ class build:
prefixbase = self.opts.prefixbase()
if prefixbase is None:
prefixbase = ''
inpath = os.path.join('%{buildroot}', prefixbase)
tardir = os.path.abspath(self.config.expand('%{_tardir}'))
inpath = path.join('%{buildroot}', prefixbase)
tardir = path.abspath(self.config.expand('%{_tardir}'))
self.script.append(self.config.expand('if test -d %s; then' % (inpath)))
self.script.append(' mkdir -p %s' % tardir)
self.script.append(self.config.expand(' cd ' + inpath))
tar = os.path.join(tardir, package.long_name() + '.tar.bz2')
tar = path.join(tardir, package.long_name() + '.tar.bz2')
cmd = self.config.expand(' %{__tar} -cf - . ' + '| %{__bzip2} > ' + tar)
self.script.append(cmd)
self.script.append(self.config.expand(' cd %{_builddir}'))
@ -397,7 +397,7 @@ class build:
_notice(self.opts, 'cleanup: %s' % (builddir))
self.rmdir(builddir)
def make(self, path):
def make(self):
packages = self.config.packages()
package = packages['main']
name = package.name()
@ -413,7 +413,7 @@ class build:
self.clean(package)
if not self.opts.dry_run():
self.builddir()
sn = self.config.expand(os.path.join('%{_builddir}', 'doit'))
sn = path.join(self.config.expand('%{_builddir}'), 'doit')
self._output('write script: ' + sn)
self.script.write(sn)
_notice(self.opts, 'building: ' + name)
@ -428,7 +428,7 @@ def run(args):
try:
opts, _defaults = defaults.load(args)
log.default = log.log(opts.logfiles())
_notice(opts, 'Tools Builder, v%s' % (version))
_notice(opts, 'Source Builder, Package Builder v%s' % (version))
for config_file in opts.config_files():
b = build(config_file, _defaults = _defaults, opts = opts)
b.make()

View File

@ -33,6 +33,7 @@ import defaults
import error
import execute
import log
import path
class package:
@ -75,7 +76,7 @@ class package:
def get_info(self, info):
if not info in self.infos:
raise error.general('no ' + info + ' in package "' + self.name + '"')
raise error.general('no %s in package "%s"' % (info, self.name))
return self.info
def version(self):
@ -214,7 +215,7 @@ class file:
return s
def _name_line_msg(self, msg):
return '%s:%d: %s' % (os.path.basename(self.name), self.lc, msg)
return '%s:%d: %s' % (path.basename(self.name), self.lc, msg)
def _output(self, text):
if not self.opts.quiet():
@ -305,7 +306,7 @@ class file:
if exit_code == 0:
line = line.replace(s, output)
else:
raise error.general('shell macro failed: ' + s + ': ' + output)
raise error.general('shell macro failed: %s: %s' % (s, output))
return line
def _expand(self, s):
@ -366,7 +367,7 @@ class file:
colon = m[start:].find(':')
if colon < 0:
if not m.endswith('}'):
self._warning("malform conditional macro'" + m)
self._warning("malform conditional macro '%s'" % (m))
mn = None
else:
mn = self._label(m[start:-1])
@ -394,7 +395,7 @@ class file:
s = s.replace(m, self.defines[mn.lower()])
expanded = True
elif show_warning:
self._error("macro '" + mn + "' not found")
self._error("macro '%s' not found" % (mn))
return self._shell(s)
def _define(self, config, ls):
@ -409,7 +410,7 @@ class file:
self.defines[d] = ls[2].strip()
else:
if self.opts.warn_all():
self._warning("macro '" + d + "' already defined")
self._warning("macro '%s' already defined" % (d))
def _undefine(self, config, ls):
if len(ls) <= 1:
@ -417,7 +418,7 @@ class file:
else:
mn = self._label(ls[1])
if mn in self.defines:
self._error("macro '" + mn + "' not defined")
self._error("macro '%s' not defined" % (mn))
del self.defines[mn]
def _ifs(self, config, ls, label, iftrue, isvalid):
@ -719,16 +720,16 @@ class file:
else:
configname = '%s.cfg' % (exname)
cfgname = os.path.basename(configname)
cfgname = path.basename(configname)
if not os.path.exists(configname):
if not path.exists(configname):
if ':' in configname:
configdirs = os.path.dirname(configname).split(':')
configdirs = path.dirname(configname).split(':')
else:
configdirs = self.define('_configdir').split(':')
for cp in configdirs:
configname = os.path.join(os.path.abspath(cp), cfgname)
if os.path.exists(configname):
configname = path.join(path.abspath(cp), cfgname)
if path.exists(configname):
break
configname = None
if configname is None:
@ -736,10 +737,10 @@ class file:
try:
if self.opts.trace():
print '_open: %s' % (configname)
config = open(configname, 'r')
print '_open: %s' % (path.host(configname))
config = open(path.host(configname), 'r')
except IOError, err:
raise error.general('error opening config file: %s' % (configname))
raise error.general('error opening config file: %s' % (path.host(configname)))
self.configpath += [configname]
try:
@ -768,7 +769,7 @@ class file:
_package = r[2][0]
else:
if r[2][0].strip() != '-n':
self._warning("unknown directive option: '" + ' '.join(r[2]) + "'")
self._warning("unknown directive option: '%s'" % (' '.join(r[2])))
_package = r[2][1].strip()
self._set_package(_package)
if dir and dir != r[1]:
@ -840,8 +841,8 @@ class file:
'" not found in package "' + _package + '"')
return self._packages[_package].directives[name]
def abspath(self, path):
return os.path.abspath(self.define(path))
def abspath(self, rpath):
return path.abspath(self.define(rpath))
def packages(self):
return self._packages

View File

@ -28,9 +28,15 @@ import os
import error
import execute
import path
basepath = 'sb'
#
# All paths in defaults must be Unix format. Do not store any Windows format
# paths in the defaults.
#
defaults = {
# Nothing
'nil': '',
@ -53,7 +59,7 @@ defaults = {
'_builddir': '%{_topdir}/build/%{name}-%{version}-%{release}',
'_docdir': '%{_defaultdocdir}',
'_tmppath': '%{_topdir}/build/tmp',
'_tmproot': '%{_tmppath}/source-build-%(%{__id_u} -n)/%{_toolset}',
'_tmproot': '%{_tmppath}/source-build-%(%{__id_u} -n)/%{_bset}',
'buildroot:': '%{_tmppath}/%{name}-root-%(%{__id_u} -n)',
# Defaults, override in platform specific modules.
@ -199,19 +205,21 @@ class command_line:
'no-smp' : '0',
'rebuild' : '0' }
_long_opts = { '--prefix' : '_prefix',
'--prefixbase' : '_prefixbase',
'--topdir' : '_topdir',
'--configdir' : '_configdir',
'--builddir' : '_builddir',
'--sourcedir' : '_sourcedir',
'--usrlibrpm' : '_usrlibrpm', # XXX remove ?
'--tmppath' : '_tmppath',
'--log' : '_logfile',
'--url' : '_url_base',
'--targetcflags' : '_targetcflags',
'--targetcxxflags' : '_targetcxxflags',
'--libstdcxxflags' : '_libstdcxxflags' }
#
# The define and if it is a path and needs conversion.
#
_long_opts = { '--prefix' : ('_prefix', True),
'--prefixbase' : ('_prefixbase', True),
'--topdir' : ('_topdir', True),
'--configdir' : ('_configdir', True),
'--builddir' : ('_builddir', True),
'--sourcedir' : ('_sourcedir', True),
'--tmppath' : ('_tmppath', True),
'--log' : ('_logfile', False),
'--url' : ('_url_base', False),
'--targetcflags' : ('_targetcflags', False),
'--targetcxxflags' : ('_targetcxxflags', False),
'--libstdcxxflags' : ('_libstdcxxflags', False) }
_long_true_opts = { '--force' : '_force',
'--trace' : '_trace',
@ -256,15 +264,15 @@ class command_line:
raise error.exit()
def __init__(self, argv):
self.command_path = os.path.dirname(argv[0])
self.command_path = path.dirname(argv[0])
if len(self.command_path) == 0:
self.command_path = '.'
self.command_name = os.path.basename(argv[0])
self.command_name = path.basename(argv[0])
self.args = argv[1:]
self.defaults = {}
for to in command_line._long_true_opts:
self.defaults[command_line._long_true_opts[to]] = '0'
self.defaults['_sbdir'] = self.command_path
self.defaults['_sbdir'] = path.shell(self.command_path)
self._process()
def __str__(self):
@ -295,9 +303,11 @@ class command_line:
value = args[arg]
else:
value = opt[equals + 1:]
return lo, long_opts[lo], value, arg
if long_opts[lo][1]:
value = path.shell(value)
return lo, long_opts[lo][0], value, arg
elif opt == lo:
return lo, long_opts[lo], True, arg
return lo, long_opts[lo][0], True, arg
return None, None, None, arg
self.opts = command_line._defaults
@ -337,8 +347,8 @@ class command_line:
# make sure it is ok.
#
e = execute.capture_execution()
config_sub = os.path.join(self.command_path,
basepath, 'config.sub')
config_sub = path.join(self.command_path,
basepath, 'config.sub')
exit_code, proc, output = e.shell(config_sub + ' ' + value)
if exit_code == 0:
value = output
@ -401,7 +411,7 @@ class command_line:
return s
def command(self):
return os.path.join(self.command_path, self.command_name)
return path.join(self.command_path, self.command_name)
def force(self):
return self.opts['force'] != '0'
@ -434,17 +444,24 @@ class command_line:
return self.opts['params']
def get_config_files(self, config):
#
# Convert to shell paths and return shell paths.
#
config = path.shell(config)
if config.find('*') >= 0 or config.find('?'):
configdir = os.path.dirname(config)
configbase = os.path.basename(config)
configdir = path.dirname(config)
configbase = path.basename(config)
if len(configbase) == 0:
configbase = '*'
if len(configdir) == 0:
configdir = self.expand(defaults['_configdir'], defaults)
if not os.path.isdir(configdir):
raise error.general('configdir is not a directory or does not exist: ' + configdir)
files = glob.glob(os.path.join(configdir, configbase))
configs = files
hostconfigdir = path.host(configdir)
if not os.path.isdir(hostconfigdir):
raise error.general('configdir is not a directory or does not exist: %s' % (hostconfigdir))
files = glob.glob(os.path.join(hostconfigdir, configbase))
configs = []
for f in files:
configs += path.shell(f)
else:
configs = [config]
return configs

92
sb/path.py Normal file
View File

@ -0,0 +1,92 @@
#
# RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2012 Chris Johns (chrisj@rtems.org)
# All rights reserved.
#
# This file is part of the RTEMS Tools package in 'rtems-tools'.
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Manage paths locally. The internally the path is in Unix or shell format and
# we convert to the native format when performing operations at the Python
# level. This allows macro expansion to work.
#
import os
import string
windows = os.name == 'nt'
def host(path):
if path is not None:
while '//' in path:
path = path.replace('//', '/')
if windows and len(path) > 2:
if path[0] == '/' and path[2] == '/' and \
(path[1] in string.ascii_lowercase or \
path[1] in string.ascii_uppercase):
path = ('%s:%s' % (path[1], path[2:])).replace('/', '\\')
return path
def shell(path):
if path is not None:
if windows and len(path) > 1 and path[1] == ':':
path = ('/%s%s' % (path[0], path[2:])).replace('\\', '/')
while '//' in path:
path = path.replace('//', '/')
return path
def basename(path):
return shell(os.path.basename(path))
def dirname(path):
return shell(os.path.dirname(path))
def join(path, *args):
path = shell(path)
for arg in args:
path += '/' + shell(arg)
return shell(path)
def abspath(path):
return shell(os.path.abspath(host(path)))
def splitext(path):
root, ext = os.path.splitext(host(path))
return shell(root), ext
def exists(path):
return os.path.exists(host(path))
def isdir(path):
return os.path.isdir(host(path))
def isfile(path):
return os.path.isfile(host(path))
if __name__ == '__main__':
print host('/a/b/c/d-e-f')
print host('//a/b//c/d-e-f')
print shell('/w/x/y/z')
print basename('/as/sd/df/fg/me.txt')
print dirname('/as/sd/df/fg/me.txt')
print join('/d', 'g', '/tyty/fgfg')
windows = True
print host('/a/b/c/d-e-f')
print host('//a/b//c/d-e-f')
print shell('/w/x/y/z')
print shell('w:/x/y/z')
print basename('x:/sd/df/fg/me.txt')
print dirname('x:/sd/df/fg/me.txt')
print join('s:/d/', '/g', '/tyty/fgfg')

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:

View File

@ -59,7 +59,7 @@ def load():
# Build flags
'optflags': '-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -mms-bitfields'
}
Return defines
return defines
if __name__ == '__main__':
pprint.pprint(load())