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

View File

@@ -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'