source: rtems-source-builder/source-builder/sb/options.py @ 9e49d20

5
Last change on this file since 9e49d20 was ad5d3af, checked in by Chris Johns <chrisj@…>, on 12/05/19 at 05:27:10

sb: VERSION may not contain a release path or hashes

  • Property mode set to 100644
File size: 28.8 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2010-2016 Chris Johns (chrisj@rtems.org)
4# All rights reserved.
5#
6# This file is part of the RTEMS Tools package in 'rtems-tools'.
7#
8# Permission to use, copy, modify, and/or distribute this software for any
9# purpose with or without fee is hereby granted, provided that the above
10# copyright notice and this permission notice appear in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20#
21# Determine the defaults and load the specific file.
22#
23
24from __future__ import print_function
25
26import datetime
27import glob
28import pprint
29import re
30import os
31import string
32
33import download
34import error
35import execute
36import git
37import log
38import macros
39import path
40import sources
41import sys
42
43import version
44
45basepath = 'sb'
46
47#
48# Save the host and POSIX state.
49#
50host_windows = False
51host_posix = True
52
53class command_line:
54    """Process the command line in a common way for all Tool Builder commands."""
55
56    def __init__(self, argv, optargs, _defaults, command_path):
57        self._long_opts = {
58            # key                       macro                handler            param  defs   init
59            '--prefix'               : ('_prefix',           self._lo_path,     True,  None,  False),
60            '--topdir'               : ('_topdir',           self._lo_path,     True,  None,  False),
61            '--configdir'            : ('_configdir',        self._lo_path,     True,  None,  False),
62            '--builddir'             : ('_builddir',         self._lo_path,     True,  None,  False),
63            '--sourcedir'            : ('_sourcedir',        self._lo_path,     True,  None,  False),
64            '--patchdir'             : ('_patchdir',         self._lo_path,     True,  None,  False),
65            '--tmppath'              : ('_tmppath',          self._lo_path,     True,  None,  False),
66            '--jobs'                 : ('_jobs',             self._lo_jobs,     True,  'max', True),
67            '--log'                  : ('_logfile',          self._lo_string,   True,  None,  False),
68            '--url'                  : ('_url_base',         self._lo_string,   True,  None,  False),
69            '--no-download'          : ('_disable_download', self._lo_bool,     False, '0',   True),
70            '--macros'               : ('_macros',           self._lo_string,   True,  None,  False),
71            '--source-only-download' : ('_source_download',  self._lo_bool,     False, '0',   True),
72            '--targetcflags'         : ('_targetcflags',     self._lo_string,   True,  None,  False),
73            '--targetcxxflags'       : ('_targetcxxflags',   self._lo_string,   True,  None,  False),
74            '--libstdcxxflags'       : ('_libstdcxxflags',   self._lo_string,   True,  None,  False),
75            '--force'                : ('_force',            self._lo_bool,     False, '0',   True),
76            '--quiet'                : ('_quiet',            self._lo_bool,     False, '0',   True),
77            '--trace'                : ('_trace',            self._lo_bool,     False, '0',   True),
78            '--dry-run'              : ('_dry_run',          self._lo_bool,     False, '0',   True),
79            '--warn-all'             : ('_warn_all',         self._lo_bool,     False, '0',   True),
80            '--no-clean'             : ('_no_clean',         self._lo_bool,     False, '0',   True),
81            '--keep-going'           : ('_keep_going',       self._lo_bool,     False, '0',   True),
82            '--always-clean'         : ('_always_clean',     self._lo_bool,     False, '0',   True),
83            '--no-install'           : ('_no_install',       self._lo_bool,     False, '0',   True),
84            '--regression'           : ('_regression',       self._lo_bool,     False, '0',   True),
85            '--host'                 : ('_host',             self._lo_triplets, True,  None,  False),
86            '--build'                : ('_build',            self._lo_triplets, True,  None,  False),
87            '--target'               : ('_target',           self._lo_triplets, True,  None,  False),
88            '--rtems-tools'          : ('_rtems_tools',      self._lo_string,   True,  None,  False),
89            '--rtems-bsp'            : ('_rtems_bsp',        self._lo_string,   True,  None,  False),
90            '--rtems-version'        : ('_rtems_version',    self._lo_string,   True,  None,  False),
91            '--help'                 : (None,                self._lo_help,     False, None,  False)
92            }
93
94        self.command_path = command_path
95        self.command_name = path.basename(argv[0])
96        self.argv = argv
97        self.args = argv[1:]
98        self.optargs = optargs
99        self.defaults = _defaults
100        self.opts = { 'params' : [] }
101        for lo in self._long_opts:
102            self.opts[lo[2:]] = self._long_opts[lo][3]
103            if self._long_opts[lo][4]:
104                self.defaults[self._long_opts[lo][0]] = ('none',
105                                                         'none',
106                                                         self._long_opts[lo][3])
107
108    def __str__(self):
109        def _dict(dd):
110            s = ''
111            ddl = list(dd.keys())
112            ddl.sort()
113            for d in ddl:
114                s += '  ' + d + ': ' + str(dd[d]) + '\n'
115            return s
116
117        s = 'command: ' + self.command() + \
118            '\nargs: ' + str(self.args) + \
119            '\nopts:\n' + _dict(self.opts)
120
121        return s
122
123    def _lo_string(self, opt, macro, value):
124        if value is None:
125            raise error.general('option requires a value: %s' % (opt))
126        self.opts[opt[2:]] = value
127        self.defaults[macro] = value
128
129    def _lo_path(self, opt, macro, value):
130        if value is None:
131            raise error.general('option requires a path: %s' % (opt))
132        value = path.abspath(value)
133        self.opts[opt[2:]] = value
134        self.defaults[macro] = value
135
136    def _lo_jobs(self, opt, macro, value):
137        if value is None:
138            raise error.general('option requires a value: %s' % (opt))
139        ok = False
140        if value in ['max', 'none', 'half']:
141            ok = True
142        else:
143            try:
144                i = int(value)
145                ok = True
146            except:
147                pass
148            if not ok:
149                try:
150                    f = float(value)
151                    ok = True
152                except:
153                    pass
154        if not ok:
155            raise error.general('invalid jobs option: %s' % (value))
156        self.defaults[macro] = value
157        self.opts[opt[2:]] = value
158
159    def _lo_bool(self, opt, macro, value):
160        if value is not None:
161            raise error.general('option does not take a value: %s' % (opt))
162        self.opts[opt[2:]] = '1'
163        self.defaults[macro] = '1'
164
165    def _lo_triplets(self, opt, macro, value):
166        #
167        # This is a target triplet. Run it past config.sub to make make sure it
168        # is ok.  The target triplet is 'cpu-vendor-os'.
169        #
170        e = execute.capture_execution()
171        config_sub = path.join(self.command_path,
172                               basepath, 'config.sub')
173        exit_code, proc, output = e.shell(config_sub + ' ' + value)
174        if exit_code == 0:
175            value = output
176        self.defaults[macro] = ('triplet', 'none', value)
177        self.opts[opt[2:]] = value
178        _cpu = macro + '_cpu'
179        _arch = macro + '_arch'
180        _vendor = macro + '_vendor'
181        _os = macro + '_os'
182        _arch_value = ''
183        _vendor_value = ''
184        _os_value = ''
185        dash = value.find('-')
186        if dash >= 0:
187            _arch_value = value[:dash]
188            value = value[dash + 1:]
189        dash = value.find('-')
190        if dash >= 0:
191            _vendor_value = value[:dash]
192            value = value[dash + 1:]
193        if len(value):
194            _os_value = value
195        self.defaults[_cpu]    = _arch_value
196        self.defaults[_arch]   = _arch_value
197        self.defaults[_vendor] = _vendor_value
198        self.defaults[_os]     = _os_value
199
200    def _lo_help(self, opt, macro, value):
201        self.help()
202
203    def help(self):
204        print('%s: [options] [args]' % (self.command_name))
205        print('RTEMS Source Builder, an RTEMS Tools Project (c) 2012-2019 Chris Johns')
206        print('Options and arguments:')
207        print('--force                : Force the build to proceed')
208        print('--quiet                : Quiet output (not used)')
209        print('--trace                : Trace the execution')
210        print('--dry-run              : Do everything but actually run the build')
211        print('--warn-all             : Generate warnings')
212        print('--no-clean             : Do not clean up the build tree')
213        print('--always-clean         : Always clean the build tree, even with an error')
214        print('--keep-going           : Do not stop on an error.')
215        print('--regression           : Set --no-install, --keep-going and --always-clean')
216        print('--jobs                 : Run with specified number of jobs, default: num CPUs.')
217        print('--host                 : Set the host triplet')
218        print('--build                : Set the build triplet')
219        print('--target               : Set the target triplet')
220        print('--prefix path          : Tools build prefix, ie where they are installed')
221        print('--topdir path          : Top of the build tree, default is $PWD')
222        print('--configdir path       : Path to the configuration directory, default: ./config')
223        print('--builddir path        : Path to the build directory, default: ./build')
224        print('--sourcedir path       : Path to the source directory, default: ./source')
225        print('--patchdir path        : Path to the patches directory, default: ./patches')
226        print('--tmppath path         : Path to the temp directory, default: ./tmp')
227        print('--macros file[,[file]  : Macro format files to load after the defaults')
228        print('--log file             : Log file where all build out is written too')
229        print('--url url[,url]        : URL to look for source')
230        print('--no-download          : Disable the source downloader')
231        print('--no-install           : Do not install the packages to the prefix')
232        print('--targetcflags flags   : List of C flags for the target code')
233        print('--targetcxxflags flags : List of C++ flags for the target code')
234        print('--libstdcxxflags flags : List of C++ flags to build the target libstdc++ code')
235        print('--source-only-download : Only download the source')
236        print('--with-<label>         : Add the --with-<label> to the build')
237        print('--without-<label>      : Add the --without-<label> to the build')
238        print('--rtems-tools path     : Path to an install RTEMS tool set')
239        print('--rtems-bsp arc/bsp    : Standard RTEMS architecure and BSP specifier')
240        print('--rtems-version ver    : The RTEMS major/minor version string')
241        if self.optargs:
242            for a in self.optargs:
243                print('%-22s : %s' % (a, self.optargs[a]))
244        raise error.exit()
245
246    def process(self):
247        for a in self.args:
248            if a == '-?' or a == '--help':
249                self.help()
250        arg = 0
251        while arg < len(self.args):
252            a = self.args[arg]
253            if a.startswith('--'):
254                los = a.split('=', 1)
255                lo = los[0]
256                if lo in self._long_opts:
257                    long_opt = self._long_opts[lo]
258                    if len(los) == 1:
259                        if long_opt[2]:
260                            if arg == len(self.args) - 1:
261                                raise error.general('option requires a parameter: %s' % \
262                                                    (lo))
263                            arg += 1
264                            value = self.args[arg]
265                        else:
266                            value = None
267                    else:
268                        value = '='.join(los[1:])
269                    long_opt[1](lo, long_opt[0], value)
270                else:
271                    if a.startswith('--with'):
272                        if len(los) != 1:
273                            value = los[1]
274                        else:
275                            value = '1'
276                        self.defaults[los[0][2:].replace('-', '_').lower()] = \
277                            ('none', 'none', value)
278                    else:
279                        if lo not in self.optargs:
280                            raise error.general('unknown option: %s' % (lo))
281            else:
282                if a.startswith('-'):
283                    raise error.general('short options not supported; only "-?"')
284                self.opts['params'].append(a)
285            arg += 1
286
287    def pre_process(self):
288        arg = 0
289        while arg < len(self.args):
290            a = self.args[arg]
291            if a == '--source-only-download':
292                self.args += ['--dry-run',
293                              '--with-download',
294                              '--quiet',
295                              '--without-log',
296                              '--without-error-report',
297                              '--without-release-url']
298            if a == '--dry-run':
299                self.args += ['--without-error-report']
300            arg += 1
301
302    def post_process(self, logfile = True):
303        # Handle the log first.
304        logctrl = self.parse_args('--without-log')
305        if logctrl is None:
306            if logfile:
307                logfiles = self.logfiles()
308            else:
309                logfiles = None
310            log.default = log.log(streams = logfiles)
311        if self.trace():
312            log.tracing = True
313        if self.quiet():
314            log.quiet = True
315        # Must have a host
316        if self.defaults['_host'] == self.defaults['nil']:
317            raise error.general('--host not set')
318        # Must have a host
319        if self.defaults['_build'] == self.defaults['nil']:
320            raise error.general('--build not set')
321        # Default prefix
322        prefix = self.parse_args('--prefix')
323        if prefix is None:
324            value = path.join(self.defaults['_prefix'],
325                              'rtems',
326                              str(self.defaults['rtems_version']))
327            self.opts['prefix'] = value
328            self.defaults['_prefix'] = value
329        # Manage the regression option
330        if self.opts['regression'] != '0':
331            self.opts['no-install'] = '1'
332            self.defaults['_no_install'] = '1'
333            self.opts['keep-going'] = '1'
334            self.defaults['_keep_going'] = '1'
335            self.opts['always-clean'] = '1'
336            self.defaults['_always_clean'] = '1'
337        # Handle the jobs for make
338        if '_ncpus' not in self.defaults:
339            raise error.general('host number of CPUs not set')
340        ncpus = self.jobs(self.defaults['_ncpus'])
341        if ncpus > 1:
342            self.defaults['_smp_mflags'] = '-j %d' % (ncpus)
343        else:
344            self.defaults['_smp_mflags'] = self.defaults['nil']
345        # Load user macro files
346        um = self.user_macros()
347        if um:
348            checked = path.exists(um)
349            if False in checked:
350                raise error.general('macro file not found: %s' % \
351                                    (um[checked.index(False)]))
352            for m in um:
353                self.defaults.load(m)
354        # Check if the user has a private set of macros to load
355        if 'RSB_MACROS' in os.environ:
356            if path.exists(os.environ['RSB_MACROS']):
357                self.defaults.load(os.environ['RSB_MACROS'])
358        if 'HOME' in os.environ:
359            rsb_macros = path.join(os.environ['HOME'], '.rsb_macros')
360            if path.exists(rsb_macros):
361                self.defaults.load(rsb_macros)
362
363    def sb_released(self):
364        if version.released():
365            self.defaults['rsb_released'] = '1'
366        self.defaults['rsb_version'] = version.string()
367
368    def sb_git(self):
369        repo = git.repo(self.defaults.expand('%{_sbdir}'), self)
370        if repo.valid():
371            repo_valid = '1'
372            repo_head = repo.head()
373            repo_clean = not repo.dirty()
374            repo_remotes = '%{nil}'
375            remotes = repo.remotes()
376            if 'origin' in remotes:
377                repo_remotes = '%s/origin' % (remotes['origin']['url'])
378            repo_id = repo_head
379            if not repo_clean:
380                repo_id += '-modified'
381            repo_mail = repo.email()
382        else:
383            repo_valid = '0'
384            repo_head = '%{nil}'
385            repo_clean = '%{nil}'
386            repo_remotes = '%{nil}'
387            repo_id = 'no-repo'
388            repo_mail = None
389        self.defaults['_sbgit_valid'] = repo_valid
390        self.defaults['_sbgit_head']  = repo_head
391        self.defaults['_sbgit_clean'] = str(repo_clean)
392        self.defaults['_sbgit_remotes'] = str(repo_remotes)
393        self.defaults['_sbgit_id']    = repo_id
394        if repo_mail is not None:
395            self.defaults['_sbgit_mail'] = repo_mail
396
397    def command(self):
398        return path.join(self.command_path, self.command_name)
399
400    def force(self):
401        return self.opts['force'] != '0'
402
403    def dry_run(self):
404        return self.opts['dry-run'] != '0'
405
406    def set_dry_run(self):
407        self.opts['dry-run'] = '1'
408
409    def quiet(self):
410        return self.opts['quiet'] != '0'
411
412    def trace(self):
413        return self.opts['trace'] != '0'
414
415    def warn_all(self):
416        return self.opts['warn-all'] != '0'
417
418    def keep_going(self):
419        return self.opts['keep-going'] != '0'
420
421    def no_clean(self):
422        return self.opts['no-clean'] != '0'
423
424    def always_clean(self):
425        return self.opts['always-clean'] != '0'
426
427    def no_install(self):
428        return self.opts['no-install'] != '0'
429
430    def canadian_cross(self):
431        _host = self.defaults.expand('%{_host}')
432        _build = self.defaults.expand('%{_build}')
433        _target = self.defaults.expand('%{_target}')
434        #
435        # This has been removed to fix how RTEMS 3rd party libraries
436        # are built. This may break Cxc tools builds.
437        #
438        # if len(_target):
439        #     return len(_host) and len(_build) and (_target) and \
440        #         _host != _build and _host != _target
441        return len(_target) and len(_host) and len(_build) and _host != _build
442
443    def user_macros(self):
444        #
445        # Return something even if it does not exist.
446        #
447        if self.opts['macros'] is None:
448            return None
449        um = []
450        configs = self.defaults.expand('%{_configdir}').split(':')
451        for m in self.opts['macros'].split(','):
452            if path.exists(m):
453                um += [m]
454            else:
455                # Get the expanded config macros then check them.
456                cm = path.expand(m, configs)
457                ccm = path.exists(cm)
458                if True in ccm:
459                    # Pick the first found
460                    um += [cm[ccm.index(True)]]
461                else:
462                    um += [m]
463        return um if len(um) else None
464
465    def jobs(self, cpus):
466        cpus = int(cpus)
467        if self.opts['jobs'] == 'none':
468            cpus = 0
469        elif self.opts['jobs'] == 'max':
470            pass
471        elif self.opts['jobs'] == 'half':
472            cpus = cpus / 2
473        else:
474            ok = False
475            try:
476                i = int(self.opts['jobs'])
477                cpus = i
478                ok = True
479            except:
480                pass
481            if not ok:
482                try:
483                    f = float(self.opts['jobs'])
484                    cpus = f * cpus
485                    ok = True
486                except:
487                    pass
488                if not ok:
489                    raise error.internal('bad jobs option: %s' % (self.opts['jobs']))
490        if cpus <= 0:
491            cpu = 1
492        return cpus
493
494    def params(self):
495        return self.opts['params']
496
497    def parse_args(self, arg, error = True, extra = True):
498        for a in range(0, len(self.args)):
499            if self.args[a].startswith(arg):
500                lhs = None
501                rhs = None
502                if '=' in self.args[a]:
503                    eqs = self.args[a].split('=', 1)
504                    lhs = eqs[0]
505                    if len(eqs) > 2:
506                        rhs = '='.join(eqs[1:])
507                    else:
508                        rhs = eqs[1]
509                elif extra:
510                    lhs = self.args[a]
511                    a += 1
512                    if a < len(self.args):
513                        rhs = self.args[a]
514                return [lhs, rhs]
515            a += 1
516        return None
517
518    def get_arg(self, arg):
519        if self.optargs is None or arg not in self.optargs:
520            return None
521        return self.parse_args(arg)
522
523    def with_arg(self, label, default = 'not-found'):
524        # the default if there is no option for without.
525        result = default
526        for pre in ['with', 'without']:
527            arg_str = '--%s-%s' % (pre, label)
528            arg_label = '%s_%s' % (pre, label)
529            arg = self.parse_args(arg_str, error = False, extra = False)
530            if arg is not None:
531                if arg[1] is  None:
532                    result = 'yes'
533                else:
534                    result = arg[1]
535                break
536        return [arg_label, result]
537
538    def get_config_files(self, config):
539        #
540        # Convert to shell paths and return shell paths.
541        #
542        # @fixme should this use a passed in set of defaults and not
543        #        not the initial set of values ?
544        #
545        config = path.shell(config)
546        if '*' in config or '?' in config:
547            print(config)
548            configdir = path.dirname(config)
549            configbase = path.basename(config)
550            if len(configbase) == 0:
551                configbase = '*'
552            if not configbase.endswith('.cfg'):
553                configbase = configbase + '.cfg'
554            if len(configdir) == 0:
555                configdir = self.macros.expand(self.defaults['_configdir'])
556            configs = []
557            for cp in configdir.split(':'):
558                hostconfigdir = path.host(cp)
559                for f in glob.glob(os.path.join(hostconfigdir, configbase)):
560                    configs += path.shell(f)
561        else:
562            configs = [config]
563        return configs
564
565    def config_files(self):
566        configs = []
567        for config in self.opts['params']:
568            configs.extend(self.get_config_files(config))
569        return configs
570
571    def logfiles(self):
572        if 'log' in self.opts and self.opts['log'] is not None:
573            return self.opts['log'].split(',')
574        return ['rsb-log-%s.txt' % (datetime.datetime.now().strftime('%Y%m%d-%H%M%S'))]
575
576    def urls(self):
577        if self.opts['url'] is not None:
578            return self.opts['url'].split(',')
579        return None
580
581    def download_disabled(self):
582        return self.opts['no-download'] != '0'
583
584    def disable_install(self):
585        self.opts['no-install'] = '1'
586
587    def info(self):
588        s = ' Command Line: %s%s' % (' '.join(self.argv), os.linesep)
589        s += ' Python: %s' % (sys.version.replace('\n', ''))
590        return s
591
592    def log_info(self):
593        log.output(self.info())
594
595    def rtems_options(self):
596        # Check for RTEMS specific helper options.
597        rtems_tools = self.parse_args('--rtems-tools')
598        if rtems_tools is not None:
599            if self.get_arg('--with-tools') is not None:
600                raise error.general('--rtems-tools and --with-tools cannot be used together')
601            self.args.append('--with-tools=%s' % (rtems_tools[1]))
602        rtems_version = self.parse_args('--rtems-version')
603        if rtems_version is None:
604            rtems_version = str(version.version())
605        else:
606            rtems_version = rtems_version[1]
607        self.defaults['rtems_version'] = rtems_version
608        rtems_arch_bsp = self.parse_args('--rtems-bsp')
609        if rtems_arch_bsp is not None:
610            if self.get_arg('--target') is not None:
611                raise error.general('--rtems-bsp and --target cannot be used together')
612            ab = rtems_arch_bsp[1].split('/')
613            if len(ab) != 2:
614                raise error.general('invalid --rtems-bsp option')
615            self.args.append('--target=%s-rtems%s' % (ab[0], rtems_version))
616            self.args.append('--with-rtems-bsp=%s' % (ab[1]))
617
618def load(args, optargs = None, defaults = '%{_sbdir}/defaults.mc', logfile = True):
619    """
620    Copy the defaults, get the host specific values and merge them overriding
621    any matching defaults, then create an options object to handle the command
622    line merging in any command line overrides. Finally post process the
623    command line.
624    """
625
626    global host_windows
627    global host_posix
628
629    #
630    # Adjust the args to remove the wrapper.
631    #
632    args = args[1:]
633
634    #
635    # The path to this command.
636    #
637    command_path = path.dirname(path.abspath(args[0]))
638    if len(command_path) == 0:
639        command_path = '.'
640
641    #
642    # The command line contains the base defaults object all build objects copy
643    # and modify by loading a configuration.
644    #
645    o = command_line(args,
646                     optargs,
647                     macros.macros(name = defaults,
648                                   sbdir = command_path),
649                     command_path)
650
651    overrides = None
652    if os.name == 'nt':
653        try:
654            import windows
655            overrides = windows.load()
656            host_windows = True
657            host_posix = False
658        except:
659            raise error.general('failed to load Windows host support')
660    elif os.name == 'posix':
661        uname = os.uname()
662        try:
663            if uname[0].startswith('MINGW64_NT'):
664                import windows
665                overrides = windows.load()
666                host_windows = True
667            elif uname[0].startswith('CYGWIN_NT'):
668                import windows
669                overrides = windows.load()
670            elif uname[0] == 'Darwin':
671                import darwin
672                overrides = darwin.load()
673            elif uname[0] == 'FreeBSD':
674                import freebsd
675                overrides = freebsd.load()
676            elif uname[0] == 'NetBSD':
677                import netbsd
678                overrides = netbsd.load()
679            elif uname[0] == 'Linux':
680                import linux
681                overrides = linux.load()
682            elif uname[0] == 'SunOS':
683                import solaris
684                overrides = solaris.load()
685        except error.general as ge:
686            raise error.general('failed to load %s host support: %s' % (uname[0], ge))
687        except:
688            raise error.general('failed to load %s host support' % (uname[0]))
689    else:
690        raise error.general('unsupported host type; please add')
691    if overrides is None:
692        raise error.general('no hosts defaults found; please add')
693    for k in overrides:
694        o.defaults[k] = overrides[k]
695
696    o.sb_released()
697    o.sb_git()
698    o.rtems_options()
699    o.pre_process()
700    o.process()
701    o.post_process(logfile)
702
703    #
704    # Load the release settings
705    #
706    def setting_error(msg):
707        raise error.general(msg)
708    hashes = version.load_release_settings('hashes')
709    for hash in hashes:
710        hs = hash[1].split()
711        if len(hs) != 2:
712            raise error.general('invalid release hash in VERSION')
713        sources.hash((hs[0], hash[0], hs[1]), o.defaults, setting_error)
714    release_path = version.load_release_setting('version', 'release_path',
715                                                raw = True)
716    if release_path is not None:
717        try:
718            release_path = ','.join([rp.strip() for rp in release_path.split(',')])
719        except:
720            raise error.general('invalid release path in VERSION')
721        download.set_release_path(release_path, o.defaults)
722    return o
723
724def run(args):
725    try:
726        _opts = load(args = args, defaults = 'defaults.mc')
727        log.notice('RTEMS Source Builder - Defaults, %s' % (version.string()))
728        _opts.log_info()
729        log.notice('Options:')
730        log.notice(str(_opts))
731        log.notice('Defaults:')
732        log.notice(str(_opts.defaults))
733        log.notice('with-opt1: %r' % (_opts.with_arg('opt1')))
734        log.notice('without-opt2: %r' % (_opts.with_arg('opt2')))
735    except error.general as gerr:
736        print(gerr)
737        sys.exit(1)
738    except error.internal as ierr:
739        print(ierr)
740        sys.exit(1)
741    except error.exit as eerr:
742        pass
743    except KeyboardInterrupt:
744        _notice(opts, 'abort: user terminated')
745        sys.exit(1)
746    sys.exit(0)
747
748if __name__ == '__main__':
749    run(sys.argv)
Note: See TracBrowser for help on using the repository browser.