Support directly installing.

By default the Source Builder now directly installs in the prefix and
does not create tar files. You need to supply options to create build
set level tar files and/or package level tar files.
This commit is contained in:
Chris Johns 2013-02-21 19:03:09 +11:00
parent 729f0bb61f
commit cafbcc611b
2 changed files with 75 additions and 48 deletions

View File

@ -61,8 +61,9 @@ def _notice(opts, text):
class script: class script:
"""Create and manage a shell script.""" """Create and manage a shell script."""
def __init__(self, quiet = True): def __init__(self, quiet = True, trace = False):
self.quiet = quiet self.quiet = quiet
self.trace = trace
self.reset() self.reset()
def reset(self): def reset(self):
@ -76,7 +77,9 @@ class script:
i = 0 i = 0
for l in text: for l in text:
i += 1 i += 1
log.output('script:%3d: ' % (self.lc + i) + l) 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.lc += len(text)
self.body.extend(text) self.body.extend(text)
@ -101,11 +104,12 @@ class script:
class build: class build:
"""Build a package given a config file.""" """Build a package given a config file."""
def __init__(self, name, _defaults, opts): def __init__(self, name, create_tar_files, _defaults, opts):
self.opts = opts self.opts = opts
self.create_tar_files = create_tar_files
_notice(opts, 'building: ' + name) _notice(opts, 'building: ' + name)
self.config = config.file(name, _defaults = _defaults, opts = opts) self.config = config.file(name, _defaults = _defaults, opts = opts)
self.script = script(quiet = opts.quiet()) self.script = script(quiet = opts.quiet(), trace = opts.trace())
def _output(self, text): def _output(self, text):
if not self.opts.quiet(): if not self.opts.quiet():
@ -400,6 +404,7 @@ class build:
self.script.append(' '.join(args)) self.script.append(' '.join(args))
def files(self, package): def files(self, package):
if self.create_tar_files:
self.script.append('echo "==> %files:"') self.script.append('echo "==> %files:"')
prefixbase = self.opts.prefixbase() prefixbase = self.opts.prefixbase()
if prefixbase is None: if prefixbase is None:
@ -495,10 +500,15 @@ def run(args):
raise error.general('host build environment is not set up correctly (use --force to proceed)') 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') _notice(opts, 'warning: forcing build with known host setup problems')
if opts.get_arg('--list-configs'): if opts.get_arg('--list-configs'):
list_configs(opts, _defaults) configs = get_configs(opts, _defaults)
for p in configs['paths']:
print 'Examining: %s' % (os.path.relpath(p))
for c in configs['files']:
if c.endswith('.cfg'):
print ' %s' % (c)
else: else:
for config_file in opts.config_files(): for config_file in opts.config_files():
b = build(config_file, _defaults = _defaults, opts = opts) b = build(config_file, True, _defaults = _defaults, opts = opts)
b.make() b.make()
del b del b
except error.general, gerr: except error.general, gerr:

View File

@ -79,12 +79,8 @@ class buildset:
return None return None
def copy(self, src, dst): def copy(self, src, dst):
if os.path.isdir(path.host(src)): if not os.path.isdir(path.host(src)):
topdir = self.opts.expand('%{_topdir}', self.defaults) raise error.general('copying tree: no source directory: %s' % (path.host(src)))
what = '%s -> %s' % \
(path.host(src[len(topdir) + 1:]), path.host(dst[len(topdir) + 1:]))
if self.opts.trace():
_notice(self.opts, 'installing: %s' % (what))
if not self.opts.dry_run(): if not self.opts.dry_run():
try: try:
files = distutils.dir_util.copy_tree(path.host(src), files = distutils.dir_util.copy_tree(path.host(src),
@ -92,9 +88,9 @@ class buildset:
for f in files: for f in files:
self._output(f) self._output(f)
except IOError, err: except IOError, err:
raise error.general('installing tree: %s: %s' % (what, str(err))) raise error.general('copying tree: %s: %s' % (what, str(err)))
except distutils.errors.DistutilsFileError, err: except distutils.errors.DistutilsFileError, err:
raise error.general('installing tree: %s' % (str(err))) raise error.general('copying tree: %s' % (str(err)))
def first_package(self, _build): def first_package(self, _build):
tmproot = path.abspath(_build.config.expand('%{_tmproot}')) tmproot = path.abspath(_build.config.expand('%{_tmproot}'))
@ -114,12 +110,27 @@ class buildset:
return tmproot return tmproot
def every_package(self, _build, tmproot): def every_package(self, _build, tmproot):
self.copy(_build.config.abspath('%{buildroot}'), tmproot) src = _build.config.abspath('%{buildroot}')
dst = tmproot
if self.opts.get_arg('--bset-tar-file'):
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))
self.copy(src, dst)
if not self.opts.get_arg('--no-install'):
dst = _build.config.expand('%{_prefix}')
src = path.join(src, dst)
_notice(self.opts, 'installing: %s -> %s' % \
(self.bset_pkg, os.path.relpath(path.host(dst))))
self.copy(src, dst)
def last_package(self, _build, tmproot): def last_package(self, _build, tmproot):
if self.opts.get_arg('--bset-tar-file'):
tar = path.join(_build.config.expand('%{_tardir}'), tar = path.join(_build.config.expand('%{_tardir}'),
_build.config.expand('%s.tar.bz2' % (self.bset_pkg))) _build.config.expand('%s.tar.bz2' % (self.bset_pkg)))
_notice(self.opts, 'tarball: %s' % os.path.relpath(path.host(tar))) _notice(self.opts, 'tarball: %s -> %s' %
(os.path.relpath(path.host(tmproot)), os.path.relpath(path.host(tar))))
if not self.opts.dry_run(): if not self.opts.dry_run():
cmd = _build.config.expand("'cd " + tmproot + \ cmd = _build.config.expand("'cd " + tmproot + \
" && %{__tar} -cf - . | %{__bzip2} > " + tar + "'") " && %{__tar} -cf - . | %{__bzip2} > " + tar + "'")
@ -234,7 +245,10 @@ class buildset:
bs.build() bs.build()
del bs del bs
elif configs[s].endswith('.cfg'): elif configs[s].endswith('.cfg'):
b = build.build(configs[s], _defaults = self.defaults, opts = self.opts) b = build.build(configs[s],
self.opts.get_arg('--pkg-tar-files'),
_defaults = self.defaults,
opts = self.opts)
if s == 0: if s == 0:
tmproot = self.first_package(b) tmproot = self.first_package(b)
b.make() b.make()
@ -268,9 +282,12 @@ class buildset:
def run(): def run():
import sys import sys
try: try:
optargs = { '--keep-going': 'Do not stop on error.', optargs = { '--list-configs': 'List available configurations',
'--list-configs': 'List available configurations', '--list-bsets': 'List available build sets',
'--list-bsets': 'List available build sets'} '--keep-going': 'Do not stop on error.',
'--no-install': 'Do not install the packages to the prefix.',
'--bset-tar-file': 'Create a build set tar file',
'--pkg-tar-files': 'Create package tar files' }
opts, _defaults = defaults.load(sys.argv, optargs) opts, _defaults = defaults.load(sys.argv, optargs)
log.default = log.log(opts.logfiles()) log.default = log.log(opts.logfiles())
_notice(opts, 'Source Builder - Set Builder, v%s' % (version)) _notice(opts, 'Source Builder - Set Builder, v%s' % (version))