Refactor defaults, macros and options.

To support building snapshots and pre-release source the defaults
has been refactored. The defaults have been moved to a stand alone
file and a macros.py module added. This modile abstracts the
old default dictionary turning it into a class. The macros
class can load macros from a file therefore the defaults have
been moved to a stand alone file.

The use of defaults has been removed from the project. The only
case where it is used in the options where the defaults are read
from a file. Macros are used everywhere now.

The defaults.py has been moved to the option.py and the separate
options and defaults values has been moved to a new pattern. When
constructing an object that needs macros and options if the macros
passed in is None the defaults from the options are used. This makes
it clear when the defaults are being used or when a modified set of
macros is being used.

The macros class support maps. The default is 'global' and where all
the defaults reside and where configuratiion file changes end up.
Maps allow macros to be read from a file and override the values
being maintained in the 'global' map. Reading a macro first checks
the map and if not present checks the 'global' map.

The addition of maps to the macros provides the base to support
snapshots and pre-release testing with standard configurations.
This functionality needs to be added. It works by letting to
specify a snapshot with:

source0: none, override, 'my-dist.tar.bz2'

and it will be used rather the value from the standard configuration.
With a build set you need to also specify the package these macros
are for. The maps provide this.
This commit is contained in:
Chris Johns 2013-04-09 13:51:43 +10:00
parent 530a9385a7
commit cb12e4875c
11 changed files with 780 additions and 438 deletions

242
source-builder/defaults.mc Normal file
View File

@ -0,0 +1,242 @@
#
# RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2013 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.
#
# All paths in defaults must be Unix format. Do not store any Windows format
# paths in the defaults.
#
# Every entry must describe the type of checking a host must pass.
#
# Records:
# key: type, attribute, value
# type : none, dir, exe, triplet
# attribute: none, required, optional
# value : 'single line', '''multi line'''
#
#
# Global defaults
#
[global]
# Nothing
nil: none, none, ''
# Set to invalid values.
_bset: none, none, ''
name: none, none, ''
version: none, none, ''
release: none, none, ''
# GNU triples needed to build packages
_host: triplet, required, ''
_build: triplet, required, '%{_host}'
_target: none, optional, ''
# Paths
_host_platform: none, none, '%{_host_cpu}-%{_host_vendor}-%{_host_os}%{?_gnu}'
_arch: none, none, '%{_host_arch}'
_topdir: dir, required, '%{_cwd}'
_configdir: dir, optional, '%{_topdir}/config:%{_sbdir}/config'
_tardir: dir, optional, '%{_topdir}/tar'
_sourcedir: dir, optional, '%{_topdir}/sources'
_patchdir: dir, optional, '%{_topdir}/patches:%{_sbdir}/patches'
_builddir: dir, optional, '%{_topdir}/build/%{name}-%{version}-%{release}'
_buildcxcdir: dir, optional, '%{_topdir}/build/%{name}-%{version}-%{release}-cxc'
_docdir: dir, none, '%{_defaultdocdir}'
_tmppath: dir, none, '%{_topdir}/build/tmp'
_tmproot: dir, none, '%{_tmppath}/source-build-%(%{__id_u} -n)/%{_bset}'
_tmpcxcroot: dir, none, '%{_tmppath}/source-build-%(%{__id_u} -n)-cxc/%{_bset}'
buildroot: dir, none, '%{_tmppath}/%{name}-root-%(%{__id_u} -n)'
buildcxcroot: dir, none, '%{_tmppath}/%{name}-root-%(%{__id_u} -n)-cxc'
_datadir: dir, none, '%{_prefix}/share'
_defaultdocdir: dir, none, '%{_prefix}/share/doc'
_exeext: none, none, ''
_exec_prefix: dir, none, '%{_prefix}'
_bindir: dir, none, '%{_exec_prefix}/bin'
_sbindir: dir, none, '%{_exec_prefix}/sbin'
_libexecdir: dir, none, '%{_exec_prefix}/libexec'
_datarootdir: dir, none, '%{_prefix}/share'
_datadir: dir, none, '%{_datarootdir}'
_sysconfdir: dir, none, '%{_prefix}/etc'
_sharedstatedir: dir, none, '%{_prefix}/com'
_localstatedir: dir, none, '%{prefix}/var'
_includedir: dir, none, '%{_prefix}/include'
_lib: dir, none, 'lib'
_libdir: dir, none, '%{_exec_prefix}/%{_lib}'
_libexecdir: dir, none, '%{_exec_prefix}/libexec'
_mandir: dir, none, '%{_datarootdir}/man'
_infodir: dir, none, '%{_datarootdir}/info'
_localedir: dir, none, '%{_datarootdir}/locale'
_localedir: dir, none, '%{_datadir}/locale'
_localstatedir: dir, none, '%{_prefix}/var'
_prefix: dir, none, '%{_usr}'
_usr: dir, none, '/usr/local'
_usrsrc: dir, none, '%{_usr}/src'
_var: dir, none, '/usr/local/var'
_varrun: dir, none, '%{_var}/run'
# Defaults, override in platform specific modules.
___setup_shell: exe, required, '/bin/sh'
__aclocal: exe, optional, 'aclocal'
__ar: exe, required, 'ar'
__arch_install_post: exe, none, '%{nil}'
__as: exe, required, 'as'
__autoconf: exe, required, 'autoconf'
__autoheader: exe, required, 'autoheader'
__automake: exe, required, 'automake'
__awk: exe, required, 'awk'
__bash: exe, optional, '/bin/bash'
__bison: exe, required, '/usr/bin/bison'
__bzip2: exe, required, '/usr/bin/bzip2'
__cat: exe, required, '/bin/cat'
__cc: exe, required, '/usr/bin/gcc'
__chgrp: exe, required, '/usr/bin/chgrp'
__chmod: exe, required, '/bin/chmod'
__chown: exe, required, '/usr/sbin/chown'
__cp: exe, required, '/bin/cp'
__cpp: exe, none, '%{__cc} -E'
__cxx: exe, required, '/usr/bin/g++'
__flex: exe, required, '/usr/bin/flex'
__git: exe, required, '/usr/bin/git'
__grep: exe, required, '/usr/bin/grep'
__gzip: exe, required, '/usr/bin/gzip'
__id: exe, required, '/usr/bin/id'
__id_u: exe, none, '%{__id} -u'
__install: exe, required, '/usr/bin/install'
__install_info: exe, optional, '/usr/bin/install-info'
__ld: exe, required, '/usr/bin/ld'
__ldconfig: exe, required, '/sbin/ldconfig'
__ln_s: exe, none, 'ln -s'
__make: exe, required, 'make'
__makeinfo: exe, required, '/usr/bin/makeinfo'
__mkdir: exe, required, '/bin/mkdir'
__mkdir_p: exe, none, '/bin/mkdir -p'
__mv: exe, required, '/bin/mv'
__nm: exe, required, '/usr/bin/nm'
__objcopy: exe, optional, '/usr/bin/objcopy'
__objdump: exe, optional, '/usr/bin/objdump'
__patch_bin: exe, required, '/usr/bin/patch'
__patch_opts: none, none, '%{nil}'
__patch: exe, none, '%{__patch_bin} %{__patch_opts}'
__perl: exe, optional, 'perl'
__ranlib: exe, required, 'ranlib'
__rm: exe, required, '/bin/rm'
__rmfile: exe, none, '%{__rm} -f'
__rmdir: exe, none, '%{__rm} -rf'
__sed: exe, required, '/usr/bin/sed'
__setup_post: exe, none, '%{__chmod} -R a+rX,g-w,o-w .'
__sh: exe, required, '/bin/sh'
__tar: exe, required, '/usr/bin/tar'
__tar_extract: exe, none, '%{__tar} -xvvf'
__touch: exe, required, '/usr/bin/touch'
__unzip: exe, required, '/usr/bin/unzip'
__xz: exe, required, '/usr/bin/xz'
# Shell Build Settings.
___build_args: none, none, '-e'
___build_cmd: none, none, '%{?_sudo:%{_sudo} }%{?_remsh:%{_remsh} %{_remhost} }%{?_remsudo:%{_remsudo} }%{?_remchroot:%{_remchroot} %{_remroot} }%{___build_shell} %{___build_args}'
___build_post: none, none, 'exit 0'
# Prebuild set up script.
___build_pre: none, none, '''# ___build_pre in as set up in defaults.py
# Save the original path away.
export SB_ORIG_PATH=${PATH}
# Directories
%{?_prefix:SB_PREFIX="%{_prefix}"}
%{?_prefix:SB_PREFIX_CLEAN=$(echo "%{_prefix}" | %{__sed} -e 's/^\///')}
SB_SOURCE_DIR="%{_sourcedir}"
SB_BUILD_DIR="%{_builddir}"
SB_OPT_FLAGS="%{?_tmproot:-I%{_tmproot}/${SB_PREFIX_CLEAN}/include -L%{_tmproot}/${SB_PREFIX_CLEAN}/lib} %{optflags}"
SB_ARCH="%{_arch}"
SB_OS="%{_os}"
export SB_SOURCE_DIR SB_BUILD_DIR SB_OPT_FLAGS SB_ARCH SB_OS
# Documentation
SB_DOC_DIR="%{_docdir}"
export SB_DOC_DIR
# Packages
SB_PACKAGE_NAME="%{name}"
SB_PACKAGE_VERSION="%{version}"
SB_PACKAGE_RELEASE="%{release}"
export SB_PACKAGE_NAME SB_PACKAGE_VERSION SB_PACKAGE_RELEASE
# Build directories
export SB_PREFIX
%{?_builddir:SB_BUILD_DIR="%{_builddir}"}
%{?buildroot:SB_BUILD_ROOT="%{buildroot}"}
%{?buildroot:%{?_prefix:SB_BUILD_ROOT_BINDIR="%{buildroot}/${SB_PREFIX_CLEAN}/bin"}}
export SB_BUILD_ROOT SB_BUILD_DIR SB_BUILD_ROOT_BINDIR
%{?_buildcxcdir:SB_BUILD_CXC_DIR="%{_buildcxcdir}"}
%{?buildcxcroot:SB_BUILD_CXC_ROOT="%{buildcxcroot}"}
%{?buildcxcroot:%{?_prefix:SB_BUILD_CXC_ROOT_BINDIR="%{buildcxcroot}/${SB_PREFIX_CLEAN}/bin"}}
export SB_BUILD_CXC_ROOT SB_BUILD_CXC_DIR SB_BUILD_CXC_ROOT_BINDIR
%{?_tmproot:SB_TMPROOT="%{_tmproot}"}
%{?_tmproot:%{?_prefix:SB_TMPPREFIX="%{_tmproot}/${SB_PREFIX_CLEAN}"}}
%{?_tmproot:%{?_prefix:SB_TMPBINDIR="%{_tmproot}/${SB_PREFIX_CLEAN}/bin"}}
export SB_TMPROOT SB_TMPPREFIX SB_TMPBINDIR
%{?_tmpcxcroot:SB_TMPCXCROOT="%{_tmproot}"}
%{?_tmpcxcroot:%{?_prefix:SB_TMPCXCPREFIX="%{_tmpcxcroot}/${SB_PREFIX_CLEAN}"}}
%{?_tmpcxcroot:%{?_prefix:SB_TMPCXCBINDIR="%{_tmpcxcroot}/${SB_PREFIX_CLEAN}/bin"}}
export SB_TMPCXCROOT SB_TMPCXCPREFIX SB_TMPCXCBINDIR
# The compiler flags
%{?_targetcflags:CFLAGS_FOR_TARGET="%{_targetcflags}"}
%{?_targetcxxflags:CXXFLAGS_FOR_TARGET="%{_targetcxxflags}"}
export CFLAGS_FOR_TARGET
export CXXFLAGS_FOR_TARGET
# Set up the path. Put the CXC path first.
if test -n "${SB_TMPBINDIR}" ; then
PATH="${SB_TMPBINDIR}:$PATH"
fi
if test -n "${SB_TMPCXCBINDIR}" ; then
PATH="${SB_TMPCXCBINDIR}:$PATH"
fi
export PATH
# Default environment set up.
LANG=C
export LANG
unset DISPLAY || :
umask 022
cd "%{_builddir}"'''
___build_shell: none, none, '%{?_buildshell:%{_buildshell}}%{!?_buildshell:/bin/sh}'
___build_template: none, none, '''#!%{___build_shell}
%{___build_pre}
%{nil}'''
# Configure command
configure: none, none, '''
CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ;
CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ;
FFLAGS="${FFLAGS:-%optflags}" ; export FFLAGS ;
./configure --build=%{_build} --host=%{_host} \
--target=%{_target_platform} \
--program-prefix=%{?_program_prefix} \
--prefix=%{_prefix} \
--exec-prefix=%{_exec_prefix} \
--bindir=%{_bindir} \
--sbindir=%{_sbindir} \
--sysconfdir=%{_sysconfdir} \
--datadir=%{_datadir} \
--includedir=%{_includedir} \
--libdir=%{_libdir} \
--libexecdir=%{_libexecdir} \
--localstatedir=%{_localstatedir} \
--sharedstatedir=%{_sharedstatedir} \
--mandir=%{_mandir} \
--infodir=%{_infodir}'''

View File

@ -22,8 +22,8 @@ import sys, os
base = os.path.dirname(sys.argv[0]) base = os.path.dirname(sys.argv[0])
sys.path.insert(0, base + '/sb') sys.path.insert(0, base + '/sb')
try: try:
import defaults import options
defaults.run(sys.argv) options.run(sys.argv)
except ImportError: except ImportError:
print >> sys.stderr, "Incorrect Defaults installation" print >> sys.stderr, "Incorrect Defaults installation"
sys.exit(1) sys.exit(1)

View File

@ -34,10 +34,10 @@ import urlparse
try: try:
import check import check
import config import config
import defaults
import error import error
import execute import execute
import log import log
import options
import path import path
import version import version
except KeyboardInterrupt: except KeyboardInterrupt:
@ -99,11 +99,15 @@ class script:
class build: class build:
"""Build a package given a config file.""" """Build a package given a config file."""
def __init__(self, name, create_tar_files, _defaults, opts): def __init__(self, name, create_tar_files, opts, macros = None):
self.opts = opts self.opts = opts
if macros is None:
self.macros = opts.defaults
else:
self.macros = macros
self.create_tar_files = create_tar_files self.create_tar_files = create_tar_files
_notice(opts, 'config: ' + name) _notice(opts, 'config: ' + name)
self.config = config.file(name, _defaults = _defaults, opts = opts) self.config = config.file(name, opts, self.macros)
self.script = script(quiet = opts.quiet(), trace = opts.trace()) self.script = script(quiet = opts.quiet(), trace = opts.trace())
def _output(self, text): def _output(self, text):
@ -481,7 +485,7 @@ class build:
package = packages['main'] package = packages['main']
return package.name() return package.name()
def get_configs(opts, _defaults): def get_configs(opts):
def _scan(_path, ext): def _scan(_path, ext):
configs = [] configs = []
@ -494,7 +498,7 @@ def get_configs(opts, _defaults):
return configs return configs
configs = { 'paths': [], 'files': [] } configs = { 'paths': [], 'files': [] }
for cp in opts.expand('%{_configdir}', _defaults).split(':'): for cp in opts.defaults.expand('%{_configdir}').split(':'):
hcp = path.host(path.abspath(cp)) hcp = path.host(path.abspath(cp))
configs['paths'] += [hcp] configs['paths'] += [hcp]
configs['files'] += _scan(hcp, ['.cfg', '.bset']) configs['files'] += _scan(hcp, ['.cfg', '.bset'])
@ -516,16 +520,16 @@ def find_config(config, configs):
def run(args): def run(args):
try: try:
optargs = { '--list-configs': 'List available configurations' } optargs = { '--list-configs': 'List available configurations' }
opts, _defaults = defaults.load(args, optargs) opts = options.load(args, optargs)
log.default = log.log(opts.logfiles()) log.default = log.log(opts.logfiles())
_notice(opts, 'RTEMS Source Builder, Package Builder v%s' % (version.str())) _notice(opts, 'RTEMS Source Builder, Package Builder v%s' % (version.str()))
if not check.host_setup(opts, _defaults): if not check.host_setup(opts):
if not opts.force(): if not opts.force():
raise error.general('host build environment is not set up' + raise error.general('host build environment is not set up' +
' correctly (use --force to proceed)') ' 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'):
configs = get_configs(opts, _defaults) configs = get_configs(opts)
for p in configs['paths']: for p in configs['paths']:
print 'Examining: %s' % (os.path.relpath(p)) print 'Examining: %s' % (os.path.relpath(p))
for c in configs['files']: for c in configs['files']:
@ -533,7 +537,7 @@ def run(args):
print ' %s' % (c) print ' %s' % (c)
else: else:
for config_file in opts.config_files(): for config_file in opts.config_files():
b = build(config_file, True, _defaults = _defaults, opts = opts) b = build(config_file, True, opts)
b.make() b.make()
del b del b
except error.general, gerr: except error.general, gerr:

View File

@ -23,10 +23,10 @@
import os import os
import defaults
import error import error
import execute import execute
import log import log
import options
import path import path
import version import version
@ -100,7 +100,7 @@ def _check_paths(name, paths):
return True return True
return False return False
def host_setup(_opts, _defaults): def host_setup(opts):
""" Basic sanity check. All executables and directories must exist.""" """ Basic sanity check. All executables and directories must exist."""
checks = { 'none': _check_none, checks = { 'none': _check_none,
@ -110,22 +110,22 @@ def host_setup(_opts, _defaults):
sane = True sane = True
for d in sorted(_defaults.iterkeys()): for d in opts.defaults.keys():
try: try:
(test, constraint, value) = _defaults[d] (test, constraint, value) = opts.defaults.get(d)
except: except:
raise error.general('invalid default: %s [%r]' % (d, _defaults[d])) raise error.general('invalid default: %s [%r]' % (d, opts.defaults.get(d)))
if test != 'none': if test != 'none':
value = _opts.expand(value, _defaults) value = opts.defaults.expand(value)
if test not in checks: if test not in checks:
raise error.general('invalid check test: %s [%r]' % (test, _defaults[d])) raise error.general('invalid check test: %s [%r]' % (test, opts.defaults.get(d)))
ok = checks[test](_opts, d, value, constraint) ok = checks[test](opts, d, value, constraint)
if _opts.trace(): if opts.trace():
if ok: if ok:
tag = ' ' tag = ' '
else: else:
tag = '*' tag = '*'
_notice(_opts, '%c %15s: %r -> "%s"' % (tag, d, _defaults[d], value)) _notice(opts, '%c %15s: %r -> "%s"' % (tag, d, opts.defaults.get(d), value))
if sane and not ok: if sane and not ok:
sane = False sane = False
@ -135,9 +135,9 @@ def host_setup(_opts, _defaults):
def run(): def run():
import sys import sys
try: try:
_opts, _defaults = defaults.load(args = sys.argv) _opts = options.load(args = sys.argv)
_notice(_opts, 'RTEMS Source Builder - Check, v%s' % (version.str())) _notice(_opts, 'RTEMS Source Builder - Check, v%s' % (version.str()))
if host_setup(_opts, _defaults): if host_setup(_opts):
print 'Environment is ok' print 'Environment is ok'
else: else:
print 'Environment is not correctly set up' print 'Environment is not correctly set up'

View File

@ -1,6 +1,6 @@
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2012 Chris Johns (chrisj@rtems.org) # Copyright 2010-2013 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -31,10 +31,10 @@ import re
import sys import sys
try: try:
import defaults
import error import error
import execute import execute
import log import log
import options
import path import path
except KeyboardInterrupt: except KeyboardInterrupt:
print 'user terminated' print 'user terminated'
@ -207,8 +207,12 @@ class file:
re.compile('%source[0-9]*'), re.compile('%source[0-9]*'),
re.compile('%patch[0-9]*') ] re.compile('%patch[0-9]*') ]
def __init__(self, name, _defaults, opts): def __init__(self, name, opts, macros = None):
self.opts = opts self.opts = opts
if macros is None:
self.macros = opts.defaults
else:
self.macros = macros
if self.opts.trace(): if self.opts.trace():
print 'config: %s' % (name) print 'config: %s' % (name)
self.disable_macro_reassign = False self.disable_macro_reassign = False
@ -216,13 +220,10 @@ class file:
self.wss = re.compile(r'\s+') self.wss = re.compile(r'\s+')
self.tags = re.compile(r':+') self.tags = re.compile(r':+')
self.sf = re.compile(r'%\([^\)]+\)') self.sf = re.compile(r'%\([^\)]+\)')
self.default_defines = {}
for d in _defaults:
self.default_defines[self._label(d)] = _defaults[d][2]
for arg in self.opts.args: for arg in self.opts.args:
if arg.startswith('--with-') or arg.startswith('--without-'): if arg.startswith('--with-') or arg.startswith('--without-'):
label = arg[2:].lower().replace('-', '_') label = arg[2:].lower().replace('-', '_')
self.default_defines[self._label(label)] = label self.macros.define(label)
self._includes = [] self._includes = []
self.load_depth = 0 self.load_depth = 0
self.load(name) self.load(name)
@ -241,7 +242,7 @@ class file:
'\n' + str(self.opts) + \ '\n' + str(self.opts) + \
'\nlines parsed: %d' % (self.lc) + \ '\nlines parsed: %d' % (self.lc) + \
'\nname: ' + self.name + \ '\nname: ' + self.name + \
'\ndefines:\n' + _dict(self.defines) '\nmacros:\n' + str(self.macros)
for _package in self._packages: for _package in self._packages:
s += str(self._packages[_package]) s += str(self._packages[_package])
return s return s
@ -266,6 +267,8 @@ class file:
self.opts.set_dry_run() self.opts.set_dry_run()
def _label(self, name): def _label(self, name):
if name.startswith('%{') and name[-1] is '}':
return name
return '%{' + name.lower() + '}' return '%{' + name.lower() + '}'
def _macro_split(self, s): def _macro_split(self, s):
@ -383,7 +386,7 @@ class file:
# Change the ' ' to '_' because the macros have no spaces. # Change the ' ' to '_' because the macros have no spaces.
# #
n = self._label('with_' + m[7:-1].strip()) n = self._label('with_' + m[7:-1].strip())
if n in self.defines: if n in self.macros:
s = s.replace(m, '1') s = s.replace(m, '1')
else: else:
s = s.replace(m, '0') s = s.replace(m, '0')
@ -401,7 +404,7 @@ class file:
mn = None mn = None
elif m.startswith('%{defined'): elif m.startswith('%{defined'):
n = self._label(m[9:-1].strip()) n = self._label(m[9:-1].strip())
if n in self.defines: if n in self.macros:
s = s.replace(m, '1') s = s.replace(m, '1')
else: else:
s = s.replace(m, '0') s = s.replace(m, '0')
@ -424,9 +427,9 @@ class file:
if mn: if mn:
if m.startswith('%{?'): if m.startswith('%{?'):
istrue = False istrue = False
if mn in self.defines: if mn in self.macros:
# If defined and 0 then it is false. # If defined and 0 then it is false.
istrue = _check_bool(self.defines[mn]) istrue = _check_bool(self.macros[mn])
if istrue is None: if istrue is None:
istrue = True istrue = True
if colon >= 0 and istrue: if colon >= 0 and istrue:
@ -437,8 +440,8 @@ class file:
mn = '%{nil}' mn = '%{nil}'
else: else:
isfalse = True isfalse = True
if mn in self.defines: if mn in self.macros:
istrue = _check_bool(self.defines[mn]) istrue = _check_bool(self.macros[mn])
if istrue is None or istrue == True: if istrue is None or istrue == True:
isfalse = False isfalse = False
if colon >= 0 and isfalse: if colon >= 0 and isfalse:
@ -448,8 +451,8 @@ class file:
else: else:
mn = '%{nil}' mn = '%{nil}'
if mn: if mn:
if mn.lower() in self.defines: if mn.lower() in self.macros:
s = s.replace(m, self.defines[mn.lower()]) s = s.replace(m, self.macros[mn.lower()])
expanded = True expanded = True
elif show_warning: elif show_warning:
self._error("macro '%s' not found" % (mn)) self._error("macro '%s' not found" % (mn))
@ -461,27 +464,27 @@ class file:
else: else:
d = self._label(ls[1]) d = self._label(ls[1])
if self.disable_macro_reassign: if self.disable_macro_reassign:
if (d not in self.defines) or \ if (d not in self.macros) or \
(d in self.defines and len(self.defines[d]) == 0): (d in self.macros and len(self.macros[d]) == 0):
if len(ls) == 2: if len(ls) == 2:
self.defines[d] = '1' self.macros[d] = '1'
else: else:
self.defines[d] = ' '.join([f.strip() for f in ls[2:]]) self.macros[d] = ' '.join([f.strip() for f in ls[2:]])
else: else:
self._warning("macro '%s' already defined" % (d)) self._warning("macro '%s' already defined" % (d))
else: else:
if len(ls) == 2: if len(ls) == 2:
self.defines[d] = '1' self.macros[d] = '1'
else: else:
self.defines[d] = ' '.join([f.strip() for f in ls[2:]]) self.macros[d] = ' '.join([f.strip() for f in ls[2:]])
def _undefine(self, config, ls): def _undefine(self, config, ls):
if len(ls) <= 1: if len(ls) <= 1:
self._warning('invalid macro definition') self._warning('invalid macro definition')
else: else:
mn = self._label(ls[1]) mn = self._label(ls[1])
if mn in self.defines: if mn in self.macros:
del self.defines[mn] del self.macros[mn]
else: else:
self._warning("macro '%s' not defined" % (mn)) self._warning("macro '%s' not defined" % (mn))
@ -703,11 +706,11 @@ class file:
# Check if already defined. Would be by the command line or # Check if already defined. Would be by the command line or
# even a host specific default. # even a host specific default.
# #
if self._label('with_' + ls[1]) not in self.defines: if self._label('with_' + ls[1]) not in self.macros:
self._define(config, (ls[0], 'without_' + ls[1])) self._define(config, (ls[0], 'without_' + ls[1]))
elif ls[0] == '%bcond_without': elif ls[0] == '%bcond_without':
if isvalid: if isvalid:
if self._label('without_' + ls[1]) not in self.defines: if self._label('without_' + ls[1]) not in self.macros:
self._define(config, (ls[0], 'with_' + ls[1])) self._define(config, (ls[0], 'with_' + ls[1]))
else: else:
for r in self._ignore: for r in self._ignore:
@ -755,7 +758,6 @@ class file:
self.in_error = False self.in_error = False
self.lc = 0 self.lc = 0
self.name = name self.name = name
self.defines = copy.deepcopy(self.default_defines)
self.conditionals = {} self.conditionals = {}
self._packages = {} self._packages = {}
self.package = 'main' self.package = 'main'
@ -898,15 +900,15 @@ class file:
self.load_depth -= 1 self.load_depth -= 1
def defined(self, name): def defined(self, name):
return name.lower() in self.defines return self.macros.has_key(name)
def define(self, name): def define(self, name):
if name.lower() in self.defines: if name in self.macros:
d = self.defines[name.lower()] d = self.macros[name]
else: else:
n = self._label(name) n = self._label(name)
if n in self.defines: if n in self.macros:
d = self.defines[n] d = self.macros[n]
else: else:
raise error.general('%d: macro "%s" not found' % (self.lc, name)) raise error.general('%d: macro "%s" not found' % (self.lc, name))
return self._expand(d) return self._expand(d)
@ -922,7 +924,7 @@ class file:
return el return el
return self._expand(line) return self._expand(line)
def default(self, name): def macro(self, name):
if name.lower() in self.defines: if name.lower() in self.defines:
return self.defines[name.lower()] return self.defines[name.lower()]
raise error.general('macro "%s" not found' % (name)) raise error.general('macro "%s" not found' % (name))
@ -947,11 +949,14 @@ class file:
def run(): def run():
import sys import sys
try: try:
opts, _defaults = defaults.load(sys.argv) #
# Run where defaults.mc is located
#
opts = options.load(sys.argv, defaults = 'defaults.mc')
if opts.trace(): if opts.trace():
print 'config: count %d' % (len(opts.config_files())) print 'config: count %d' % (len(opts.config_files()))
for config_file in opts.config_files(): for config_file in opts.config_files():
s = file(config_file, _defaults = _defaults, opts = opts) s = file(config_file, opts)
print s print s
del s del s
except error.general, gerr: except error.general, gerr:

View File

@ -22,7 +22,6 @@
# RTEMS project's spec files. # RTEMS project's spec files.
# #
import pprint
import os import os
import execute import execute
@ -56,4 +55,5 @@ def load():
return defines return defines
if __name__ == '__main__': if __name__ == '__main__':
import pprint
pprint.pprint(load()) pprint.pprint(load())

View File

@ -23,9 +23,9 @@
import os import os
import defaults
import error import error
import execute import execute
import options
import path import path
class repo: class repo:
@ -42,11 +42,14 @@ class repo:
self._git_exit_code(exit_code) self._git_exit_code(exit_code)
return exit_code, output return exit_code, output
def __init__(self, _path, _opts, _defaults): def __init__(self, _path, opts, macros = None):
self.path = _path self.path = _path
self.opts = _opts self.opts = opts
self.default = _defaults if macros is None:
self.git = _opts.expand('%{__git}', _defaults) self.macros = opts.defaults
else:
self.macros = macros
self.git = self.macros.expand('%{__git}')
def git_version(self): def git_version(self):
ec, output = self._run(['--version'], True) ec, output = self._run(['--version'], True)
@ -120,8 +123,8 @@ class repo:
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
_opts, _defaults = defaults.load(sys.argv) opts = options.load(sys.argv)
g = repo('.', _opts, _defaults) g = repo('.', opts)
print g.git_version() print g.git_version()
print g.valid() print g.valid()
print g.status() print g.status()

333
source-builder/sb/macros.py Normal file
View File

@ -0,0 +1,333 @@
#
# RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2013 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.
#
# Macro tables.
#
import re
import os
import string
import error
import path
#
# Macro tables
#
class macros:
class macro_iterator:
def __init__(self, keys):
self.keys = keys
self.index = 0
def __iter__(self):
return self
def next(self):
if self.index < len(self.keys):
key = self.keys[self.index]
self.index += 1
return key
raise StopIteration
def iterkeys(self):
return self.keys
def __init__(self, name = None, original = None, sbdir = '.'):
self.macro_filter = re.compile(r'%{[^}]+}')
if original is None:
self.macros = {}
self.map = 'global'
self.macros[self.map] = {}
self.macros[self.map]['_cwd'] = ('dir', 'required', path.shell(os.getcwd()))
self.macros[self.map]['_sbdir'] = ('dir', 'required', path.shell(sbdir))
else:
self.macros = {}
for m in original.macros:
if m not in self.macros:
self.macros[m] = {}
for k in original.macros[m]:
self.macros[m][k] = original.macros[m][k]
self.map = original.map
if name is not None:
self.load(name)
def __copy__(self):
return macros(original = self)
def __str__(self):
text_len = 80
text = ''
for map in self.macros:
text += '[%s]%s' % (map, os.linesep)
for k in sorted(self.macros[map].keys()):
d = self.macros[map][k]
text += " %s:%s '%s'%s '%s'%s" % \
(k, ' ' * (20 - len(k)),
d[0], ' ' * (8 - len(d[0])),
d[1], ' ' * (10 - len(d[1])))
if len(d[2]) == 0:
text += "''%s" % (os.linesep)
else:
if '\n' in d[2]:
text += "'''"
else:
text += "'"
indent = False
ds = d[2].split('\n')
lc = 0
for l in ds:
lc += 1
while len(l):
if indent:
text += ' %21s %10s %12s' % (' ', ' ', ' ')
text += l[0:text_len]
l = l[text_len:]
if len(l):
text += ' \\'
elif lc == len(ds):
if len(ds) > 1:
text += "'''"
else:
text += "'"
text += '%s' % (os.linesep)
indent = True
return text
def __iter__(self):
return macros.macro_iterator(self.macros[self.map].keys())
def __getitem__(self, key):
macro = self.get(key)
if macro is None:
raise IndexError('key: %s' % (key))
return macro[2]
def __setitem__(self, key, value):
if type(key) is not str:
raise TypeError('bad key type (want str): %s' % (type(key)))
if type(value) is str:
value = ('none', 'none', value)
if type(value) is not tuple:
raise TypeError('bad value type (want tuple): %s' % (type(value)))
if len(value) != 3:
raise TypeError('bad value tuple (len not 3): %d' % (len(value)))
if type(value[0]) is not str:
raise TypeError('bad value tuple type field: %s' % (type(value[0])))
if type(value[1]) is not str:
raise TypeError('bad value tuple attrib field: %s' % (type(value[1])))
if type(value[2]) is not str:
raise TypeError('bad value tuple value field: %s' % (type(value[2])))
if value[0] not in ['none', 'triplet', 'dir', 'file', 'exe']:
raise TypeError('bad value tuple (type field): %s' % (value[0]))
if value[1] not in ['none', 'optional', 'required', 'override']:
raise TypeError('bad value tuple (attrib field): %s' % (value[1]))
self.macros[self.map][self.key_filter(key)] = value
def __delitem__(self, key):
self.undefine(key)
def __contains__(self, key):
return self.has_key(key)
def __len__(self):
return len(self.keys())
def keys(self):
k = self.macros[self.map].keys()
if map is not 'global':
k += self.macros['global'].keys()
return sorted(set(k))
def has_key(self, key):
if type(key) is not str:
raise TypeError('bad key type (want str): %s' % (type(key)))
key = self.key_filter(key)
if key not in self.macros[self.map].keys():
if key not in self.macros['global'].keys():
return False
return True
def key_filter(self, key):
if key.startswith('%{') and key[-1] is '}':
key = key[2:-1]
return key.lower()
def parse(self, lines):
macros = { 'global': {} }
map = 'global'
lc = 0
state = 'key'
token = ''
macro = []
for l in lines:
lc += 1
#print 'l:%s' % (l[:-1])
if len(l) == 0:
continue
for c in l:
#print ']]]]]]]] c:%s(%d) s:%s t:"%s" m:%r M:%s' % (c, ord(c), state, token, macro, map)
if c is '#' and not state.startswith('value'):
break
if c == '\n' or c == '\r':
if not (state is 'key' and len(token) == 0) and \
not state.startswith('value-multiline'):
raise error.general('malformed macro line:%d: %s' % (lc, l))
if state is 'key':
if c not in string.whitespace:
if c is '[':
state = 'map'
elif c is ':':
macro += [token]
token = ''
state = 'attribs'
elif c is '#':
break
else:
token += c
elif state is 'map':
if c is ']':
if token not in macros:
macros[token] = {}
map = token
token = ''
state = 'key'
elif c in string.ascii_letters or c in string.digits:
token += c
else:
raise error.general('invalid macro map:%d: %s' % (lc, l))
elif state is 'attribs':
if c not in string.whitespace:
if c is ',':
macro += [token]
token = ''
if len(macro) == 3:
state = 'value-start'
else:
token += c
elif state is 'value-start':
if c is "'":
state = 'value-line-start'
elif state is 'value-line-start':
if c is "'":
state = 'value-multiline-start'
else:
state = 'value-line'
token += c
elif state is 'value-multiline-start':
if c is "'":
state = 'value-multiline'
else:
macro += [token]
state = 'macro'
elif state is 'value-line':
if c is "'":
macro += [token]
state = 'macro'
else:
token += c
elif state is 'value-multiline':
if c is "'":
state = 'value-multiline-end'
else:
token += c
elif state is 'value-multiline-end':
if c is "'":
state = 'value-multiline-end-end'
else:
state = 'value-multiline'
token += "'" + c
elif state is 'value-multiline-end-end':
if c is "'":
macro += [token]
state = 'macro'
else:
state = 'value-multiline'
token += "''" + c
else:
raise error.internal('bad state: %s' % (state))
if state is 'macro':
macros[map][macro[0]] = (macro[1], macro[2], macro[3])
macro = []
token = ''
state = 'key'
return macros
def load(self, name):
try:
name = self.expand(name)
mc = open(name, 'r')
except IOError, err:
raise error.general('opening macro file: %s' % (path.host(name)))
macros = self.parse(mc)
for m in macros:
for mm in macros[m]:
self.macros[m][mm] = macros[m][mm]
mc.close()
def get(self, key):
if type(key) is not str:
raise TypeError('bad key type: %s' % (type(key)))
key = self.key_filter(key)
if self.map is not 'global'and key in self.macros[self.map]:
return self.macros[self.map][key]
if key in self.macros['global']:
return self.macros['global'][key]
return None
def define(self, key, value = '1'):
if type(key) is not str:
raise TypeError('bad key type: %s' % (type(key)))
self.__setitem__(key, ('none', 'none', value))
def undefine(self, key):
if type(key) is not str:
raise TypeError('bad key type: %s' % (type(key)))
key = self.key_filter(key)
for map in self.macros:
if key in self.macros[map]:
del self.macros[map][key]
def expand(self, _str):
"""Simple basic expander of config file macros."""
expanded = True
while expanded:
expanded = False
for m in self.macro_filter.findall(_str):
name = m[2:-1]
macro = self.get(name)
if macro is None:
raise error.general('cannot expand default macro: %s in "%s"' %
(m, _str))
_str = _str.replace(m, macro[2])
expanded = True
return _str
if __name__ == "__main__":
import copy
import sys
m = macros(name = 'defaults.mc')
d = copy.copy(m)
m['test1'] = 'something'
if d.has_key('test1'):
print 'error: copy failed.'
sys.exit(1)
print m

View File

@ -1,6 +1,6 @@
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2012 Chris Johns (chrisj@rtems.org) # Copyright 2010-2013 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -25,233 +25,21 @@ import glob
import pprint import pprint
import re import re
import os import os
import string
import error import error
import execute import execute
import git import git
import macros
import path import path
import sys import sys
basepath = 'sb' basepath = 'sb'
#
# All paths in defaults must be Unix format. Do not store any Windows format
# paths in the defaults.
#
# Every entry must describe the type of checking a host must pass.
#
defaults = {
# Nothing
'nil': ('none', 'none', ''),
# Set to invalid values.
'_bset': ('none', 'none', ''),
'name': ('none', 'none', ''),
'version': ('none', 'none', ''),
'release': ('none', 'none', ''),
# GNU triples needed to build packages
'_host': ('triplet', 'required', ''),
'_build': ('triplet', 'required', '%{_host}'),
'_target': ('none', 'optional', ''),
# Paths
'_host_platform': ('none', 'none', '%{_host_cpu}-%{_host_vendor}-%{_host_os}%{?_gnu}'),
'_arch': ('none', 'none', '%{_host_arch}'),
'_sbdir': ('none', 'none', ''),
'_topdir': ('dir', 'required', path.shell(os.getcwd())),
'_configdir': ('dir', 'optional', '%{_topdir}/config:%{_sbdir}/config'),
'_tardir': ('dir', 'optional', '%{_topdir}/tar'),
'_sourcedir': ('dir', 'optional', '%{_topdir}/sources'),
'_patchdir': ('dir', 'optional', '%{_topdir}/patches:%{_sbdir}/patches'),
'_builddir': ('dir', 'optional', '%{_topdir}/build/%{name}-%{version}-%{release}'),
'_buildcxcdir': ('dir', 'optional', '%{_topdir}/build/%{name}-%{version}-%{release}-cxc'),
'_docdir': ('dir', 'none', '%{_defaultdocdir}'),
'_tmppath': ('dir', 'none', '%{_topdir}/build/tmp'),
'_tmproot': ('dir', 'none', '%{_tmppath}/source-build-%(%{__id_u} -n)/%{_bset}'),
'_tmpcxcroot': ('dir', 'none', '%{_tmppath}/source-build-%(%{__id_u} -n)-cxc/%{_bset}'),
'buildroot': ('dir', 'none', '%{_tmppath}/%{name}-root-%(%{__id_u} -n)'),
'buildcxcroot': ('dir', 'none', '%{_tmppath}/%{name}-root-%(%{__id_u} -n)-cxc'),
'_datadir': ('dir', 'none', '%{_prefix}/share'),
'_defaultdocdir': ('dir', 'none', '%{_prefix}/share/doc'),
'_exeext': ('none', 'none', ''),
'_exec_prefix': ('dir', 'none', '%{_prefix}'),
'_bindir': ('dir', 'none', '%{_exec_prefix}/bin'),
'_sbindir': ('dir', 'none', '%{_exec_prefix}/sbin'),
'_libexecdir': ('dir', 'none', '%{_exec_prefix}/libexec'),
'_datarootdir': ('dir', 'none', '%{_prefix}/share'),
'_datadir': ('dir', 'none', '%{_datarootdir}'),
'_sysconfdir': ('dir', 'none', '%{_prefix}/etc'),
'_sharedstatedir': ('dir', 'none', '%{_prefix}/com'),
'_localstatedir': ('dir', 'none', '%{prefix}/var'),
'_includedir': ('dir', 'none', '%{_prefix}/include'),
'_lib': ('dir', 'none', 'lib'),
'_libdir': ('dir', 'none', '%{_exec_prefix}/%{_lib}'),
'_libexecdir': ('dir', 'none', '%{_exec_prefix}/libexec'),
'_mandir': ('dir', 'none', '%{_datarootdir}/man'),
'_infodir': ('dir', 'none', '%{_datarootdir}/info'),
'_localedir': ('dir', 'none', '%{_datarootdir}/locale'),
'_localedir': ('dir', 'none', '%{_datadir}/locale'),
'_localstatedir': ('dir', 'none', '%{_prefix}/var'),
'_prefix': ('dir', 'none', '%{_usr}'),
'_usr': ('dir', 'none', '/usr/local'),
'_usrsrc': ('dir', 'none', '%{_usr}/src'),
'_var': ('dir', 'none', '/usr/local/var'),
'_varrun': ('dir', 'none', '%{_var}/run'),
# Defaults, override in platform specific modules.
'___setup_shell': ('exe', 'required', '/bin/sh'),
'__aclocal': ('exe', 'optional', 'aclocal'),
'__ar': ('exe', 'required', 'ar'),
'__arch_install_post': ('exe', 'none', '%{nil}'),
'__as': ('exe', 'required', 'as'),
'__autoconf': ('exe', 'required', 'autoconf'),
'__autoheader': ('exe', 'required', 'autoheader'),
'__automake': ('exe', 'required', 'automake'),
'__awk': ('exe', 'required', 'awk'),
'__bash': ('exe', 'optional', '/bin/bash'),
'__bison': ('exe', 'required', '/usr/bin/bison'),
'__bzip2': ('exe', 'required', '/usr/bin/bzip2'),
'__cat': ('exe', 'required', '/bin/cat'),
'__cc': ('exe', 'required', '/usr/bin/gcc'),
'__chgrp': ('exe', 'required', '/usr/bin/chgrp'),
'__chmod': ('exe', 'required', '/bin/chmod'),
'__chown': ('exe', 'required', '/usr/sbin/chown'),
'__cp': ('exe', 'required', '/bin/cp'),
'__cpp': ('exe', 'none', '%{__cc} -E'),
'__cxx': ('exe', 'required', '/usr/bin/g++'),
'__flex': ('exe', 'required', '/usr/bin/flex'),
'__git': ('exe', 'required', '/usr/bin/git'),
'__grep': ('exe', 'required', '/usr/bin/grep'),
'__gzip': ('exe', 'required', '/usr/bin/gzip'),
'__id': ('exe', 'required', '/usr/bin/id'),
'__id_u': ('exe', 'none', '%{__id} -u'),
'__install': ('exe', 'required', '/usr/bin/install'),
'__install_info': ('exe', 'optional', '/usr/bin/install-info'),
'__ld': ('exe', 'required', '/usr/bin/ld'),
'__ldconfig': ('exe', 'required', '/sbin/ldconfig'),
'__ln_s': ('exe', 'none', 'ln -s'),
'__make': ('exe', 'required', 'make'),
'__makeinfo': ('exe', 'required', '/usr/bin/makeinfo'),
'__mkdir': ('exe', 'required', '/bin/mkdir'),
'__mkdir_p': ('exe', 'none', '/bin/mkdir -p'),
'__mv': ('exe', 'required', '/bin/mv'),
'__nm': ('exe', 'required', '/usr/bin/nm'),
'__objcopy': ('exe', 'optional', '/usr/bin/objcopy'),
'__objdump': ('exe', 'optional', '/usr/bin/objdump'),
'__patch_bin': ('exe', 'required', '/usr/bin/patch'),
'__patch_opts': ('none', 'none', '%{nil}'),
'__patch': ('exe', 'none', '%{__patch_bin} %{__patch_opts}'),
'__perl': ('exe', 'optional', 'perl'),
'__ranlib': ('exe', 'required', 'ranlib'),
'__rm': ('exe', 'required', '/bin/rm'),
'__rmfile': ('exe', 'none', '%{__rm} -f'),
'__rmdir': ('exe', 'none', '%{__rm} -rf'),
'__sed': ('exe', 'required', '/usr/bin/sed'),
'__setup_post': ('exe', 'none', '%{__chmod} -R a+rX,g-w,o-w .'),
'__sh': ('exe', 'required', '/bin/sh'),
'__tar': ('exe', 'required', '/usr/bin/tar'),
'__tar_extract': ('exe', 'none', '%{__tar} -xvvf'),
'__touch': ('exe', 'required', '/usr/bin/touch'),
'__unzip': ('exe', 'required', '/usr/bin/unzip'),
'__xz': ('exe', 'required', '/usr/bin/xz'),
# Shell Build Settings.
'___build_args': ('none', 'none', '-e'),
'___build_cmd': ('none', 'none', '%{?_sudo:%{_sudo} }%{?_remsh:%{_remsh} %{_remhost} }%{?_remsudo:%{_remsudo} }%{?_remchroot:%{_remchroot} %{_remroot} }%{___build_shell} %{___build_args}'),
'___build_post': ('none', 'none', 'exit 0'),
# Prebuild set up script.
'___build_pre': ('none', 'none', '''# ___build_pre in as set up in defaults.py
# Save the original path away.
export SB_ORIG_PATH=${PATH}
# Directories
%{?_prefix:SB_PREFIX="%{_prefix}"}
%{?_prefix:SB_PREFIX_CLEAN=$(echo "%{_prefix}" | %{__sed} -e \'s/^\///\')}
SB_SOURCE_DIR="%{_sourcedir}"
SB_BUILD_DIR="%{_builddir}"
SB_OPT_FLAGS="%{?_tmproot:-I%{_tmproot}/${SB_PREFIX_CLEAN}/include -L%{_tmproot}/${SB_PREFIX_CLEAN}/lib} %{optflags}"
SB_ARCH="%{_arch}"
SB_OS="%{_os}"
export SB_SOURCE_DIR SB_BUILD_DIR SB_OPT_FLAGS SB_ARCH SB_OS
# Documentation
SB_DOC_DIR="%{_docdir}"
export SB_DOC_DIR
# Packages
SB_PACKAGE_NAME="%{name}"
SB_PACKAGE_VERSION="%{version}"
SB_PACKAGE_RELEASE="%{release}"
export SB_PACKAGE_NAME SB_PACKAGE_VERSION SB_PACKAGE_RELEASE
# Build directories
export SB_PREFIX
%{?_builddir:SB_BUILD_DIR="%{_builddir}"}
%{?buildroot:SB_BUILD_ROOT="%{buildroot}"}
%{?buildroot:%{?_prefix:SB_BUILD_ROOT_BINDIR="%{buildroot}/${SB_PREFIX_CLEAN}/bin"}}
export SB_BUILD_ROOT SB_BUILD_DIR SB_BUILD_ROOT_BINDIR
%{?_buildcxcdir:SB_BUILD_CXC_DIR="%{_buildcxcdir}"}
%{?buildcxcroot:SB_BUILD_CXC_ROOT="%{buildcxcroot}"}
%{?buildcxcroot:%{?_prefix:SB_BUILD_CXC_ROOT_BINDIR="%{buildcxcroot}/${SB_PREFIX_CLEAN}/bin"}}
export SB_BUILD_CXC_ROOT SB_BUILD_CXC_DIR SB_BUILD_CXC_ROOT_BINDIR
%{?_tmproot:SB_TMPROOT="%{_tmproot}"}
%{?_tmproot:%{?_prefix:SB_TMPPREFIX="%{_tmproot}/${SB_PREFIX_CLEAN}"}}
%{?_tmproot:%{?_prefix:SB_TMPBINDIR="%{_tmproot}/${SB_PREFIX_CLEAN}/bin"}}
export SB_TMPROOT SB_TMPPREFIX SB_TMPBINDIR
%{?_tmpcxcroot:SB_TMPCXCROOT="%{_tmproot}"}
%{?_tmpcxcroot:%{?_prefix:SB_TMPCXCPREFIX="%{_tmpcxcroot}/${SB_PREFIX_CLEAN}"}}
%{?_tmpcxcroot:%{?_prefix:SB_TMPCXCBINDIR="%{_tmpcxcroot}/${SB_PREFIX_CLEAN}/bin"}}
export SB_TMPCXCROOT SB_TMPCXCPREFIX SB_TMPCXCBINDIR
# The compiler flags
%{?_targetcflags:CFLAGS_FOR_TARGET="%{_targetcflags}"}
%{?_targetcxxflags:CXXFLAGS_FOR_TARGET="%{_targetcxxflags}"}
export CFLAGS_FOR_TARGET
export CXXFLAGS_FOR_TARGET
# Set up the path. Put the CXC path first.
if test -n "${SB_TMPBINDIR}" ; then
PATH="${SB_TMPBINDIR}:$PATH"
fi
if test -n "${SB_TMPCXCBINDIR}" ; then
PATH="${SB_TMPCXCBINDIR}:$PATH"
fi
export PATH
# Default environment set up.
LANG=C
export LANG
unset DISPLAY || :
umask 022
cd "%{_builddir}"'''),
'___build_shell': ('none', 'none', '%{?_buildshell:%{_buildshell}}%{!?_buildshell:/bin/sh}'),
'___build_template': ('none', 'none', '''#!%{___build_shell}
%{___build_pre}
%{nil}'''),
# Configure command
'configure': ('none', 'none', '''
CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ;
CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ;
FFLAGS="${FFLAGS:-%optflags}" ; export FFLAGS ;
./configure --build=%{_build} --host=%{_host} \
--target=%{_target_platform} \
--program-prefix=%{?_program_prefix} \
--prefix=%{_prefix} \
--exec-prefix=%{_exec_prefix} \
--bindir=%{_bindir} \
--sbindir=%{_sbindir} \
--sysconfdir=%{_sysconfdir} \
--datadir=%{_datadir} \
--includedir=%{_includedir} \
--libdir=%{_libdir} \
--libexecdir=%{_libexecdir} \
--localstatedir=%{_localstatedir} \
--sharedstatedir=%{_sharedstatedir} \
--mandir=%{_mandir} \
--infodir=%{_infodir}''')
}
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."""
def __init__(self, argv, optargs): def __init__(self, argv, optargs, _defaults, command_path):
self._long_opts = { self._long_opts = {
# key macro handler param defs init # key macro handler param defs init
'--prefix' : ('_prefix', self._lo_path, True, None, False), '--prefix' : ('_prefix', self._lo_path, True, None, False),
@ -280,21 +68,17 @@ class command_line:
'--help' : (None, self._lo_help, False, None, False) '--help' : (None, self._lo_help, False, None, False)
} }
self.command_path = path.dirname(argv[0]) self.command_path = command_path
if len(self.command_path) == 0:
self.command_path = '.'
self.command_name = path.basename(argv[0]) self.command_name = path.basename(argv[0])
self.argv = argv self.argv = argv
self.args = argv[1:] self.args = argv[1:]
self.optargs = optargs self.optargs = optargs
self.defaults = {} self.defaults = _defaults
self.defaults['_sbdir'] = ('dir', 'required', path.shell(self.command_path))
self.opts = { 'params' : [] } self.opts = { 'params' : [] }
for lo in self._long_opts: for lo in self._long_opts:
self.opts[lo[2:]] = self._long_opts[lo][3] self.opts[lo[2:]] = self._long_opts[lo][3]
if self._long_opts[lo][4]: if self._long_opts[lo][4]:
self.defaults[self._long_opts[lo][0]] = ('none', 'none', self._long_opts[lo][3]) self.defaults[self._long_opts[lo][0]] = ('none', 'none', self._long_opts[lo][3])
self._process()
def __str__(self): def __str__(self):
def _dict(dd): def _dict(dd):
@ -315,14 +99,14 @@ class command_line:
if value is None: if value is None:
raise error.general('option requires a value: %s' % (opt)) raise error.general('option requires a value: %s' % (opt))
self.opts[opt[2:]] = value self.opts[opt[2:]] = value
self.defaults[macro] = ('none', 'none', value) self.defaults[macro] = value
def _lo_path(self, opt, macro, value): def _lo_path(self, opt, macro, value):
if value is None: if value is None:
raise error.general('option requires a path: %s' % (opt)) raise error.general('option requires a path: %s' % (opt))
value = path.shell(value) value = path.shell(value)
self.opts[opt[2:]] = value self.opts[opt[2:]] = value
self.defaults[macro] = ('none', 'none', value) self.defaults[macro] = value
def _lo_jobs(self, opt, macro, value): def _lo_jobs(self, opt, macro, value):
if value is None: if value is None:
@ -344,14 +128,14 @@ class command_line:
pass pass
if not ok: if not ok:
raise error.general('invalid jobs option: %s' % (value)) raise error.general('invalid jobs option: %s' % (value))
self.defaults[macro] = ('none', 'none', value) self.defaults[macro] = value
self.opts[opt[2:]] = value self.opts[opt[2:]] = value
def _lo_bool(self, opt, macro, value): def _lo_bool(self, opt, macro, value):
if value is not None: if value is not None:
raise error.general('option does not take a value: %s' % (opt)) raise error.general('option does not take a value: %s' % (opt))
self.opts[opt[2:]] = '1' self.opts[opt[2:]] = '1'
self.defaults[macro] = ('none', 'none', '1') self.defaults[macro] = '1'
def _lo_triplets(self, opt, macro, value): def _lo_triplets(self, opt, macro, value):
# #
@ -383,15 +167,15 @@ class command_line:
value = value[dash + 1:] value = value[dash + 1:]
if len(value): if len(value):
_os_value = value _os_value = value
self.defaults[_cpu] = ('none', 'none', _arch_value) self.defaults[_cpu] = _arch_value
self.defaults[_arch] = ('none', 'none', _arch_value) self.defaults[_arch] = _arch_value
self.defaults[_vendor] = ('none', 'none', _vendor_value) self.defaults[_vendor] = _vendor_value
self.defaults[_os] = ('none', 'none', _os_value) self.defaults[_os] = _os_value
def _lo_help(self, opt, macro, value): def _lo_help(self, opt, macro, value):
self.help() self.help()
def _help(self): def help(self):
print '%s: [options] [args]' % (self.command_name) print '%s: [options] [args]' % (self.command_name)
print 'RTEMS Source Builder, an RTEMS Tools Project (c) 2012-2013 Chris Johns' print 'RTEMS Source Builder, an RTEMS Tools Project (c) 2012-2013 Chris Johns'
print 'Options and arguments:' print 'Options and arguments:'
@ -424,12 +208,12 @@ class command_line:
print '%-22s : %s' % (a, self.optargs[a]) print '%-22s : %s' % (a, self.optargs[a])
raise error.exit() raise error.exit()
def _process(self): def process(self):
arg = 0 arg = 0
while arg < len(self.args): while arg < len(self.args):
a = self.args[arg] a = self.args[arg]
if a == '-?': if a == '-?':
self._help() self.help()
elif a.startswith('--'): elif a.startswith('--'):
los = a.split('=') los = a.split('=')
lo = los[0] lo = los[0]
@ -450,40 +234,16 @@ class command_line:
self.opts['params'].append(a) self.opts['params'].append(a)
arg += 1 arg += 1
def _post_process(self, _defaults): def post_process(self):
if _defaults['_host'][2] == _defaults['nil'][2]: if self.defaults['_host'] == self.defaults['nil']:
raise error.general('host not set') raise error.general('host not set')
if '_ncpus' not in _defaults: if '_ncpus' not in self.defaults:
raise error.general('host number of CPUs not set') raise error.general('host number of CPUs not set')
ncpus = self.jobs(_defaults['_ncpus'][2]) ncpus = self.jobs(self.defaults['_ncpus'])
if ncpus > 1: if ncpus > 1:
_defaults['_smp_mflags'] = ('none', 'none', '-j %d' % (ncpus)) self.defaults['_smp_mflags'] = '-j %d' % (ncpus)
else: else:
_defaults['_smp_mflags'] = ('none', 'none', _defaults['nil'][2]) self.defaults['_smp_mflags'] = self.defaults['nil']
return _defaults
def define(self, _defaults, key, value = '1'):
_defaults[key] = ('none', 'none', value)
def undefine(self, _defaults, key):
if key in _defaults:
del _defaults[key]
def expand(self, s, _defaults):
"""Simple basic expander of config file macros."""
mf = re.compile(r'%{[^}]+}')
expanded = True
while expanded:
expanded = False
for m in mf.findall(s):
name = m[2:-1]
if name in _defaults:
s = s.replace(m, _defaults[name][2])
expanded = True
else:
raise error.general('cannot expand default macro: %s in "%s"' %
(m, s))
return s
def command(self): def command(self):
return path.join(self.command_path, self.command_name) return path.join(self.command_path, self.command_name)
@ -573,7 +333,7 @@ class command_line:
if not configbase.endswith('.cfg'): if not configbase.endswith('.cfg'):
configbase = configbase + '.cfg' configbase = configbase + '.cfg'
if len(configdir) == 0: if len(configdir) == 0:
configdir = self.expand(self.defaults['_configdir'][2], self.defaults) configdir = self.macros.expand(self.defaults['_configdir'])
configs = [] configs = []
for cp in configdir.split(':'): for cp in configdir.split(':'):
hostconfigdir = path.host(cp) hostconfigdir = path.host(cp)
@ -590,7 +350,7 @@ class command_line:
return configs return configs
def logfiles(self): def logfiles(self):
if 'log' in self.opts: if 'log' in self.opts and self.opts['log'] is not None:
return self.opts['log'].split(',') return self.opts['log'].split(',')
return ['stdout'] return ['stdout']
@ -599,15 +359,31 @@ class command_line:
return self.opts['url'].split(',') return self.opts['url'].split(',')
return None return None
def load(args, optargs = None): def load(args, optargs = None, defaults = '%{_sbdir}/defaults.mc'):
""" """
Copy the defaults, get the host specific values and merge them overriding Copy the defaults, get the host specific values and merge them overriding
any matching defaults, then create an options object to handle the command any matching defaults, then create an options object to handle the command
line merging in any command line overrides. Finally post process the line merging in any command line overrides. Finally post process the
command line. command line.
""" """
import copy
d = copy.copy(defaults) #
# The path to this command.
#
command_path = path.dirname(args[0])
if len(command_path) == 0:
command_path = '.'
#
# The command line contains the base defaults object all build objects copy
# and modify by loading a configuration.
#
o = command_line(args,
optargs,
macros.macros(name = defaults,
sbdir = command_path),
command_path)
overrides = None overrides = None
if os.name == 'nt': if os.name == 'nt':
import windows import windows
@ -634,12 +410,12 @@ def load(args, optargs = None):
if overrides is None: if overrides is None:
raise error.general('no hosts defaults found; please add') raise error.general('no hosts defaults found; please add')
for k in overrides: for k in overrides:
d[k] = overrides[k] o.defaults[k] = overrides[k]
o = command_line(args, optargs)
for k in o.defaults: o.process()
d[k] = o.defaults[k] o.post_process()
d = o._post_process(d)
repo = git.repo(o.expand('%{_sbdir}', d), o, d) repo = git.repo(o.defaults.expand('%{_sbdir}'), o)
if repo.valid(): if repo.valid():
repo_valid = '1' repo_valid = '1'
repo_head = repo.head() repo_head = repo.head()
@ -652,35 +428,19 @@ def load(args, optargs = None):
repo_head = '%{nil}' repo_head = '%{nil}'
repo_clean = '%{nil}' repo_clean = '%{nil}'
repo_id = 'no-repo' repo_id = 'no-repo'
o.define(d, '_sbgit_valid', repo_valid) o.defaults['_sbgit_valid'] = repo_valid
o.define(d, '_sbgit_head', repo_head) o.defaults['_sbgit_head'] = repo_head
o.define(d, '_sbgit_clean', str(repo_clean)) o.defaults['_sbgit_clean'] = str(repo_clean)
o.define(d, '_sbgit_id', repo_id) o.defaults['_sbgit_id'] = repo_id
return o, d return o
def run(args): def run(args):
try: try:
_opts, _defaults = load(args = args) _opts = load(args = args)
print 'Options:' print 'Options:'
print _opts print _opts
print 'Defaults:' print 'Defaults:'
for k in sorted(_defaults.keys()): print _opts.defaults
d = _defaults[k]
print '%-20s: %-8s %-10s' % (k, d[0], d[1]),
indent = False
if len(d[2]) == 0:
print
text_len = 80
for l in d[2].split('\n'):
while len(l):
if indent:
print '%20s %8s %10s' % (' ', ' ', ' '),
print l[0:text_len],
l = l[text_len:]
if len(l):
print ' \\',
print
indent = True
except error.general, gerr: except error.general, gerr:
print gerr print gerr
sys.exit(1) sys.exit(1)

View File

@ -31,10 +31,10 @@ try:
import build import build
import check import check
import config import config
import defaults
import error import error
import git import git
import log import log
import options
import path import path
import setbuilder import setbuilder
import version import version
@ -56,18 +56,21 @@ class report:
line_len = 78 line_len = 78
def __init__(self, format, _configs, _defaults, opts): def __init__(self, format, _configs, opts, macros = None):
self.format = format self.format = format
self.configs = _configs self.configs = _configs
self.defaults = _defaults
self.opts = opts self.opts = opts
if macros is None:
self.macros = opts.defaults
else:
self.macros = macros
self.bset_nesting = 0 self.bset_nesting = 0
self.configs_active = False self.configs_active = False
self.out = '' self.out = ''
self.asciidoc = None self.asciidoc = None
def _sbpath(self, *args): def _sbpath(self, *args):
p = self.opts.expand('%{_sbdir}', self.defaults) p = self.macros.expand('%{_sbdir}')
for arg in args: for arg in args:
p = path.join(p, arg) p = path.join(p, arg)
return os.path.abspath(path.host(p)) return os.path.abspath(path.host(p))
@ -87,7 +90,7 @@ class report:
import asciidocapi import asciidocapi
except: except:
raise error.general('installation error: no asciidocapi found') raise error.general('installation error: no asciidocapi found')
asciidoc_py = self._sbpath(defaults.basepath, 'asciidoc', 'asciidoc.py') asciidoc_py = self._sbpath(options.basepath, 'asciidoc', 'asciidoc.py')
try: try:
self.asciidoc = asciidocapi.AsciiDocAPI(asciidoc_py) self.asciidoc = asciidocapi.AsciiDocAPI(asciidoc_py)
except: except:
@ -109,7 +112,7 @@ class report:
else: else:
self.output('-' * self.line_len) self.output('-' * self.line_len)
self.output('%s' % (text)) self.output('%s' % (text))
repo = git.repo('.', self.opts, self.defaults) repo = git.repo('.', self.opts, self.macros)
repo_valid = repo.valid() repo_valid = repo.valid()
if repo_valid: if repo_valid:
if self.is_asciidoc(): if self.is_asciidoc():
@ -172,7 +175,7 @@ class report:
self.output('RTEMS Tools Project <rtems-users@rtems.org>') self.output('RTEMS Tools Project <rtems-users@rtems.org>')
self.output(datetime.datetime.now().ctime()) self.output(datetime.datetime.now().ctime())
self.output('') self.output('')
image = self._sbpath(defaults.basepath, 'images', 'rtemswhitebg.jpg') image = self._sbpath(options.basepath, 'images', 'rtemswhitebg.jpg')
self.output('image:%s["RTEMS",width="20%%"]' % (image)) self.output('image:%s["RTEMS",width="20%%"]' % (image))
self.output('') self.output('')
if intro_text: if intro_text:
@ -248,9 +251,9 @@ class report:
if self.is_asciidoc(): if self.is_asciidoc():
self.output('--------------------------------------------') self.output('--------------------------------------------')
def config(self, configname, _defaults, _opts): def config(self, configname, opts, macros):
_config = config.file(configname, _defaults = _defaults, opts = _opts) _config = config.file(configname, opts, macros)
packages = _config.packages() packages = _config.packages()
package = packages['main'] package = packages['main']
name = package.name() name = package.name()
@ -308,17 +311,14 @@ class report:
def buildset(self, name): def buildset(self, name):
self.bset_nesting += 1 self.bset_nesting += 1
self.buildset_start(name) self.buildset_start(name)
_opts = copy.copy(self.opts) opts = copy.copy(self.opts)
_defaults = copy.copy(self.defaults) macros = copy.copy(self.macros)
bset = setbuilder.buildset(name, bset = setbuilder.buildset(name, self.configs, opts, macros)
_configs = self.configs,
_defaults = _defaults,
opts = _opts)
for c in bset.load(): for c in bset.load():
if c.endswith('.bset'): if c.endswith('.bset'):
self.buildset(c) self.buildset(c)
elif c.endswith('.cfg'): elif c.endswith('.cfg'):
self.config(c, _defaults, _opts) self.config(c, opts, macros)
else: else:
raise error.general('invalid config type: %s' % (c)) raise error.general('invalid config type: %s' % (c))
self.buildset_end(name) self.buildset_end(name)
@ -352,7 +352,7 @@ class report:
if config.endswith('.bset'): if config.endswith('.bset'):
self.buildset(config) self.buildset(config)
elif config.endswith('.cfg'): elif config.endswith('.cfg'):
self.config(config, self.defaults, self.opts) self.config(config, self.opts, self.macros)
else: else:
raise error.general('invalid config type: %s' % (config)) raise error.general('invalid config type: %s' % (config))
self.generate(outname) self.generate(outname)
@ -363,14 +363,14 @@ def run(args):
'--list-configs': 'List available configurations', '--list-configs': 'List available configurations',
'--format': 'Output format (text, html, asciidoc)', '--format': 'Output format (text, html, asciidoc)',
'--output': 'File name to output the report' } '--output': 'File name to output the report' }
opts, _defaults = defaults.load(args, optargs) opts = options.load(args, optargs)
log.default = log.log(opts.logfiles()) log.default = log.log(opts.logfiles())
if opts.get_arg('--output') and len(opts.params()) > 1: if opts.get_arg('--output') and len(opts.params()) > 1:
raise error.general('--output can only be used with a single config') raise error.general('--output can only be used with a single config')
print 'RTEMS Source Builder, Reporter v%s' % (version.str()) print 'RTEMS Source Builder, Reporter v%s' % (version.str())
if not check.host_setup(opts, _defaults): if not check.host_setup(opts):
_notice(opts, 'warning: forcing build with known host setup problems') _notice(opts, 'warning: forcing build with known host setup problems')
configs = build.get_configs(opts, _defaults) configs = build.get_configs(opts)
if not setbuilder.list_bset_cfg_files(opts, configs): if not setbuilder.list_bset_cfg_files(opts, configs):
output = opts.get_arg('--output') output = opts.get_arg('--output')
if output is not None: if output is not None:
@ -391,13 +391,11 @@ def run(args):
ext = '.html' ext = '.html'
else: else:
raise error.general('invalid format: %s' % (format_opt[1])) raise error.general('invalid format: %s' % (format_opt[1]))
r = report(format = format, r = report(format, configs, opts)
_configs = configs,
_defaults = _defaults,
opts = opts)
for _config in opts.params(): for _config in opts.params():
if output is None: if output is None:
outname = path.splitext(_config)[0] + ext outname = path.splitext(_config)[0] + ext
outname = outname.replace('/', '-')
else: else:
outname = output outname = output
r.make(_config, outname) r.make(_config, outname)

View File

@ -33,9 +33,9 @@ import sys
try: try:
import build import build
import check import check
import defaults
import error import error
import log import log
import options
import path import path
import reports import reports
import version import version
@ -59,14 +59,16 @@ def _notice(opts, text):
class buildset: class buildset:
"""Build a set builds a set of packages.""" """Build a set builds a set of packages."""
def __init__(self, bset, _configs, _defaults, opts): def __init__(self, bset, _configs, opts, macros = None):
_trace(opts, '_bset:%s: init' % (bset)) _trace(opts, '_bset:%s: init' % (bset))
self.configs = _configs self.configs = _configs
self.opts = opts self.opts = opts
self.defaults = _defaults if macros is None:
self.macros = copy.copy(opts.defaults)
else:
self.macros = copy.copy(macros)
self.bset = bset self.bset = bset
self.bset_pkg = '%s-%s-set' % (self.opts.expand('%{_target}', _defaults), self.bset_pkg = '%s-%s-set' % (self.macros.expand('%{_target}'), self.bset)
self.bset)
def _output(self, text): def _output(self, text):
if not self.opts.quiet(): if not self.opts.quiet():
@ -87,8 +89,8 @@ class buildset:
raise error.general('copying tree: %s' % (str(err))) raise error.general('copying tree: %s' % (str(err)))
def report(self, _config, _build): def report(self, _config, _build):
if not self.opts.get_arg('--no-report'): if not _build.opts.get_arg('--no-report'):
format = self.opts.get_arg('--report-format') format = _build.opts.get_arg('--report-format')
if format is None: if format is None:
format = 'html' format = 'html'
ext = '.html' ext = '.html'
@ -107,14 +109,14 @@ class buildset:
else: else:
raise error.general('invalid report format: %s' % (format[1])) raise error.general('invalid report format: %s' % (format[1]))
buildroot = _build.config.abspath('%{buildroot}') buildroot = _build.config.abspath('%{buildroot}')
prefix = self.opts.expand('%{_prefix}', self.defaults) prefix = _build.macros.expand('%{_prefix}')
name = _build.main_package().name() + ext name = _build.main_package().name() + ext
outpath = path.host(path.join(buildroot, prefix, 'share', 'rtems-source-builder')) outpath = path.host(path.join(buildroot, prefix, 'share', 'rtems-source-builder'))
outname = path.host(path.join(outpath, name)) outname = path.host(path.join(outpath, name))
_notice(self.opts, 'reporting: %s -> %s' % (_config, name)) _notice(self.opts, 'reporting: %s -> %s' % (_config, name))
if not self.opts.dry_run(): if not _build.opts.dry_run():
_build.mkdir(outpath) _build.mkdir(outpath)
r = reports.report(format, self.configs, self.defaults, self.opts) r = reports.report(format, self.configs, _build.opts, _build.macros)
r.make(_config, outname) r.make(_config, outname)
del r del r
@ -134,23 +136,24 @@ class buildset:
self.copy(src, dst) self.copy(src, dst)
def canadian_cross(self, _build): def canadian_cross(self, _build):
defaults_to_save = ['%{_prefix}', # @fixme Switch to using a private macros map.
'%{_tmproot}', macros_to_save = ['%{_prefix}',
'%{buildroot}', '%{_tmproot}',
'%{_builddir}', '%{buildroot}',
'%{_host}'] '%{_builddir}',
defaults_to_copy = [('%{_host}', '%{_build}'), '%{_host}']
('%{_tmproot}', '%{_tmpcxcroot}'), macros_to_copy = [('%{_host}', '%{_build}'),
('%{buildroot}', '%{buildcxcroot}'), ('%{_tmproot}', '%{_tmpcxcroot}'),
('%{_builddir}', '%{_buildcxcdir}')] ('%{buildroot}', '%{buildcxcroot}'),
orig_defaults = {} ('%{_builddir}', '%{_buildcxcdir}')]
for d in defaults_to_save: orig_macros = {}
orig_defaults[d] = _build.config.default(d) for m in macros_to_save:
for d in defaults_to_copy: orig_macros[m] = _build.config.macro(m)
_build.config.set_define(d[0], _build.config.default(d[1])) for m in macros_to_copy:
_build.config.set_define(m[0], _build.config.macro(m[1]))
_build.make() _build.make()
for d in defaults_to_save: for m in macris_to_save:
_build.config.set_define(d, orig_defaults[d]) _build.config.set_define(m, orig_macros[m])
self.root_copy(_build.config.expand('%{buildcxcroot}'), self.root_copy(_build.config.expand('%{buildcxcroot}'),
_build.config.expand('%{_tmpcxcroot}')) _build.config.expand('%{_tmpcxcroot}'))
@ -186,7 +189,7 @@ class buildset:
bsetname = bset bsetname = bset
if not path.exists(bsetname): if not path.exists(bsetname):
for cp in self.opts.expand('%{_configdir}', self.defaults).split(':'): for cp in self.macros.expand('%{_configdir}').split(':'):
configdir = path.abspath(cp) configdir = path.abspath(cp)
bsetname = path.join(configdir, bset) bsetname = path.join(configdir, bset)
if path.exists(bsetname): if path.exists(bsetname):
@ -214,20 +217,19 @@ class buildset:
print '%03d: %s' % (lc, l) print '%03d: %s' % (lc, l)
ls = l.split() ls = l.split()
if ls[0][-1] == ':' and ls[0][:-1] == 'package': if ls[0][-1] == ':' and ls[0][:-1] == 'package':
self.bset_pkg = self.opts.expand(ls[1].strip(), self.defaults) self.bset_pkg = self.macros.expand(ls[1].strip())
self.defaults['package'] = ('none', 'none', self.bset_pkg) self.macros['package'] = self.bset_pkg
elif ls[0][0] == '%': elif ls[0][0] == '%':
if ls[0] == '%define': if ls[0] == '%define':
if len(ls) > 2: if len(ls) > 2:
self.opts.define(self.defaults, self.macros.define(ls[1].strip(),
ls[1].strip(), ' '.join([f.strip() for f in ls[2:]]))
' '.join([f.strip() for f in ls[2:]]))
else: else:
self.opts.define(self.defaults, ls[1].strip()) self.macros.define(ls[1].strip())
elif ls[0] == '%undefine': elif ls[0] == '%undefine':
if len(ls) > 2: if len(ls) > 2:
raise error.general('%undefine requires just the name') raise error.general('%undefine requires just the name')
self.opts.undefine(self.defaults, ls[1].strip()) self.macros.undefine(ls[1].strip())
elif ls[0] == '%include': elif ls[0] == '%include':
configs += self.parse(ls[1].strip()) configs += self.parse(ls[1].strip())
else: else:
@ -248,9 +250,9 @@ class buildset:
def load(self): def load(self):
exbset = self.opts.expand(self.bset, self.defaults) exbset = self.macros.expand(self.bset)
self.defaults['_bset'] = ('none', 'none', exbset) self.macros['_bset'] = exbset
root, ext = path.splitext(exbset) root, ext = path.splitext(exbset)
@ -280,23 +282,18 @@ class buildset:
try: try:
# #
# Each section of the build set gets a separate set of # Each section of the build set gets a separate set of
# defaults so we do not contaminate one configuration with # macros so we do not contaminate one configuration with
# another. # another.
# #
_opts = copy.copy(self.opts) opts = copy.copy(self.opts)
_defaults = copy.copy(self.defaults) macros = copy.copy(self.macros)
if configs[s].endswith('.bset'): if configs[s].endswith('.bset'):
bs = buildset(configs[s], bs = buildset(configs[s], self.configs, opts, macros)
_configs = self.configs,
_defaults = _defaults,
opts = _opts)
bs.build(deps) bs.build(deps)
del bs del bs
elif configs[s].endswith('.cfg'): elif configs[s].endswith('.cfg'):
b = build.build(configs[s], b = build.build(configs[s], self.opts.get_arg('--pkg-tar-files'),
self.opts.get_arg('--pkg-tar-files'), opts, macros)
_defaults = _defaults,
opts = _opts)
if deps is None: if deps is None:
self.build_package(configs[s], b) self.build_package(configs[s], b)
if s == len(configs) - 1: if s == len(configs) - 1:
@ -360,19 +357,19 @@ def run():
'--report-format': 'The report format (text, html, asciidoc).', '--report-format': 'The report format (text, html, asciidoc).',
'--bset-tar-file': 'Create a build set tar file', '--bset-tar-file': 'Create a build set tar file',
'--pkg-tar-files': 'Create package tar files' } '--pkg-tar-files': 'Create package tar files' }
opts, _defaults = defaults.load(sys.argv, optargs) opts = options.load(sys.argv, optargs)
log.default = log.log(opts.logfiles()) log.default = log.log(opts.logfiles())
_notice(opts, 'RTEMS Source Builder - Set Builder, v%s' % (version.str())) _notice(opts, 'RTEMS Source Builder - Set Builder, v%s' % (version.str()))
if not check.host_setup(opts, _defaults): if not check.host_setup(opts):
raise error.general('host build environment is not set up correctly') raise error.general('host build environment is not set up correctly')
configs = build.get_configs(opts, _defaults) configs = build.get_configs(opts)
if opts.get_arg('--list-deps'): if opts.get_arg('--list-deps'):
deps = [] deps = []
else: else:
deps = None deps = None
if not list_bset_cfg_files(opts, configs): if not list_bset_cfg_files(opts, configs):
for bset in opts.params(): for bset in opts.params():
b = buildset(bset, _configs = configs, _defaults = _defaults, opts = opts) b = buildset(bset, configs, opts)
b.build(deps) b.build(deps)
del b del b
if deps is not None: if deps is not None: