mirror of
https://git.rtems.org/rtems-source-builder
synced 2024-10-09 07:15:10 +08:00
Refactor the logging support.
This commit is contained in:
parent
ec5674403d
commit
5142becd8e
@ -48,18 +48,10 @@ except:
|
||||
print 'error: unknown application load error'
|
||||
sys.exit(1)
|
||||
|
||||
def _notice(opts, text):
|
||||
if not opts.quiet() and not log.default.has_stdout():
|
||||
print text
|
||||
log.output(text)
|
||||
log.flush()
|
||||
|
||||
class script:
|
||||
"""Create and manage a shell script."""
|
||||
|
||||
def __init__(self, quiet = True, trace = False):
|
||||
self.quiet = quiet
|
||||
self.trace = trace
|
||||
def __init__(self):
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
@ -69,13 +61,11 @@ class script:
|
||||
def append(self, text):
|
||||
if type(text) is str:
|
||||
text = text.splitlines()
|
||||
if not self.quiet:
|
||||
if not log.quiet:
|
||||
i = 0
|
||||
for l in text:
|
||||
i += 1
|
||||
log.output('script:%3d: %s' % (self.lc + i, l))
|
||||
if self.trace:
|
||||
print '%3d: S %s' % (self.lc + i, l)
|
||||
self.lc += len(text)
|
||||
self.body.extend(text)
|
||||
|
||||
@ -107,22 +97,18 @@ class build:
|
||||
else:
|
||||
self.macros = macros
|
||||
self.create_tar_files = create_tar_files
|
||||
_notice(opts, 'config: ' + name)
|
||||
log.notice('config: ' + name)
|
||||
self.config = config.file(name, opts, self.macros)
|
||||
self.script = script(quiet = opts.quiet(), trace = opts.trace())
|
||||
|
||||
def _output(self, text):
|
||||
if not self.opts.quiet():
|
||||
log.output(text)
|
||||
self.script = script()
|
||||
|
||||
def rmdir(self, rmpath):
|
||||
self._output('removing: %s' % (path.host(rmpath)))
|
||||
log.output('removing: %s' % (path.host(rmpath)))
|
||||
if not self.opts.dry_run():
|
||||
if path.exists(rmpath):
|
||||
path.removeall(rmpath)
|
||||
|
||||
def mkdir(self, mkpath):
|
||||
self._output('making dir: %s' % (path.host(mkpath)))
|
||||
log.output('making dir: %s' % (path.host(mkpath)))
|
||||
if not self.opts.dry_run():
|
||||
path.mkdir(mkpath)
|
||||
|
||||
@ -191,7 +177,7 @@ class build:
|
||||
_host != _build and _host != _target
|
||||
|
||||
def setup(self, package, args):
|
||||
self._output('prep: %s: %s' % (package.name(), ' '.join(args)))
|
||||
log.output('prep: %s: %s' % (package.name(), ' '.join(args)))
|
||||
opts, args = getopt.getopt(args[1:], 'qDcTn:b:a:')
|
||||
source_tag = 0
|
||||
quiet = False
|
||||
@ -254,7 +240,7 @@ class build:
|
||||
def run(self, command, shell_opts = '', cwd = None):
|
||||
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)
|
||||
log.output('run: ' + cmd)
|
||||
exit_code, proc, output = e.shell(cmd, cwd = path.host(cwd))
|
||||
if exit_code != 0:
|
||||
raise error.general('shell cmd failed: %s' % (cmd))
|
||||
@ -336,18 +322,14 @@ class build:
|
||||
builddir = self.config.abspath('_builddir')
|
||||
buildcxcdir = self.config.abspath('_buildcxcdir')
|
||||
tmproot = self.config.abspath('_tmproot')
|
||||
if self.opts.trace():
|
||||
_notice(self.opts, 'cleanup: %s' % (buildroot))
|
||||
log.trace('cleanup: %s' % (buildroot))
|
||||
self.rmdir(buildroot)
|
||||
if self.opts.trace():
|
||||
_notice(self.opts, 'cleanup: %s' % (builddir))
|
||||
log.trace('cleanup: %s' % (builddir))
|
||||
self.rmdir(builddir)
|
||||
if self.canadian_cross():
|
||||
if self.opts.trace():
|
||||
_notice(self.opts, 'cleanup: %s' % (buildcxcdir))
|
||||
log.trace('cleanup: %s' % (buildcxcdir))
|
||||
self.rmdir(buildcxcdir)
|
||||
if self.opts.trace():
|
||||
_notice(self.opts, 'cleanup: %s' % (tmproot))
|
||||
log.trace('cleanup: %s' % (tmproot))
|
||||
self.rmdir(tmproot)
|
||||
|
||||
def main_package(self):
|
||||
@ -358,13 +340,12 @@ class build:
|
||||
package = self.main_package()
|
||||
name = package.name()
|
||||
if self.canadian_cross():
|
||||
_notice(self.opts, 'package: (Cxc) %s' % (name))
|
||||
log.notice('package: (Cxc) %s' % (name))
|
||||
else:
|
||||
_notice(self.opts, 'package: %s' % (name))
|
||||
if self.opts.trace():
|
||||
print '---- macro maps', '-' * 55
|
||||
print self.config.macros
|
||||
print '-' * 70
|
||||
log.notice('package: %s' % (name))
|
||||
log.trace('---- macro maps %s' % ('-' * 55))
|
||||
log.trace('%s' % (str(self.config.macros)))
|
||||
log.trace('-' * 70)
|
||||
self.script.reset()
|
||||
self.script.append(self.config.expand('%{___build_template}'))
|
||||
self.script.append('echo "=> ' + name + ':"')
|
||||
@ -373,12 +354,12 @@ class build:
|
||||
if not self.opts.dry_run():
|
||||
self.builddir()
|
||||
sn = path.join(self.config.expand('%{_builddir}'), 'doit')
|
||||
self._output('write script: ' + sn)
|
||||
log.output('write script: ' + sn)
|
||||
self.script.write(sn)
|
||||
if self.canadian_cross():
|
||||
_notice(self.opts, 'building: (Cxc) %s' % (name))
|
||||
log.notice('building: (Cxc) %s' % (name))
|
||||
else:
|
||||
_notice(self.opts, 'building: %s' % (name))
|
||||
log.notice('building: %s' % (name))
|
||||
self.run(sn)
|
||||
|
||||
def name(self):
|
||||
@ -422,13 +403,12 @@ def run(args):
|
||||
try:
|
||||
optargs = { '--list-configs': 'List available configurations' }
|
||||
opts = options.load(args, optargs)
|
||||
log.default = log.log(opts.logfiles())
|
||||
_notice(opts, 'RTEMS Source Builder, Package Builder v%s' % (version.str()))
|
||||
log.notice('RTEMS Source Builder, Package Builder v%s' % (version.str()))
|
||||
if not check.host_setup(opts):
|
||||
if not opts.force():
|
||||
raise error.general('host build environment is not set up' +
|
||||
' correctly (use --force to proceed)')
|
||||
_notice(opts, 'warning: forcing build with known host setup problems')
|
||||
log.notice('warning: forcing build with known host setup problems')
|
||||
if opts.get_arg('--list-configs'):
|
||||
configs = get_configs(opts)
|
||||
for p in configs['paths']:
|
||||
@ -452,7 +432,7 @@ def run(args):
|
||||
except error.exit, eerr:
|
||||
pass
|
||||
except KeyboardInterrupt:
|
||||
_notice(opts, 'abort: user terminated')
|
||||
log.notice('abort: user terminated')
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
||||
|
||||
|
@ -30,13 +30,6 @@ import options
|
||||
import path
|
||||
import version
|
||||
|
||||
def _notice(opts, text):
|
||||
if not opts.quiet() and log.default and not log.default.has_stdout():
|
||||
print text
|
||||
log.output(text)
|
||||
log.flush()
|
||||
|
||||
|
||||
def _check_none(_opts, macro, value, constraint):
|
||||
return True
|
||||
|
||||
@ -48,10 +41,10 @@ def _check_triplet(_opts, macro, value, constraint):
|
||||
def _check_dir(_opts, macro, value, constraint):
|
||||
if constraint != 'none' and not path.isdir(value):
|
||||
if constraint == 'required':
|
||||
_notice(_opts, 'error: dir: not found: (%s) %s' % (macro, value))
|
||||
log.notice('error: dir: not found: (%s) %s' % (macro, value))
|
||||
return False
|
||||
if _opts.warn_all():
|
||||
_notice(_opts, 'warning: dir: not found: (%s) %s' % (macro, value))
|
||||
log.notice('warning: dir: not found: (%s) %s' % (macro, value))
|
||||
return True
|
||||
|
||||
|
||||
@ -77,16 +70,14 @@ def _check_exe(_opts, macro, value, constraint):
|
||||
|
||||
if _check_paths(value, paths):
|
||||
if absexe:
|
||||
_notice(_opts,
|
||||
'warning: exe: absolute exe found in path: (%s) %s' % (macro, orig_value))
|
||||
log.notice('warning: exe: absolute exe found in path: (%s) %s' % (macro, orig_value))
|
||||
return True
|
||||
|
||||
if constraint == 'optional':
|
||||
if _opts.trace():
|
||||
_notice(_opts, 'warning: exe: optional exe not found: (%s) %s' % (macro, orig_value))
|
||||
log.trace('warning: exe: optional exe not found: (%s) %s' % (macro, orig_value))
|
||||
return True
|
||||
|
||||
_notice(_opts, 'error: exe: not found: (%s) %s' % (macro, orig_value))
|
||||
log.notice('error: exe: not found: (%s) %s' % (macro, orig_value))
|
||||
return False
|
||||
|
||||
|
||||
@ -123,12 +114,11 @@ def host_setup(opts):
|
||||
if test not in checks:
|
||||
raise error.general('invalid check test: %s [%r]' % (test, opts.defaults.get(d)))
|
||||
ok = checks[test](opts, d, value, constraint)
|
||||
if opts.trace():
|
||||
if ok:
|
||||
tag = ' '
|
||||
else:
|
||||
tag = '*'
|
||||
_notice(opts, '%c %15s: %r -> "%s"' % (tag, d, opts.defaults.get(d), value))
|
||||
if ok:
|
||||
tag = ' '
|
||||
else:
|
||||
tag = '*'
|
||||
log.trace('%c %15s: %r -> "%s"' % (tag, d, opts.defaults.get(d), value))
|
||||
if sane and not ok:
|
||||
sane = False
|
||||
|
||||
@ -139,7 +129,7 @@ def run():
|
||||
import sys
|
||||
try:
|
||||
_opts = options.load(args = sys.argv)
|
||||
_notice(_opts, 'RTEMS Source Builder - Check, v%s' % (version.str()))
|
||||
log.notice('RTEMS Source Builder - Check, v%s' % (version.str()))
|
||||
if host_setup(_opts):
|
||||
print 'Environment is ok'
|
||||
else:
|
||||
@ -153,7 +143,7 @@ def run():
|
||||
except error.exit, eerr:
|
||||
pass
|
||||
except KeyboardInterrupt:
|
||||
_notice(opts, 'abort: user terminated')
|
||||
log.notice('abort: user terminated')
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
||||
|
||||
|
@ -227,8 +227,8 @@ class file:
|
||||
self.macros = opts.defaults
|
||||
else:
|
||||
self.macros = macros
|
||||
if self.opts.trace():
|
||||
print 'config: %s' % (name)
|
||||
self.init_name = name
|
||||
log.trace('config: %s' % (name))
|
||||
self.disable_macro_reassign = False
|
||||
self.configpath = []
|
||||
self.wss = re.compile(r'\s+')
|
||||
@ -262,22 +262,19 @@ class file:
|
||||
return s
|
||||
|
||||
def _name_line_msg(self, msg):
|
||||
return '%s:%d: %s' % (path.basename(self.name), self.lc, msg)
|
||||
return '%s:%d: %s' % (path.basename(self.init_name), self.lc, msg)
|
||||
|
||||
def _output(self, text):
|
||||
if not self.opts.quiet():
|
||||
log.output(text)
|
||||
|
||||
def _warning(self, msg):
|
||||
self._output('warning: %s' % (self._name_line_msg(msg)))
|
||||
|
||||
def _error(self, msg):
|
||||
err = 'error: %s' % (self._name_line_msg(msg))
|
||||
print >> sys.stderr, err
|
||||
self._output(err)
|
||||
log.stderr(err)
|
||||
log.output(err)
|
||||
self.in_error = True
|
||||
if not self.opts.dry_run():
|
||||
print >> sys.stderr, 'warning: switched to dry run due to errors'
|
||||
log.stderr('warning: switched to dry run due to errors')
|
||||
self.opts.set_dry_run()
|
||||
|
||||
def _label(self, name):
|
||||
@ -389,7 +386,7 @@ class file:
|
||||
elif m.startswith('%{expand'):
|
||||
colon = m.find(':')
|
||||
if colon < 8:
|
||||
self._warning('malformed expand macro, no colon found')
|
||||
log.warning('malformed expand macro, no colon found')
|
||||
else:
|
||||
e = self._expand(m[colon + 1:-1].strip())
|
||||
s = s.replace(m, e)
|
||||
@ -408,11 +405,11 @@ class file:
|
||||
mn = None
|
||||
elif m.startswith('%{echo'):
|
||||
if not m.endswith('}'):
|
||||
self._warning("malformed conditional macro '%s'" % (m))
|
||||
log.warning("malformed conditional macro '%s'" % (m))
|
||||
mn = None
|
||||
else:
|
||||
e = self._expand(m[6:-1].strip())
|
||||
self._output('%s' % (self._name_line_msg(e)))
|
||||
log.output('%s' % (self._name_line_msg(e)))
|
||||
s = ''
|
||||
expanded = True
|
||||
mn = None
|
||||
@ -432,7 +429,7 @@ class file:
|
||||
colon = m[start:].find(':')
|
||||
if colon < 0:
|
||||
if not m.endswith('}'):
|
||||
self._warning("malformed conditional macro '%s'" % (m))
|
||||
log.warning("malformed conditional macro '%s'" % (m))
|
||||
mn = None
|
||||
else:
|
||||
mn = self._label(m[start:-1])
|
||||
@ -474,15 +471,15 @@ class file:
|
||||
|
||||
def _select(self, config, ls):
|
||||
if len(ls) != 2:
|
||||
self._warning('invalid select statement')
|
||||
log.warning('invalid select statement')
|
||||
else:
|
||||
r = self.macros.set_read_map(ls[1])
|
||||
if self.opts.trace():
|
||||
print '_select: ', r, ls[1], self.macros.maps()
|
||||
log.trace('config: %s: _select: %s %s %r' % \
|
||||
(self.init_name, r, ls[1], self.macros.maps()))
|
||||
|
||||
def _define(self, config, ls):
|
||||
if len(ls) <= 1:
|
||||
self._warning('invalid macro definition')
|
||||
log.warning('invalid macro definition')
|
||||
else:
|
||||
d = self._label(ls[1])
|
||||
if self.disable_macro_reassign:
|
||||
@ -493,7 +490,7 @@ class file:
|
||||
else:
|
||||
self.macros[d] = ' '.join([f.strip() for f in ls[2:]])
|
||||
else:
|
||||
self._warning("macro '%s' already defined" % (d))
|
||||
log.warning("macro '%s' already defined" % (d))
|
||||
else:
|
||||
if len(ls) == 2:
|
||||
self.macros[d] = '1'
|
||||
@ -502,13 +499,13 @@ class file:
|
||||
|
||||
def _undefine(self, config, ls):
|
||||
if len(ls) <= 1:
|
||||
self._warning('invalid macro definition')
|
||||
log.warning('invalid macro definition')
|
||||
else:
|
||||
mn = self._label(ls[1])
|
||||
if mn in self.macros:
|
||||
del self.macros[mn]
|
||||
else:
|
||||
self._warning("macro '%s' not defined" % (mn))
|
||||
log.warning("macro '%s' not defined" % (mn))
|
||||
|
||||
def _ifs(self, config, ls, label, iftrue, isvalid):
|
||||
text = []
|
||||
@ -616,8 +613,7 @@ class file:
|
||||
self._error('malformed if: ' + reduce(add, ls, ''))
|
||||
if invert:
|
||||
istrue = not istrue
|
||||
if self.opts.trace():
|
||||
print '_if: ', ifls, istrue
|
||||
log.trace('config: %s: _if: %s %s' % (self.init_name, ifls, str(istrue)))
|
||||
return self._ifs(config, ls, '%if', istrue, isvalid)
|
||||
|
||||
def _ifos(self, config, ls, isvalid):
|
||||
@ -663,8 +659,8 @@ class file:
|
||||
l = _clean(l)
|
||||
if len(l) == 0:
|
||||
continue
|
||||
if self.opts.trace():
|
||||
print '%03d: %d %s' % (self.lc, isvalid, l)
|
||||
log.trace('config: %s: %03d: %s %s' % \
|
||||
(self.init_name, self.lc, str(isvalid), l))
|
||||
lo = l
|
||||
if isvalid:
|
||||
l = self._expand(l)
|
||||
@ -718,11 +714,11 @@ class file:
|
||||
elif ls[0] == '%endif':
|
||||
if roc:
|
||||
return ('control', '%endif', '%endif')
|
||||
self._warning("unexpected '" + ls[0] + "'")
|
||||
log.warning("unexpected '" + ls[0] + "'")
|
||||
elif ls[0] == '%else':
|
||||
if roc:
|
||||
return ('control', '%else', '%else')
|
||||
self._warning("unexpected '" + ls[0] + "'")
|
||||
log.warning("unexpected '" + ls[0] + "'")
|
||||
elif ls[0].startswith('%defattr'):
|
||||
return ('data', [l])
|
||||
elif ls[0] == '%bcond_with':
|
||||
@ -745,7 +741,7 @@ class file:
|
||||
for d in self._directive:
|
||||
if ls[0].strip() == d:
|
||||
return ('directive', ls[0].strip(), ls[1:])
|
||||
self._warning("unknown directive: '" + ls[0] + "'")
|
||||
log.warning("unknown directive: '" + ls[0] + "'")
|
||||
return ('data', [lo])
|
||||
else:
|
||||
return ('data', [lo])
|
||||
@ -837,8 +833,7 @@ class file:
|
||||
raise error.general('no config file found: %s' % (cfgname))
|
||||
|
||||
try:
|
||||
if self.opts.trace():
|
||||
print '_open: %s' % (path.host(configname))
|
||||
log.trace('config: %s: _open: %s' % (self.init_name, path.host(configname)))
|
||||
config = open(path.host(configname), 'r')
|
||||
except IOError, err:
|
||||
raise error.general('error opening config file: %s' % (path.host(configname)))
|
||||
@ -858,7 +853,7 @@ class file:
|
||||
elif r[0] == 'control':
|
||||
if r[1] == '%end':
|
||||
break
|
||||
self._warning("unexpected '%s'" % (r[1]))
|
||||
log.warning("unexpected '%s'" % (r[1]))
|
||||
elif r[0] == 'directive':
|
||||
new_data = []
|
||||
if r[1] == '%description':
|
||||
@ -873,7 +868,7 @@ class file:
|
||||
_package = r[2][0]
|
||||
else:
|
||||
if r[2][0].strip() != '-n':
|
||||
self._warning("unknown directive option: '%s'" % (' '.join(r[2])))
|
||||
log.warning("unknown directive option: '%s'" % (' '.join(r[2])))
|
||||
_package = r[2][1].strip()
|
||||
self._set_package(_package)
|
||||
if dir and dir != r[1]:
|
||||
@ -887,13 +882,12 @@ class file:
|
||||
raise error.general('config error: %s' % (l[7:]))
|
||||
elif l.startswith('%warning'):
|
||||
l = self._expand(l)
|
||||
print >> sys.stderr, 'warning: %s' % (l[9:])
|
||||
self._warning(l[9:])
|
||||
log.stderr('warning: %s' % (l[9:]))
|
||||
log.warning(l[9:])
|
||||
if not dir:
|
||||
l = self._expand(l)
|
||||
ls = self.tags.split(l, 1)
|
||||
if self.opts.trace():
|
||||
print '_tag: ', l, ls
|
||||
log.trace('config: %s: _tag: %s %s' % (self.init_name, l, ls))
|
||||
if len(ls) > 1:
|
||||
info = ls[0].lower()
|
||||
if info[-1] == ':':
|
||||
@ -904,7 +898,7 @@ class file:
|
||||
if info is not None:
|
||||
self._info_append(info, info_data)
|
||||
else:
|
||||
self._warning("invalid format: '%s'" % (info_data[:-1]))
|
||||
log.warning("invalid format: '%s'" % (info_data[:-1]))
|
||||
else:
|
||||
data.append(l)
|
||||
else:
|
||||
@ -976,8 +970,7 @@ def run():
|
||||
# Run where defaults.mc is located
|
||||
#
|
||||
opts = options.load(sys.argv, defaults = 'defaults.mc')
|
||||
if opts.trace():
|
||||
print 'config: count %d' % (len(opts.config_files()))
|
||||
log.trace('config: count %d' % (len(opts.config_files())))
|
||||
for config_file in opts.config_files():
|
||||
s = file(config_file, opts)
|
||||
print s
|
||||
@ -989,7 +982,7 @@ def run():
|
||||
print ierr
|
||||
sys.exit(1)
|
||||
except KeyboardInterrupt:
|
||||
print 'user terminated'
|
||||
log.notice('abort: user terminated')
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
||||
|
||||
|
@ -25,6 +25,7 @@ import os
|
||||
|
||||
import error
|
||||
import execute
|
||||
import log
|
||||
import options
|
||||
import path
|
||||
|
||||
@ -33,7 +34,7 @@ class repo:
|
||||
|
||||
def _cvs_exit_code(self, cmd, ec, output):
|
||||
if ec:
|
||||
print output
|
||||
log.output(output)
|
||||
raise error.general('cvs command failed (%s): %d' % (cmd, ec))
|
||||
|
||||
def _parse_args(self, url):
|
||||
@ -54,7 +55,9 @@ class repo:
|
||||
if path.exists(self.path):
|
||||
cwd = self.path
|
||||
cmd = [self.cvs, '-q'] + args
|
||||
log.output('cmd: (%s) %s' % (str(cwd), ' '.join(cmd)))
|
||||
exit_code, proc, output = e.spawn(cmd, cwd = cwd)
|
||||
log.trace(output)
|
||||
if check:
|
||||
self._cvs_exit_code(cmd, exit_code, output)
|
||||
return exit_code, output
|
||||
|
@ -34,16 +34,6 @@ import git
|
||||
import log
|
||||
import path
|
||||
|
||||
def _notice(opts, text):
|
||||
if not opts.quiet() and not log.default.has_stdout():
|
||||
print text
|
||||
log.output(text)
|
||||
log.flush()
|
||||
|
||||
def _output(opts, text):
|
||||
if not opts.quiet():
|
||||
log.output(text)
|
||||
|
||||
def _http_parser(source, config, opts):
|
||||
#
|
||||
# Is the file compressed ?
|
||||
@ -142,7 +132,7 @@ def _http_downloader(url, local, config, opts):
|
||||
#
|
||||
if url.startswith('https://api.github.com'):
|
||||
url = urlparse.urljoin(url, config.expand('tarball/%{version}'))
|
||||
_notice(opts, 'download: %s -> %s' % (url, os.path.relpath(path.host(local))))
|
||||
log.notice('download: %s -> %s' % (url, os.path.relpath(path.host(local))))
|
||||
failed = False
|
||||
if not opts.dry_run():
|
||||
_in = None
|
||||
@ -152,20 +142,19 @@ def _http_downloader(url, local, config, opts):
|
||||
_out = open(path.host(local), 'wb')
|
||||
_out.write(_in.read())
|
||||
except IOError, err:
|
||||
msg = 'download: %s: error: %s' % (url, str(err))
|
||||
_notice(opts, msg)
|
||||
log.notice('download: %s: error: %s' % (url, str(err)))
|
||||
if path.exists(local):
|
||||
os.remove(path.host(local))
|
||||
failed = True
|
||||
except ValueError, err:
|
||||
msg = 'download: %s: error: %s' % (url, str(err))
|
||||
_notice(opts, msg)
|
||||
log.notice('download: %s: error: %s' % (url, str(err)))
|
||||
if path.exists(local):
|
||||
os.remove(path.host(local))
|
||||
failed = True
|
||||
except:
|
||||
msg = 'download: %s: error' % (url)
|
||||
print >> sys.stderr, msg
|
||||
log.stderr(msd)
|
||||
log.notice(msg)
|
||||
if _out is not None:
|
||||
_out.close()
|
||||
raise
|
||||
@ -183,28 +172,28 @@ def _git_downloader(url, local, config, opts):
|
||||
us = url.split('?')
|
||||
repo = git.repo(local, opts, config.macros)
|
||||
if not repo.valid():
|
||||
_notice(opts, 'git: clone: %s -> %s' % (us[0], rlp))
|
||||
log.notice('git: clone: %s -> %s' % (us[0], rlp))
|
||||
if not opts.dry_run():
|
||||
repo.clone(us[0], local)
|
||||
for a in us[1:]:
|
||||
_as = a.split('=')
|
||||
if _as[0] == 'branch':
|
||||
_notice(opts, 'git: checkout: %s => %s' % (us[0], _as[1]))
|
||||
log.notice('git: checkout: %s => %s' % (us[0], _as[1]))
|
||||
if not opts.dry_run():
|
||||
repo.checkout(_as[1])
|
||||
elif _as[0] == 'pull':
|
||||
_notice(opts, 'git: pull: %s' % (us[0]))
|
||||
log.notice('git: pull: %s' % (us[0]))
|
||||
if not opts.dry_run():
|
||||
repo.pull()
|
||||
elif _as[0] == 'fetch':
|
||||
_notice(opts, 'git: fetch: %s -> %s' % (us[0], rlp))
|
||||
log.notice('git: fetch: %s -> %s' % (us[0], rlp))
|
||||
if not opts.dry_run():
|
||||
repo.fetch()
|
||||
elif _as[0] == 'reset':
|
||||
arg = []
|
||||
if len(_as) > 1:
|
||||
arg = ['--%s' % (_as[1])]
|
||||
_notice(opts, 'git: reset: %s' % (us[0]))
|
||||
log.notice('git: reset: %s' % (us[0]))
|
||||
if not opts.dry_run():
|
||||
repo.reset(arg)
|
||||
return True
|
||||
@ -236,17 +225,17 @@ def _cvs_downloader(url, local, config, opts):
|
||||
date = _as[1]
|
||||
repo = cvs.repo(local, opts, config.macros, src_prefix)
|
||||
if not repo.valid():
|
||||
_notice(opts, 'cvs: checkout: %s -> %s' % (us[0], rlp))
|
||||
log.notice('cvs: checkout: %s -> %s' % (us[0], rlp))
|
||||
if not opts.dry_run():
|
||||
repo.checkout(':%s' % (us[0][6:]), module, tag, date)
|
||||
for a in us[1:]:
|
||||
_as = a.split('=')
|
||||
if _as[0] == 'update':
|
||||
_notice(opts, 'cvs: update: %s' % (us[0]))
|
||||
log.notice('cvs: update: %s' % (us[0]))
|
||||
if not opts.dry_run():
|
||||
repo.update()
|
||||
elif _as[0] == 'reset':
|
||||
_notice(opts, 'cvs: reset: %s' % (us[0]))
|
||||
log.notice('cvs: reset: %s' % (us[0]))
|
||||
if not opts.dry_run():
|
||||
repo.reset()
|
||||
return True
|
||||
@ -266,9 +255,9 @@ def get_file(url, local, opts, config):
|
||||
if local is None:
|
||||
raise error.general('source/patch path invalid')
|
||||
if not path.isdir(path.dirname(local)) and not opts.download_disabled():
|
||||
_notice(opts,
|
||||
'Creating source directory: %s' % (os.path.relpath(path.host(path.dirname(local)))))
|
||||
_output(opts, 'making dir: %s' % (path.host(path.dirname(local))))
|
||||
log.notice('Creating source directory: %s' % \
|
||||
(os.path.relpath(path.host(path.dirname(local)))))
|
||||
log.output('making dir: %s' % (path.host(path.dirname(local))))
|
||||
if not opts.dry_run():
|
||||
path.mkdir(path.dirname(local))
|
||||
if not path.exists(local) and opts.download_disabled():
|
||||
@ -290,8 +279,7 @@ def get_file(url, local, opts, config):
|
||||
url_file = url_path[slash + 1:]
|
||||
urls.append(urlparse.urljoin(base, url_file))
|
||||
urls.append(url)
|
||||
if opts.trace():
|
||||
print '_url:', ','.join(urls), '->', local
|
||||
log.trace('_url: %s -> %s' % (','.join(urls), local))
|
||||
for url in urls:
|
||||
for dl in downloaders:
|
||||
if url.startswith(dl):
|
||||
|
@ -181,6 +181,7 @@ class execute:
|
||||
r, e = os.path.splitext(command[0])
|
||||
if e not in ['.exe', '.com', '.bat']:
|
||||
command[0] = command[0] + '.exe'
|
||||
log.trace('exe: %s' % (command))
|
||||
proc = subprocess.Popen(command, shell = shell,
|
||||
cwd = cwd, env = env,
|
||||
stdin = stdin, stdout = stdout,
|
||||
|
@ -25,6 +25,7 @@ import os
|
||||
|
||||
import error
|
||||
import execute
|
||||
import log
|
||||
import options
|
||||
import path
|
||||
|
||||
@ -41,7 +42,10 @@ class repo:
|
||||
cwd = self.path
|
||||
else:
|
||||
cwd = None
|
||||
exit_code, proc, output = e.spawn([self.git] + args, cwd = cwd)
|
||||
cmd = [self.git] + args
|
||||
log.trace('cmd: (%s) %s' % (str(cwd), ' '.join(cmd)))
|
||||
exit_code, proc, output = e.spawn(cmd, cwd = cwd)
|
||||
log.trace(output)
|
||||
if check:
|
||||
self._git_exit_code(exit_code)
|
||||
return exit_code, output
|
||||
|
@ -31,11 +31,17 @@ import error
|
||||
#
|
||||
default = None
|
||||
|
||||
#
|
||||
# Global parameters.
|
||||
#
|
||||
tracing = False
|
||||
quiet = False
|
||||
|
||||
def set_default_once(log):
|
||||
if default is None:
|
||||
default = log
|
||||
|
||||
def output(text = os.linesep, log = None):
|
||||
def _output(text = os.linesep, log = None):
|
||||
"""Output the text to a log if provided else send it to stdout."""
|
||||
if text is None:
|
||||
text = os.linesep
|
||||
@ -52,6 +58,28 @@ def output(text = os.linesep, log = None):
|
||||
for l in text.replace(chr(13), '').splitlines():
|
||||
print l
|
||||
|
||||
def stderr(text = os.linesep, log = None):
|
||||
for l in text.replace(chr(13), '').splitlines():
|
||||
print >> sys.stderr, l
|
||||
|
||||
def output(text = os.linesep, log = None):
|
||||
if not quiet:
|
||||
_output(text, log)
|
||||
|
||||
def notice(text = os.linesep, log = None):
|
||||
if not quiet and default is not None and not default.has_stdout():
|
||||
for l in text.replace(chr(13), '').splitlines():
|
||||
print l
|
||||
_output(text, log)
|
||||
|
||||
def trace(text = os.linesep, log = None):
|
||||
if tracing:
|
||||
_output(text, log)
|
||||
|
||||
def warning(text = os.linesep, log = None):
|
||||
for l in text.replace(chr(13), '').splitlines():
|
||||
_output('warning: %s' % (l), log)
|
||||
|
||||
def flush(log = None):
|
||||
if log:
|
||||
log.flush()
|
||||
@ -94,6 +122,7 @@ class log:
|
||||
for f in range(0, len(self.fhs)):
|
||||
if self.fhs[f] is not None:
|
||||
self.fhs[f].write(out)
|
||||
self.flush()
|
||||
|
||||
def flush(self):
|
||||
"""Flush the output."""
|
||||
@ -104,8 +133,30 @@ class log:
|
||||
if __name__ == "__main__":
|
||||
l = log(['stdout', 'log.txt'])
|
||||
for i in range(0, 10):
|
||||
l.output('hello world: %d\n' % (i))
|
||||
l.output('hello world CRLF\r\n')
|
||||
l.output('hello world NONE')
|
||||
l.output('log: hello world: %d\n' % (i))
|
||||
l.output('log: hello world CRLF\r\n')
|
||||
l.output('log: hello world NONE')
|
||||
l.flush()
|
||||
for i in [0, 1]:
|
||||
quiet = False
|
||||
tracing = False
|
||||
print '- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30)
|
||||
trace('trace with quiet and trace off')
|
||||
notice('notice with quiet and trace off')
|
||||
quiet = True
|
||||
tracing = False
|
||||
print '- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30)
|
||||
trace('trace with quiet on and trace off')
|
||||
notice('notice with quiet on and trace off')
|
||||
quiet = False
|
||||
tracing = True
|
||||
print '- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30)
|
||||
trace('trace with quiet off and trace on')
|
||||
notice('notice with quiet off and trace on')
|
||||
quiet = True
|
||||
tracing = True
|
||||
print '- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30)
|
||||
trace('trace with quiet on and trace on')
|
||||
notice('notice with quiet on and trace on')
|
||||
default = l
|
||||
del l
|
||||
|
@ -30,6 +30,7 @@ import string
|
||||
import error
|
||||
import execute
|
||||
import git
|
||||
import log
|
||||
import macros
|
||||
import path
|
||||
import sys
|
||||
@ -243,6 +244,12 @@ class command_line:
|
||||
arg += 1
|
||||
|
||||
def post_process(self):
|
||||
# Handle the log first.
|
||||
log.default = log.log(self.logfiles())
|
||||
if self.trace():
|
||||
log.tracing = True
|
||||
if self.quiet():
|
||||
log.quiet = True
|
||||
# Must have a host
|
||||
if self.defaults['_host'] == self.defaults['nil']:
|
||||
raise error.general('host not set')
|
||||
@ -271,6 +278,25 @@ class command_line:
|
||||
for m in um:
|
||||
self.defaults.load(m)
|
||||
|
||||
def sb_git(self):
|
||||
repo = git.repo(self.defaults.expand('%{_sbdir}'), self)
|
||||
if repo.valid():
|
||||
repo_valid = '1'
|
||||
repo_head = repo.head()
|
||||
repo_clean = repo.clean()
|
||||
repo_id = repo_head
|
||||
if not repo_clean:
|
||||
repo_id += '-modified'
|
||||
else:
|
||||
repo_valid = '0'
|
||||
repo_head = '%{nil}'
|
||||
repo_clean = '%{nil}'
|
||||
repo_id = 'no-repo'
|
||||
self.defaults['_sbgit_valid'] = repo_valid
|
||||
self.defaults['_sbgit_head'] = repo_head
|
||||
self.defaults['_sbgit_clean'] = str(repo_clean)
|
||||
self.defaults['_sbgit_id'] = repo_id
|
||||
|
||||
def command(self):
|
||||
return path.join(self.command_path, self.command_name)
|
||||
|
||||
@ -466,26 +492,10 @@ def load(args, optargs = None, defaults = '%{_sbdir}/defaults.mc'):
|
||||
for k in overrides:
|
||||
o.defaults[k] = overrides[k]
|
||||
|
||||
o.sb_git()
|
||||
o.process()
|
||||
o.post_process()
|
||||
|
||||
repo = git.repo(o.defaults.expand('%{_sbdir}'), o)
|
||||
if repo.valid():
|
||||
repo_valid = '1'
|
||||
repo_head = repo.head()
|
||||
repo_clean = repo.clean()
|
||||
repo_id = repo_head
|
||||
if not repo_clean:
|
||||
repo_id += '-modified'
|
||||
else:
|
||||
repo_valid = '0'
|
||||
repo_head = '%{nil}'
|
||||
repo_clean = '%{nil}'
|
||||
repo_id = 'no-repo'
|
||||
o.defaults['_sbgit_valid'] = repo_valid
|
||||
o.defaults['_sbgit_head'] = repo_head
|
||||
o.defaults['_sbgit_clean'] = str(repo_clean)
|
||||
o.defaults['_sbgit_id'] = repo_id
|
||||
return o
|
||||
|
||||
def run(args):
|
||||
|
@ -45,12 +45,6 @@ except:
|
||||
print 'error: unknown application load error'
|
||||
sys.exit(1)
|
||||
|
||||
def _notice(opts, text):
|
||||
if not opts.quiet() and not log.default.has_stdout():
|
||||
print text
|
||||
log.output(text)
|
||||
log.flush()
|
||||
|
||||
class report:
|
||||
"""Report the build details about a package given a config file."""
|
||||
|
||||
@ -364,12 +358,11 @@ def run(args):
|
||||
'--format': 'Output format (text, html, asciidoc)',
|
||||
'--output': 'File name to output the report' }
|
||||
opts = options.load(args, optargs)
|
||||
log.default = log.log(opts.logfiles())
|
||||
if opts.get_arg('--output') and len(opts.params()) > 1:
|
||||
raise error.general('--output can only be used with a single config')
|
||||
print 'RTEMS Source Builder, Reporter v%s' % (version.str())
|
||||
if not check.host_setup(opts):
|
||||
_notice(opts, 'warning: forcing build with known host setup problems')
|
||||
log.warning('forcing build with known host setup problems')
|
||||
configs = build.get_configs(opts)
|
||||
if not setbuilder.list_bset_cfg_files(opts, configs):
|
||||
output = opts.get_arg('--output')
|
||||
@ -409,7 +402,7 @@ def run(args):
|
||||
except error.exit, eerr:
|
||||
pass
|
||||
except KeyboardInterrupt:
|
||||
_notice(opts, 'abort: user terminated')
|
||||
log.notice('abort: user terminated')
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
||||
|
||||
|
@ -46,21 +46,11 @@ except:
|
||||
print 'error: unknown application load error'
|
||||
sys.exit(1)
|
||||
|
||||
def _trace(opts, text):
|
||||
if opts.trace():
|
||||
print text
|
||||
|
||||
def _notice(opts, text):
|
||||
if not opts.quiet() and not log.default.has_stdout():
|
||||
print text
|
||||
log.output(text)
|
||||
log.flush()
|
||||
|
||||
class buildset:
|
||||
"""Build a set builds a set of packages."""
|
||||
|
||||
def __init__(self, bset, _configs, opts, macros = None):
|
||||
_trace(opts, '_bset:%s: init' % (bset))
|
||||
log.trace('_bset: %s: init' % (bset))
|
||||
self.configs = _configs
|
||||
self.opts = opts
|
||||
if macros is None:
|
||||
@ -70,10 +60,6 @@ class buildset:
|
||||
self.bset = bset
|
||||
self.bset_pkg = '%s-%s-set' % (self.macros.expand('%{_target}'), self.bset)
|
||||
|
||||
def _output(self, text):
|
||||
if not self.opts.quiet():
|
||||
log.output(text)
|
||||
|
||||
def copy(self, src, dst):
|
||||
if not os.path.isdir(path.host(src)):
|
||||
raise error.general('copying tree: no source directory: %s' % (path.host(src)))
|
||||
@ -82,7 +68,7 @@ class buildset:
|
||||
files = distutils.dir_util.copy_tree(path.host(src),
|
||||
path.host(dst))
|
||||
for f in files:
|
||||
self._output(f)
|
||||
log.output(f)
|
||||
except IOError, err:
|
||||
raise error.general('copying tree: %s -> %s: %s' % (src, dst, str(err)))
|
||||
except distutils.errors.DistutilsFileError, err:
|
||||
@ -113,7 +99,7 @@ class buildset:
|
||||
name = _build.main_package().name() + ext
|
||||
outpath = path.host(path.join(buildroot, prefix, 'share', 'rtems-source-builder'))
|
||||
outname = path.host(path.join(outpath, name))
|
||||
_notice(self.opts, 'reporting: %s -> %s' % (_config, name))
|
||||
log.notice('reporting: %s -> %s' % (_config, name))
|
||||
if not _build.opts.dry_run():
|
||||
_build.mkdir(outpath)
|
||||
r = reports.report(format, self.configs, _build.opts, _build.macros)
|
||||
@ -123,15 +109,14 @@ class buildset:
|
||||
def root_copy(self, src, dst):
|
||||
what = '%s -> %s' % \
|
||||
(os.path.relpath(path.host(src)), os.path.relpath(path.host(dst)))
|
||||
if self.opts.trace():
|
||||
_notice(self.opts, 'collecting: %s' % (what))
|
||||
log.trace('_bset: %s: collecting: %s' % (self.bset, what))
|
||||
if not self.opts.dry_run():
|
||||
self.copy(src, dst)
|
||||
|
||||
def install(self, name, buildroot, prefix):
|
||||
dst = prefix
|
||||
src = path.join(buildroot, prefix)
|
||||
_notice(self.opts, 'installing: %s -> %s' % (name, path.host(dst)))
|
||||
log.notice('installing: %s -> %s' % (name, path.host(dst)))
|
||||
if not self.opts.dry_run():
|
||||
self.copy(src, dst)
|
||||
|
||||
@ -170,7 +155,7 @@ class buildset:
|
||||
if self.opts.get_arg('--bset-tar-file'):
|
||||
path.mkdir(tardir)
|
||||
tar = path.join(tardir, _build.config.expand('%s.tar.bz2' % (self.bset_pkg)))
|
||||
_notice(self.opts, 'tarball: %s' % (os.path.relpath(path.host(tar))))
|
||||
log.notice('tarball: %s' % (os.path.relpath(path.host(tar))))
|
||||
if not self.opts.dry_run():
|
||||
tmproot = _build.config.expand('%{_tmproot}')
|
||||
cmd = _build.config.expand("'cd " + tmproot + \
|
||||
@ -198,8 +183,7 @@ class buildset:
|
||||
if bsetname is None:
|
||||
raise error.general('no build set file found: %s' % (bset))
|
||||
try:
|
||||
if self.opts.trace():
|
||||
print '_bset:%s: open: %s' % (self.bset, bsetname)
|
||||
log.trace('_bset: %s: open: %s' % (self.bset, bsetname))
|
||||
bset = open(path.host(bsetname), 'r')
|
||||
except IOError, err:
|
||||
raise error.general('error opening bset file: %s' % (bsetname))
|
||||
@ -213,8 +197,7 @@ class buildset:
|
||||
l = _clean(l)
|
||||
if len(l) == 0:
|
||||
continue
|
||||
if self.opts.trace():
|
||||
print '%03d: %s' % (lc, l)
|
||||
log.trace('_bset: %s: %03d: %s' % (self.bset, lc, l))
|
||||
ls = l.split()
|
||||
if ls[0][-1] == ':' and ls[0][:-1] == 'package':
|
||||
self.bset_pkg = self.macros.expand(ls[1].strip())
|
||||
@ -265,12 +248,12 @@ class buildset:
|
||||
|
||||
def build(self, deps = None):
|
||||
|
||||
_trace(self.opts, '_bset:%s: make' % (self.bset))
|
||||
_notice(self.opts, 'Build Set: %s' % (self.bset))
|
||||
log.trace('_bset: %s: make' % (self.bset))
|
||||
log.notice('Build Set: %s' % (self.bset))
|
||||
|
||||
configs = self.load()
|
||||
|
||||
_trace(self.opts, '_bset:%s: configs: %s' % (self.bset, ','.join(configs)))
|
||||
log.trace('_bset: %s: configs: %s' % (self.bset, ','.join(configs)))
|
||||
|
||||
current_path = os.environ['PATH']
|
||||
|
||||
@ -318,7 +301,7 @@ class buildset:
|
||||
if deps is None and \
|
||||
(not self.opts.no_clean() or self.opts.always_clean()):
|
||||
for b in builds:
|
||||
_notice(self.opts, 'cleaning: %s' % (b.name()))
|
||||
log.notice('cleaning: %s' % (b.name()))
|
||||
b.cleanup()
|
||||
for b in builds:
|
||||
del b
|
||||
@ -330,7 +313,7 @@ class buildset:
|
||||
|
||||
os.environ['PATH'] = current_path
|
||||
|
||||
_notice(self.opts, 'Build Set: Time %s' % (str(end - start)))
|
||||
log.notice('Build Set: Time %s' % (str(end - start)))
|
||||
|
||||
def list_bset_cfg_files(opts, configs):
|
||||
if opts.get_arg('--list-configs') or opts.get_arg('--list-bsets'):
|
||||
@ -357,8 +340,7 @@ def run():
|
||||
'--bset-tar-file': 'Create a build set tar file',
|
||||
'--pkg-tar-files': 'Create package tar files' }
|
||||
opts = options.load(sys.argv, optargs)
|
||||
log.default = log.log(opts.logfiles())
|
||||
_notice(opts, 'RTEMS Source Builder - Set Builder, v%s' % (version.str()))
|
||||
log.notice('RTEMS Source Builder - Set Builder, v%s' % (version.str()))
|
||||
if not check.host_setup(opts):
|
||||
raise error.general('host build environment is not set up correctly')
|
||||
configs = build.get_configs(opts)
|
||||
@ -390,7 +372,7 @@ def run():
|
||||
except error.exit, eerr:
|
||||
pass
|
||||
except KeyboardInterrupt:
|
||||
_notice(opts, 'abort: user terminated')
|
||||
log.notice('abort: user terminated')
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user