mirror of
https://git.rtems.org/rtems-source-builder
synced 2024-10-09 07:15:10 +08:00
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:
parent
530a9385a7
commit
cb12e4875c
242
source-builder/defaults.mc
Normal file
242
source-builder/defaults.mc
Normal 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}'''
|
@ -22,8 +22,8 @@ import sys, os
|
||||
base = os.path.dirname(sys.argv[0])
|
||||
sys.path.insert(0, base + '/sb')
|
||||
try:
|
||||
import defaults
|
||||
defaults.run(sys.argv)
|
||||
import options
|
||||
options.run(sys.argv)
|
||||
except ImportError:
|
||||
print >> sys.stderr, "Incorrect Defaults installation"
|
||||
sys.exit(1)
|
||||
|
@ -34,10 +34,10 @@ import urlparse
|
||||
try:
|
||||
import check
|
||||
import config
|
||||
import defaults
|
||||
import error
|
||||
import execute
|
||||
import log
|
||||
import options
|
||||
import path
|
||||
import version
|
||||
except KeyboardInterrupt:
|
||||
@ -99,11 +99,15 @@ class script:
|
||||
class build:
|
||||
"""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
|
||||
if macros is None:
|
||||
self.macros = opts.defaults
|
||||
else:
|
||||
self.macros = macros
|
||||
self.create_tar_files = create_tar_files
|
||||
_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())
|
||||
|
||||
def _output(self, text):
|
||||
@ -481,7 +485,7 @@ class build:
|
||||
package = packages['main']
|
||||
return package.name()
|
||||
|
||||
def get_configs(opts, _defaults):
|
||||
def get_configs(opts):
|
||||
|
||||
def _scan(_path, ext):
|
||||
configs = []
|
||||
@ -494,7 +498,7 @@ def get_configs(opts, _defaults):
|
||||
return configs
|
||||
|
||||
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))
|
||||
configs['paths'] += [hcp]
|
||||
configs['files'] += _scan(hcp, ['.cfg', '.bset'])
|
||||
@ -516,16 +520,16 @@ def find_config(config, configs):
|
||||
def run(args):
|
||||
try:
|
||||
optargs = { '--list-configs': 'List available configurations' }
|
||||
opts, _defaults = defaults.load(args, optargs)
|
||||
opts = options.load(args, optargs)
|
||||
log.default = log.log(opts.logfiles())
|
||||
_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():
|
||||
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')
|
||||
if opts.get_arg('--list-configs'):
|
||||
configs = get_configs(opts, _defaults)
|
||||
configs = get_configs(opts)
|
||||
for p in configs['paths']:
|
||||
print 'Examining: %s' % (os.path.relpath(p))
|
||||
for c in configs['files']:
|
||||
@ -533,7 +537,7 @@ def run(args):
|
||||
print ' %s' % (c)
|
||||
else:
|
||||
for config_file in opts.config_files():
|
||||
b = build(config_file, True, _defaults = _defaults, opts = opts)
|
||||
b = build(config_file, True, opts)
|
||||
b.make()
|
||||
del b
|
||||
except error.general, gerr:
|
||||
|
@ -23,10 +23,10 @@
|
||||
|
||||
import os
|
||||
|
||||
import defaults
|
||||
import error
|
||||
import execute
|
||||
import log
|
||||
import options
|
||||
import path
|
||||
import version
|
||||
|
||||
@ -100,7 +100,7 @@ def _check_paths(name, paths):
|
||||
return True
|
||||
return False
|
||||
|
||||
def host_setup(_opts, _defaults):
|
||||
def host_setup(opts):
|
||||
""" Basic sanity check. All executables and directories must exist."""
|
||||
|
||||
checks = { 'none': _check_none,
|
||||
@ -110,22 +110,22 @@ def host_setup(_opts, _defaults):
|
||||
|
||||
sane = True
|
||||
|
||||
for d in sorted(_defaults.iterkeys()):
|
||||
for d in opts.defaults.keys():
|
||||
try:
|
||||
(test, constraint, value) = _defaults[d]
|
||||
(test, constraint, value) = opts.defaults.get(d)
|
||||
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':
|
||||
value = _opts.expand(value, _defaults)
|
||||
value = opts.defaults.expand(value)
|
||||
if test not in checks:
|
||||
raise error.general('invalid check test: %s [%r]' % (test, _defaults[d]))
|
||||
ok = checks[test](_opts, d, value, constraint)
|
||||
if _opts.trace():
|
||||
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, _defaults[d], value))
|
||||
_notice(opts, '%c %15s: %r -> "%s"' % (tag, d, opts.defaults.get(d), value))
|
||||
if sane and not ok:
|
||||
sane = False
|
||||
|
||||
@ -135,9 +135,9 @@ def host_setup(_opts, _defaults):
|
||||
def run():
|
||||
import sys
|
||||
try:
|
||||
_opts, _defaults = defaults.load(args = sys.argv)
|
||||
_opts = options.load(args = sys.argv)
|
||||
_notice(_opts, 'RTEMS Source Builder - Check, v%s' % (version.str()))
|
||||
if host_setup(_opts, _defaults):
|
||||
if host_setup(_opts):
|
||||
print 'Environment is ok'
|
||||
else:
|
||||
print 'Environment is not correctly set up'
|
||||
|
@ -1,6 +1,6 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# This file is part of the RTEMS Tools package in 'rtems-tools'.
|
||||
@ -31,10 +31,10 @@ import re
|
||||
import sys
|
||||
|
||||
try:
|
||||
import defaults
|
||||
import error
|
||||
import execute
|
||||
import log
|
||||
import options
|
||||
import path
|
||||
except KeyboardInterrupt:
|
||||
print 'user terminated'
|
||||
@ -207,8 +207,12 @@ class file:
|
||||
re.compile('%source[0-9]*'),
|
||||
re.compile('%patch[0-9]*') ]
|
||||
|
||||
def __init__(self, name, _defaults, opts):
|
||||
def __init__(self, name, opts, macros = None):
|
||||
self.opts = opts
|
||||
if macros is None:
|
||||
self.macros = opts.defaults
|
||||
else:
|
||||
self.macros = macros
|
||||
if self.opts.trace():
|
||||
print 'config: %s' % (name)
|
||||
self.disable_macro_reassign = False
|
||||
@ -216,13 +220,10 @@ class file:
|
||||
self.wss = re.compile(r'\s+')
|
||||
self.tags = 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:
|
||||
if arg.startswith('--with-') or arg.startswith('--without-'):
|
||||
label = arg[2:].lower().replace('-', '_')
|
||||
self.default_defines[self._label(label)] = label
|
||||
self.macros.define(label)
|
||||
self._includes = []
|
||||
self.load_depth = 0
|
||||
self.load(name)
|
||||
@ -241,7 +242,7 @@ class file:
|
||||
'\n' + str(self.opts) + \
|
||||
'\nlines parsed: %d' % (self.lc) + \
|
||||
'\nname: ' + self.name + \
|
||||
'\ndefines:\n' + _dict(self.defines)
|
||||
'\nmacros:\n' + str(self.macros)
|
||||
for _package in self._packages:
|
||||
s += str(self._packages[_package])
|
||||
return s
|
||||
@ -266,6 +267,8 @@ class file:
|
||||
self.opts.set_dry_run()
|
||||
|
||||
def _label(self, name):
|
||||
if name.startswith('%{') and name[-1] is '}':
|
||||
return name
|
||||
return '%{' + name.lower() + '}'
|
||||
|
||||
def _macro_split(self, s):
|
||||
@ -383,7 +386,7 @@ class file:
|
||||
# Change the ' ' to '_' because the macros have no spaces.
|
||||
#
|
||||
n = self._label('with_' + m[7:-1].strip())
|
||||
if n in self.defines:
|
||||
if n in self.macros:
|
||||
s = s.replace(m, '1')
|
||||
else:
|
||||
s = s.replace(m, '0')
|
||||
@ -401,7 +404,7 @@ class file:
|
||||
mn = None
|
||||
elif m.startswith('%{defined'):
|
||||
n = self._label(m[9:-1].strip())
|
||||
if n in self.defines:
|
||||
if n in self.macros:
|
||||
s = s.replace(m, '1')
|
||||
else:
|
||||
s = s.replace(m, '0')
|
||||
@ -424,9 +427,9 @@ class file:
|
||||
if mn:
|
||||
if m.startswith('%{?'):
|
||||
istrue = False
|
||||
if mn in self.defines:
|
||||
if mn in self.macros:
|
||||
# If defined and 0 then it is false.
|
||||
istrue = _check_bool(self.defines[mn])
|
||||
istrue = _check_bool(self.macros[mn])
|
||||
if istrue is None:
|
||||
istrue = True
|
||||
if colon >= 0 and istrue:
|
||||
@ -437,8 +440,8 @@ class file:
|
||||
mn = '%{nil}'
|
||||
else:
|
||||
isfalse = True
|
||||
if mn in self.defines:
|
||||
istrue = _check_bool(self.defines[mn])
|
||||
if mn in self.macros:
|
||||
istrue = _check_bool(self.macros[mn])
|
||||
if istrue is None or istrue == True:
|
||||
isfalse = False
|
||||
if colon >= 0 and isfalse:
|
||||
@ -448,8 +451,8 @@ class file:
|
||||
else:
|
||||
mn = '%{nil}'
|
||||
if mn:
|
||||
if mn.lower() in self.defines:
|
||||
s = s.replace(m, self.defines[mn.lower()])
|
||||
if mn.lower() in self.macros:
|
||||
s = s.replace(m, self.macros[mn.lower()])
|
||||
expanded = True
|
||||
elif show_warning:
|
||||
self._error("macro '%s' not found" % (mn))
|
||||
@ -461,27 +464,27 @@ class file:
|
||||
else:
|
||||
d = self._label(ls[1])
|
||||
if self.disable_macro_reassign:
|
||||
if (d not in self.defines) or \
|
||||
(d in self.defines and len(self.defines[d]) == 0):
|
||||
if (d not in self.macros) or \
|
||||
(d in self.macros and len(self.macros[d]) == 0):
|
||||
if len(ls) == 2:
|
||||
self.defines[d] = '1'
|
||||
self.macros[d] = '1'
|
||||
else:
|
||||
self.defines[d] = ' '.join([f.strip() for f in ls[2:]])
|
||||
self.macros[d] = ' '.join([f.strip() for f in ls[2:]])
|
||||
else:
|
||||
self._warning("macro '%s' already defined" % (d))
|
||||
else:
|
||||
if len(ls) == 2:
|
||||
self.defines[d] = '1'
|
||||
self.macros[d] = '1'
|
||||
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):
|
||||
if len(ls) <= 1:
|
||||
self._warning('invalid macro definition')
|
||||
else:
|
||||
mn = self._label(ls[1])
|
||||
if mn in self.defines:
|
||||
del self.defines[mn]
|
||||
if mn in self.macros:
|
||||
del self.macros[mn]
|
||||
else:
|
||||
self._warning("macro '%s' not defined" % (mn))
|
||||
|
||||
@ -703,11 +706,11 @@ class file:
|
||||
# Check if already defined. Would be by the command line or
|
||||
# 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]))
|
||||
elif ls[0] == '%bcond_without':
|
||||
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]))
|
||||
else:
|
||||
for r in self._ignore:
|
||||
@ -755,7 +758,6 @@ class file:
|
||||
self.in_error = False
|
||||
self.lc = 0
|
||||
self.name = name
|
||||
self.defines = copy.deepcopy(self.default_defines)
|
||||
self.conditionals = {}
|
||||
self._packages = {}
|
||||
self.package = 'main'
|
||||
@ -898,15 +900,15 @@ class file:
|
||||
self.load_depth -= 1
|
||||
|
||||
def defined(self, name):
|
||||
return name.lower() in self.defines
|
||||
return self.macros.has_key(name)
|
||||
|
||||
def define(self, name):
|
||||
if name.lower() in self.defines:
|
||||
d = self.defines[name.lower()]
|
||||
if name in self.macros:
|
||||
d = self.macros[name]
|
||||
else:
|
||||
n = self._label(name)
|
||||
if n in self.defines:
|
||||
d = self.defines[n]
|
||||
if n in self.macros:
|
||||
d = self.macros[n]
|
||||
else:
|
||||
raise error.general('%d: macro "%s" not found' % (self.lc, name))
|
||||
return self._expand(d)
|
||||
@ -922,7 +924,7 @@ class file:
|
||||
return el
|
||||
return self._expand(line)
|
||||
|
||||
def default(self, name):
|
||||
def macro(self, name):
|
||||
if name.lower() in self.defines:
|
||||
return self.defines[name.lower()]
|
||||
raise error.general('macro "%s" not found' % (name))
|
||||
@ -947,11 +949,14 @@ class file:
|
||||
def run():
|
||||
import sys
|
||||
try:
|
||||
opts, _defaults = defaults.load(sys.argv)
|
||||
#
|
||||
# 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()))
|
||||
for config_file in opts.config_files():
|
||||
s = file(config_file, _defaults = _defaults, opts = opts)
|
||||
s = file(config_file, opts)
|
||||
print s
|
||||
del s
|
||||
except error.general, gerr:
|
||||
|
@ -22,7 +22,6 @@
|
||||
# RTEMS project's spec files.
|
||||
#
|
||||
|
||||
import pprint
|
||||
import os
|
||||
|
||||
import execute
|
||||
@ -56,4 +55,5 @@ def load():
|
||||
return defines
|
||||
|
||||
if __name__ == '__main__':
|
||||
import pprint
|
||||
pprint.pprint(load())
|
||||
|
@ -23,9 +23,9 @@
|
||||
|
||||
import os
|
||||
|
||||
import defaults
|
||||
import error
|
||||
import execute
|
||||
import options
|
||||
import path
|
||||
|
||||
class repo:
|
||||
@ -42,11 +42,14 @@ class repo:
|
||||
self._git_exit_code(exit_code)
|
||||
return exit_code, output
|
||||
|
||||
def __init__(self, _path, _opts, _defaults):
|
||||
def __init__(self, _path, opts, macros = None):
|
||||
self.path = _path
|
||||
self.opts = _opts
|
||||
self.default = _defaults
|
||||
self.git = _opts.expand('%{__git}', _defaults)
|
||||
self.opts = opts
|
||||
if macros is None:
|
||||
self.macros = opts.defaults
|
||||
else:
|
||||
self.macros = macros
|
||||
self.git = self.macros.expand('%{__git}')
|
||||
|
||||
def git_version(self):
|
||||
ec, output = self._run(['--version'], True)
|
||||
@ -120,8 +123,8 @@ class repo:
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
_opts, _defaults = defaults.load(sys.argv)
|
||||
g = repo('.', _opts, _defaults)
|
||||
opts = options.load(sys.argv)
|
||||
g = repo('.', opts)
|
||||
print g.git_version()
|
||||
print g.valid()
|
||||
print g.status()
|
||||
|
333
source-builder/sb/macros.py
Normal file
333
source-builder/sb/macros.py
Normal 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
|
@ -1,6 +1,6 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# This file is part of the RTEMS Tools package in 'rtems-tools'.
|
||||
@ -25,233 +25,21 @@ import glob
|
||||
import pprint
|
||||
import re
|
||||
import os
|
||||
import string
|
||||
|
||||
import error
|
||||
import execute
|
||||
import git
|
||||
import macros
|
||||
import path
|
||||
import sys
|
||||
|
||||
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:
|
||||
"""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 = {
|
||||
# key macro handler param defs init
|
||||
'--prefix' : ('_prefix', self._lo_path, True, None, False),
|
||||
@ -280,21 +68,17 @@ class command_line:
|
||||
'--help' : (None, self._lo_help, False, None, False)
|
||||
}
|
||||
|
||||
self.command_path = path.dirname(argv[0])
|
||||
if len(self.command_path) == 0:
|
||||
self.command_path = '.'
|
||||
self.command_path = command_path
|
||||
self.command_name = path.basename(argv[0])
|
||||
self.argv = argv
|
||||
self.args = argv[1:]
|
||||
self.optargs = optargs
|
||||
self.defaults = {}
|
||||
self.defaults['_sbdir'] = ('dir', 'required', path.shell(self.command_path))
|
||||
self.defaults = _defaults
|
||||
self.opts = { 'params' : [] }
|
||||
for lo in self._long_opts:
|
||||
self.opts[lo[2:]] = self._long_opts[lo][3]
|
||||
if self._long_opts[lo][4]:
|
||||
self.defaults[self._long_opts[lo][0]] = ('none', 'none', self._long_opts[lo][3])
|
||||
self._process()
|
||||
|
||||
def __str__(self):
|
||||
def _dict(dd):
|
||||
@ -315,14 +99,14 @@ class command_line:
|
||||
if value is None:
|
||||
raise error.general('option requires a value: %s' % (opt))
|
||||
self.opts[opt[2:]] = value
|
||||
self.defaults[macro] = ('none', 'none', value)
|
||||
self.defaults[macro] = value
|
||||
|
||||
def _lo_path(self, opt, macro, value):
|
||||
if value is None:
|
||||
raise error.general('option requires a path: %s' % (opt))
|
||||
value = path.shell(value)
|
||||
self.opts[opt[2:]] = value
|
||||
self.defaults[macro] = ('none', 'none', value)
|
||||
self.defaults[macro] = value
|
||||
|
||||
def _lo_jobs(self, opt, macro, value):
|
||||
if value is None:
|
||||
@ -344,14 +128,14 @@ class command_line:
|
||||
pass
|
||||
if not ok:
|
||||
raise error.general('invalid jobs option: %s' % (value))
|
||||
self.defaults[macro] = ('none', 'none', value)
|
||||
self.defaults[macro] = value
|
||||
self.opts[opt[2:]] = value
|
||||
|
||||
def _lo_bool(self, opt, macro, value):
|
||||
if value is not None:
|
||||
raise error.general('option does not take a value: %s' % (opt))
|
||||
self.opts[opt[2:]] = '1'
|
||||
self.defaults[macro] = ('none', 'none', '1')
|
||||
self.defaults[macro] = '1'
|
||||
|
||||
def _lo_triplets(self, opt, macro, value):
|
||||
#
|
||||
@ -383,15 +167,15 @@ class command_line:
|
||||
value = value[dash + 1:]
|
||||
if len(value):
|
||||
_os_value = value
|
||||
self.defaults[_cpu] = ('none', 'none', _arch_value)
|
||||
self.defaults[_arch] = ('none', 'none', _arch_value)
|
||||
self.defaults[_vendor] = ('none', 'none', _vendor_value)
|
||||
self.defaults[_os] = ('none', 'none', _os_value)
|
||||
self.defaults[_cpu] = _arch_value
|
||||
self.defaults[_arch] = _arch_value
|
||||
self.defaults[_vendor] = _vendor_value
|
||||
self.defaults[_os] = _os_value
|
||||
|
||||
def _lo_help(self, opt, macro, value):
|
||||
self.help()
|
||||
|
||||
def _help(self):
|
||||
def help(self):
|
||||
print '%s: [options] [args]' % (self.command_name)
|
||||
print 'RTEMS Source Builder, an RTEMS Tools Project (c) 2012-2013 Chris Johns'
|
||||
print 'Options and arguments:'
|
||||
@ -424,12 +208,12 @@ class command_line:
|
||||
print '%-22s : %s' % (a, self.optargs[a])
|
||||
raise error.exit()
|
||||
|
||||
def _process(self):
|
||||
def process(self):
|
||||
arg = 0
|
||||
while arg < len(self.args):
|
||||
a = self.args[arg]
|
||||
if a == '-?':
|
||||
self._help()
|
||||
self.help()
|
||||
elif a.startswith('--'):
|
||||
los = a.split('=')
|
||||
lo = los[0]
|
||||
@ -450,40 +234,16 @@ class command_line:
|
||||
self.opts['params'].append(a)
|
||||
arg += 1
|
||||
|
||||
def _post_process(self, _defaults):
|
||||
if _defaults['_host'][2] == _defaults['nil'][2]:
|
||||
def post_process(self):
|
||||
if self.defaults['_host'] == self.defaults['nil']:
|
||||
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')
|
||||
ncpus = self.jobs(_defaults['_ncpus'][2])
|
||||
ncpus = self.jobs(self.defaults['_ncpus'])
|
||||
if ncpus > 1:
|
||||
_defaults['_smp_mflags'] = ('none', 'none', '-j %d' % (ncpus))
|
||||
self.defaults['_smp_mflags'] = '-j %d' % (ncpus)
|
||||
else:
|
||||
_defaults['_smp_mflags'] = ('none', 'none', _defaults['nil'][2])
|
||||
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
|
||||
self.defaults['_smp_mflags'] = self.defaults['nil']
|
||||
|
||||
def command(self):
|
||||
return path.join(self.command_path, self.command_name)
|
||||
@ -573,7 +333,7 @@ class command_line:
|
||||
if not configbase.endswith('.cfg'):
|
||||
configbase = configbase + '.cfg'
|
||||
if len(configdir) == 0:
|
||||
configdir = self.expand(self.defaults['_configdir'][2], self.defaults)
|
||||
configdir = self.macros.expand(self.defaults['_configdir'])
|
||||
configs = []
|
||||
for cp in configdir.split(':'):
|
||||
hostconfigdir = path.host(cp)
|
||||
@ -590,7 +350,7 @@ class command_line:
|
||||
return configs
|
||||
|
||||
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 ['stdout']
|
||||
|
||||
@ -599,15 +359,31 @@ class command_line:
|
||||
return self.opts['url'].split(',')
|
||||
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
|
||||
any matching defaults, then create an options object to handle the command
|
||||
line merging in any command line overrides. Finally post process the
|
||||
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
|
||||
if os.name == 'nt':
|
||||
import windows
|
||||
@ -634,12 +410,12 @@ def load(args, optargs = None):
|
||||
if overrides is None:
|
||||
raise error.general('no hosts defaults found; please add')
|
||||
for k in overrides:
|
||||
d[k] = overrides[k]
|
||||
o = command_line(args, optargs)
|
||||
for k in o.defaults:
|
||||
d[k] = o.defaults[k]
|
||||
d = o._post_process(d)
|
||||
repo = git.repo(o.expand('%{_sbdir}', d), o, d)
|
||||
o.defaults[k] = overrides[k]
|
||||
|
||||
o.process()
|
||||
o.post_process()
|
||||
|
||||
repo = git.repo(o.defaults.expand('%{_sbdir}'), o)
|
||||
if repo.valid():
|
||||
repo_valid = '1'
|
||||
repo_head = repo.head()
|
||||
@ -652,35 +428,19 @@ def load(args, optargs = None):
|
||||
repo_head = '%{nil}'
|
||||
repo_clean = '%{nil}'
|
||||
repo_id = 'no-repo'
|
||||
o.define(d, '_sbgit_valid', repo_valid)
|
||||
o.define(d, '_sbgit_head', repo_head)
|
||||
o.define(d, '_sbgit_clean', str(repo_clean))
|
||||
o.define(d, '_sbgit_id', repo_id)
|
||||
return o, d
|
||||
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):
|
||||
try:
|
||||
_opts, _defaults = load(args = args)
|
||||
_opts = load(args = args)
|
||||
print 'Options:'
|
||||
print _opts
|
||||
print 'Defaults:'
|
||||
for k in sorted(_defaults.keys()):
|
||||
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
|
||||
print _opts.defaults
|
||||
except error.general, gerr:
|
||||
print gerr
|
||||
sys.exit(1)
|
@ -31,10 +31,10 @@ try:
|
||||
import build
|
||||
import check
|
||||
import config
|
||||
import defaults
|
||||
import error
|
||||
import git
|
||||
import log
|
||||
import options
|
||||
import path
|
||||
import setbuilder
|
||||
import version
|
||||
@ -56,18 +56,21 @@ class report:
|
||||
|
||||
line_len = 78
|
||||
|
||||
def __init__(self, format, _configs, _defaults, opts):
|
||||
def __init__(self, format, _configs, opts, macros = None):
|
||||
self.format = format
|
||||
self.configs = _configs
|
||||
self.defaults = _defaults
|
||||
self.opts = opts
|
||||
if macros is None:
|
||||
self.macros = opts.defaults
|
||||
else:
|
||||
self.macros = macros
|
||||
self.bset_nesting = 0
|
||||
self.configs_active = False
|
||||
self.out = ''
|
||||
self.asciidoc = None
|
||||
|
||||
def _sbpath(self, *args):
|
||||
p = self.opts.expand('%{_sbdir}', self.defaults)
|
||||
p = self.macros.expand('%{_sbdir}')
|
||||
for arg in args:
|
||||
p = path.join(p, arg)
|
||||
return os.path.abspath(path.host(p))
|
||||
@ -87,7 +90,7 @@ class report:
|
||||
import asciidocapi
|
||||
except:
|
||||
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:
|
||||
self.asciidoc = asciidocapi.AsciiDocAPI(asciidoc_py)
|
||||
except:
|
||||
@ -109,7 +112,7 @@ class report:
|
||||
else:
|
||||
self.output('-' * self.line_len)
|
||||
self.output('%s' % (text))
|
||||
repo = git.repo('.', self.opts, self.defaults)
|
||||
repo = git.repo('.', self.opts, self.macros)
|
||||
repo_valid = repo.valid()
|
||||
if repo_valid:
|
||||
if self.is_asciidoc():
|
||||
@ -172,7 +175,7 @@ class report:
|
||||
self.output('RTEMS Tools Project <rtems-users@rtems.org>')
|
||||
self.output(datetime.datetime.now().ctime())
|
||||
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('')
|
||||
if intro_text:
|
||||
@ -248,9 +251,9 @@ class report:
|
||||
if self.is_asciidoc():
|
||||
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()
|
||||
package = packages['main']
|
||||
name = package.name()
|
||||
@ -308,17 +311,14 @@ class report:
|
||||
def buildset(self, name):
|
||||
self.bset_nesting += 1
|
||||
self.buildset_start(name)
|
||||
_opts = copy.copy(self.opts)
|
||||
_defaults = copy.copy(self.defaults)
|
||||
bset = setbuilder.buildset(name,
|
||||
_configs = self.configs,
|
||||
_defaults = _defaults,
|
||||
opts = _opts)
|
||||
opts = copy.copy(self.opts)
|
||||
macros = copy.copy(self.macros)
|
||||
bset = setbuilder.buildset(name, self.configs, opts, macros)
|
||||
for c in bset.load():
|
||||
if c.endswith('.bset'):
|
||||
self.buildset(c)
|
||||
elif c.endswith('.cfg'):
|
||||
self.config(c, _defaults, _opts)
|
||||
self.config(c, opts, macros)
|
||||
else:
|
||||
raise error.general('invalid config type: %s' % (c))
|
||||
self.buildset_end(name)
|
||||
@ -352,7 +352,7 @@ class report:
|
||||
if config.endswith('.bset'):
|
||||
self.buildset(config)
|
||||
elif config.endswith('.cfg'):
|
||||
self.config(config, self.defaults, self.opts)
|
||||
self.config(config, self.opts, self.macros)
|
||||
else:
|
||||
raise error.general('invalid config type: %s' % (config))
|
||||
self.generate(outname)
|
||||
@ -363,14 +363,14 @@ def run(args):
|
||||
'--list-configs': 'List available configurations',
|
||||
'--format': 'Output format (text, html, asciidoc)',
|
||||
'--output': 'File name to output the report' }
|
||||
opts, _defaults = defaults.load(args, optargs)
|
||||
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, _defaults):
|
||||
if not check.host_setup(opts):
|
||||
_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):
|
||||
output = opts.get_arg('--output')
|
||||
if output is not None:
|
||||
@ -391,13 +391,11 @@ def run(args):
|
||||
ext = '.html'
|
||||
else:
|
||||
raise error.general('invalid format: %s' % (format_opt[1]))
|
||||
r = report(format = format,
|
||||
_configs = configs,
|
||||
_defaults = _defaults,
|
||||
opts = opts)
|
||||
r = report(format, configs, opts)
|
||||
for _config in opts.params():
|
||||
if output is None:
|
||||
outname = path.splitext(_config)[0] + ext
|
||||
outname = outname.replace('/', '-')
|
||||
else:
|
||||
outname = output
|
||||
r.make(_config, outname)
|
||||
|
@ -33,9 +33,9 @@ import sys
|
||||
try:
|
||||
import build
|
||||
import check
|
||||
import defaults
|
||||
import error
|
||||
import log
|
||||
import options
|
||||
import path
|
||||
import reports
|
||||
import version
|
||||
@ -59,14 +59,16 @@ def _notice(opts, text):
|
||||
class buildset:
|
||||
"""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))
|
||||
self.configs = _configs
|
||||
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_pkg = '%s-%s-set' % (self.opts.expand('%{_target}', _defaults),
|
||||
self.bset)
|
||||
self.bset_pkg = '%s-%s-set' % (self.macros.expand('%{_target}'), self.bset)
|
||||
|
||||
def _output(self, text):
|
||||
if not self.opts.quiet():
|
||||
@ -87,8 +89,8 @@ class buildset:
|
||||
raise error.general('copying tree: %s' % (str(err)))
|
||||
|
||||
def report(self, _config, _build):
|
||||
if not self.opts.get_arg('--no-report'):
|
||||
format = self.opts.get_arg('--report-format')
|
||||
if not _build.opts.get_arg('--no-report'):
|
||||
format = _build.opts.get_arg('--report-format')
|
||||
if format is None:
|
||||
format = 'html'
|
||||
ext = '.html'
|
||||
@ -107,14 +109,14 @@ class buildset:
|
||||
else:
|
||||
raise error.general('invalid report format: %s' % (format[1]))
|
||||
buildroot = _build.config.abspath('%{buildroot}')
|
||||
prefix = self.opts.expand('%{_prefix}', self.defaults)
|
||||
prefix = _build.macros.expand('%{_prefix}')
|
||||
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))
|
||||
if not self.opts.dry_run():
|
||||
if not _build.opts.dry_run():
|
||||
_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)
|
||||
del r
|
||||
|
||||
@ -134,23 +136,24 @@ class buildset:
|
||||
self.copy(src, dst)
|
||||
|
||||
def canadian_cross(self, _build):
|
||||
defaults_to_save = ['%{_prefix}',
|
||||
'%{_tmproot}',
|
||||
'%{buildroot}',
|
||||
'%{_builddir}',
|
||||
'%{_host}']
|
||||
defaults_to_copy = [('%{_host}', '%{_build}'),
|
||||
('%{_tmproot}', '%{_tmpcxcroot}'),
|
||||
('%{buildroot}', '%{buildcxcroot}'),
|
||||
('%{_builddir}', '%{_buildcxcdir}')]
|
||||
orig_defaults = {}
|
||||
for d in defaults_to_save:
|
||||
orig_defaults[d] = _build.config.default(d)
|
||||
for d in defaults_to_copy:
|
||||
_build.config.set_define(d[0], _build.config.default(d[1]))
|
||||
# @fixme Switch to using a private macros map.
|
||||
macros_to_save = ['%{_prefix}',
|
||||
'%{_tmproot}',
|
||||
'%{buildroot}',
|
||||
'%{_builddir}',
|
||||
'%{_host}']
|
||||
macros_to_copy = [('%{_host}', '%{_build}'),
|
||||
('%{_tmproot}', '%{_tmpcxcroot}'),
|
||||
('%{buildroot}', '%{buildcxcroot}'),
|
||||
('%{_builddir}', '%{_buildcxcdir}')]
|
||||
orig_macros = {}
|
||||
for m in macros_to_save:
|
||||
orig_macros[m] = _build.config.macro(m)
|
||||
for m in macros_to_copy:
|
||||
_build.config.set_define(m[0], _build.config.macro(m[1]))
|
||||
_build.make()
|
||||
for d in defaults_to_save:
|
||||
_build.config.set_define(d, orig_defaults[d])
|
||||
for m in macris_to_save:
|
||||
_build.config.set_define(m, orig_macros[m])
|
||||
self.root_copy(_build.config.expand('%{buildcxcroot}'),
|
||||
_build.config.expand('%{_tmpcxcroot}'))
|
||||
|
||||
@ -186,7 +189,7 @@ class buildset:
|
||||
bsetname = bset
|
||||
|
||||
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)
|
||||
bsetname = path.join(configdir, bset)
|
||||
if path.exists(bsetname):
|
||||
@ -214,20 +217,19 @@ class buildset:
|
||||
print '%03d: %s' % (lc, l)
|
||||
ls = l.split()
|
||||
if ls[0][-1] == ':' and ls[0][:-1] == 'package':
|
||||
self.bset_pkg = self.opts.expand(ls[1].strip(), self.defaults)
|
||||
self.defaults['package'] = ('none', 'none', self.bset_pkg)
|
||||
self.bset_pkg = self.macros.expand(ls[1].strip())
|
||||
self.macros['package'] = self.bset_pkg
|
||||
elif ls[0][0] == '%':
|
||||
if ls[0] == '%define':
|
||||
if len(ls) > 2:
|
||||
self.opts.define(self.defaults,
|
||||
ls[1].strip(),
|
||||
' '.join([f.strip() for f in ls[2:]]))
|
||||
self.macros.define(ls[1].strip(),
|
||||
' '.join([f.strip() for f in ls[2:]]))
|
||||
else:
|
||||
self.opts.define(self.defaults, ls[1].strip())
|
||||
self.macros.define(ls[1].strip())
|
||||
elif ls[0] == '%undefine':
|
||||
if len(ls) > 2:
|
||||
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':
|
||||
configs += self.parse(ls[1].strip())
|
||||
else:
|
||||
@ -248,9 +250,9 @@ class buildset:
|
||||
|
||||
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)
|
||||
|
||||
@ -280,23 +282,18 @@ class buildset:
|
||||
try:
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
_opts = copy.copy(self.opts)
|
||||
_defaults = copy.copy(self.defaults)
|
||||
opts = copy.copy(self.opts)
|
||||
macros = copy.copy(self.macros)
|
||||
if configs[s].endswith('.bset'):
|
||||
bs = buildset(configs[s],
|
||||
_configs = self.configs,
|
||||
_defaults = _defaults,
|
||||
opts = _opts)
|
||||
bs = buildset(configs[s], self.configs, opts, macros)
|
||||
bs.build(deps)
|
||||
del bs
|
||||
elif configs[s].endswith('.cfg'):
|
||||
b = build.build(configs[s],
|
||||
self.opts.get_arg('--pkg-tar-files'),
|
||||
_defaults = _defaults,
|
||||
opts = _opts)
|
||||
b = build.build(configs[s], self.opts.get_arg('--pkg-tar-files'),
|
||||
opts, macros)
|
||||
if deps is None:
|
||||
self.build_package(configs[s], b)
|
||||
if s == len(configs) - 1:
|
||||
@ -360,19 +357,19 @@ def run():
|
||||
'--report-format': 'The report format (text, html, asciidoc).',
|
||||
'--bset-tar-file': 'Create a build set tar file',
|
||||
'--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())
|
||||
_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')
|
||||
configs = build.get_configs(opts, _defaults)
|
||||
configs = build.get_configs(opts)
|
||||
if opts.get_arg('--list-deps'):
|
||||
deps = []
|
||||
else:
|
||||
deps = None
|
||||
if not list_bset_cfg_files(opts, configs):
|
||||
for bset in opts.params():
|
||||
b = buildset(bset, _configs = configs, _defaults = _defaults, opts = opts)
|
||||
b = buildset(bset, configs, opts)
|
||||
b.build(deps)
|
||||
del b
|
||||
if deps is not None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user