Changeset 3bd8def in rtems-tools


Ignore:
Timestamp:
Oct 3, 2018, 1:38:09 AM (8 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
36fde51
Parents:
5416cfa
Message:

config: Consolidate the version information into a single configuration file

Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • rtemstoolkit/check.py

    r5416cfa r3bd8def  
    169169        _opts = options.command_line(argv = sys.argv)
    170170        options.load(_opts)
    171         log.notice('RTEMS Source Builder - Check, v%s' % (version.str()))
     171        log.notice('RTEMS Source Builder - Check, v%s' % (version.string()))
    172172        if host_setup(_opts):
    173173            print('Environment is ok')
  • rtemstoolkit/options.py

    r5416cfa r3bd8def  
    290290    def help(self):
    291291        print('%s: [options] [args]' % (self.command_name))
    292         print('RTEMS Tools Project (c) 2012-2015 Chris Johns')
     292        print('RTEMS Tools Project, %s' % (version.string()))
    293293        print('Options and arguments:')
    294294        opts = list(self.long_opts_help.keys())
     
    560560                            command_path = '.')
    561561        load(opts)
    562         log.notice('RTEMS Tools Project - Defaults, v%s' % (version.str()))
     562        log.notice('RTEMS Tools Project - Defaults, v%s' % (version.string()))
    563563        opts.log_info()
    564564        log.notice('Options:')
  • rtemstoolkit/rtems.py

    r5416cfa r3bd8def  
    11#
    22# RTEMS Tools Project (http://www.rtems.org/)
    3 # Copyright 20162018 Chris Johns (chrisj@rtems.org)
     3# Copyright 2016-2018 Chris Johns (chrisj@rtems.org)
    44# All rights reserved.
    55#
     
    3434import os
    3535import re
     36import sys
    3637import textwrap
    3738
    3839from rtemstoolkit import configuration as configuration_
    3940from rtemstoolkit import error
     41from rtemstoolkit import path
    4042from rtemstoolkit import textbox
    41 from rtemstoolkit import version
    42 
     43
     44#
     45# The default path we install RTEMS under
     46#
     47_prefix_path = '/opt/rtems'
     48
     49def default_prefix():
     50    from rtemstoolkit import version
     51    return path.join(_prefix_path, version.version())
    4352
    4453def clean_windows_path():
    45     #
    46     # On Windows MSYS2 prepends a path to itself to the environment
    47     # path. This means the RTEMS specific automake is not found and which
    48     # breaks the bootstrap. We need to remove the prepended path. Also
    49     # remove any ACLOCAL paths from the environment.
    50     #
     54    '''On Windows MSYS2 prepends a path to itself to the environment path. This
     55    means the RTEMS specific automake is not found and which breaks the
     56    bootstrap. We need to remove the prepended path. Also remove any ACLOCAL
     57    paths from the environment.
     58
     59    '''
    5160    if os.name == 'nt':
    5261        cspath = os.environ['PATH'].split(os.pathsep)
    5362        if 'msys' in cspath[0] and cspath[0].endswith('bin'):
    5463            os.environ['PATH'] = os.pathsep.join(cspath[1:])
     64
     65def configuration_path():
     66    '''Return the path the configuration data path for RTEMS. The path is relative
     67    to the installed executable. Mangage the installed package and the in source
     68    tree when running from within the rtems-tools repo.
     69
     70    '''
     71    exec_name = os.path.abspath(sys.argv[0])
     72    for top in [os.path.dirname(exec_name),
     73                os.path.dirname(os.path.dirname(exec_name))]:
     74        config_path = path.join(top, 'share', 'rtems', 'config')
     75        if path.exists(config_path):
     76            break
     77        config_path = path.join(top, 'config')
     78        if path.exists(config_path):
     79            break
     80        config_path = None
     81    return config_path
     82
     83def configuration_file(config):
     84    '''Return the path to a configuration file for RTEMS. The path is relative to
     85    the installed executable or we are testing and running from within the
     86    rtems-tools repo.
     87
     88    '''
     89    return path.join(configuration_path(), config)
     90
     91def bsp_configuration_file():
     92    '''Return the path to the BSP configuration file for RTEMS. The path is
     93    relative to the installed executable or we are testing and running from
     94    within the rtems-tools repo.
     95
     96    '''
     97    return configuration_file('rtems-bsps.ini')
    5598
    5699class configuration:
  • rtemstoolkit/version.py

    r5416cfa r3bd8def  
    11#
    22# RTEMS Tools Project (http://www.rtems.org/)
    3 # Copyright 2010-2016 Chris Johns (chrisj@rtems.org)
     3# Copyright 2010-2018 Chris Johns (chrisj@rtems.org)
    44# All rights reserved.
    55#
     
    3030
    3131#
    32 # To release RTEMS Tools create a git archive and then add a suitable VERSION
    33 # file to the top directory.
     32# Releasing RTEMS Tools
     33# ---------------------
     34#
     35# Format:
     36#
     37#  The format is INI. The file requires a `[version`] section and a `revision`
     38#  option:
     39#
     40#   [version]
     41#   revision = <version-string>
     42#
     43#  The `<version-string>` has the `version` and `revision` delimited by a
     44#  single `.`. An example file is:
     45#
     46#   [version]
     47#   revision = 5.0.not_released
     48#
     49#  where the `version` is `5` and the revision is `0` and the package is not
     50#  released. The label `not_released` is reversed to mean the package is not
     51#  released. A revision string can contain extra characters after the
     52#  `revision` number for example `5.0-rc1` or is deploying a package
     53#  `5.0-nasa-cfs`
     54#
     55#  Packages can optionally add specialised sections to a version configuration
     56#  files. These can be accessed via the:
     57#
     58#   load_release_settings: Return the items in a section
     59#   load_release_setting: Return an item from a section
     60#
     61# User deployment:
     62#
     63#  Create a git archive and then add a suitable VERSION file to the top
     64#  directory of the package. The package assumes your python executable is
     65#  location in `bin` directory which is one below the top of the package's
     66#  install prefix.
     67#
     68# RTEMS Release:
     69#
     70#  Set the values in the `rtems-version.ini` file. This is a shared file so
     71#  packages and encouraged to add specific settings to other configuration
     72#  files.
     73#
     74# Notes:
     75#
     76#  This module uses os.apth for paths and assumes all paths are in the host
     77#  format.
    3478#
    3579
    3680from __future__ import print_function
    3781
     82import itertools
     83import os
    3884import sys
    3985
    40 #
    41 # Support to handle use in a package and as a unit test.
     86try:
     87    import configparser
     88except ImportError:
     89    import ConfigParser as configparser
     90
     91#
     92# Support to handle importing when installed in a package and as a unit test.
    4293# If there is a better way to let us know.
    4394#
     
    4596    from . import error
    4697    from . import git
    47     from . import path
     98    from . import rtems
    4899except (ValueError, SystemError):
    49100    import error
    50101    import git
    51102    import path
     103    import rtems
    52104
    53105#
    54106# Default to an internal string.
    55107#
    56 _version = '5'
     108_version = 'undefined'
    57109_revision = 'not_released'
    58110_version_str = '%s.%s' % (_version, _revision)
    59111_released = False
    60112_git = False
    61 
    62 def _at():
    63     return path.dirname(__file__)
     113_is_loaded = False
     114
     115def _top():
     116    top = os.path.dirname(sys.argv[0])
     117    if len(top) == 0:
     118        top = '.'
     119    return top
     120
     121def _load_released_version_config():
     122    '''Local worker to load a configuration file.'''
     123    top = _top()
     124    for ver in [os.path.join(top, 'VERSION'),
     125                os.path.join('..', 'VERSION'),
     126                rtems.configuration_file('rtems-version.ini')]:
     127        if os.path.exists(os.path.join(ver)):
     128            v = configparser.SafeConfigParser()
     129            try:
     130                v.read(ver)
     131            except Exception as e:
     132                raise error.general('Invalid version config format: %s: %s' % (ver,
     133                                                                               e))
     134            return ver, v
     135    return None, None
    64136
    65137def _load_released_version():
     138    '''Load the release data if present. If not found the package is not released.
     139
     140    A release can be made by adding a file called `VERSION` to the top level
     141    directory of a package. This is useful for user deploying a package and
     142    making custom releases.
     143
     144    The RTEMS project reserves the `rtems-version.ini` file for it's
     145    releases. This is the base release and should not be touched by users
     146    deploying a package.
     147
     148    '''
     149    global _version
     150    global _revision
    66151    global _released
    67152    global _version_str
    68     at = _at()
    69     for ver in [at, path.join(at, '..')]:
    70         if path.exists(path.join(ver, 'VERSION')):
    71             try:
    72                 import configparser
    73             except ImportError:
    74                 import ConfigParser as configparser
    75             v = configparser.SafeConfigParser()
    76             v.read(path.join(ver, 'VERSION'))
    77             _version_str = v.get('version', 'release')
    78             _released = True
     153    global _is_loaded
     154
     155    if not _is_loaded:
     156        vc, v = _load_released_version_config()
     157        if v is not None:
     158            try:
     159                ver_str = v.get('version', 'revision')
     160            except Exception as e:
     161                raise error.general('Invalid version file: %s: %s' % (vc, e))
     162            ver_split = ver_str.split('.')
     163            if len(ver_split) < 2:
     164                raise error.general('Invalid version release value: %s: %s' % (vc,
     165                                                                               ver_str))
     166            ver = ver_split[0]
     167            rev = '.'.join(ver_split[1:])
     168            try:
     169                _version = int(ver)
     170            except:
     171                raise error.general('Invalid version config value: %s: %s' % (vc,
     172                                                                              ver))
     173            try:
     174                _revision = int(''.join(itertools.takewhile(str.isdigit, rev)))
     175            except Exception as e:
     176                raise error.general('Invalid revision config value: %s: %s: %s' % (vc,
     177                                                                                   rev,
     178                                                                                   e))
     179            if not 'not_released' in ver:
     180                _released = True
     181            _version_str = ver_str
     182            _is_loaded = True
    79183    return _released
    80184
    81185def _load_git_version():
     186    global _version
     187    global _revision
    82188    global _git
    83189    global _version_str
    84     repo = git.repo(_at())
     190    repo = git.repo(_top())
    85191    if repo.valid():
    86192        head = repo.head()
    87193        if repo.dirty():
    88             modified = ' modified'
     194            modified = 'modified'
     195            sep = ' '
    89196        else:
    90197            modified = ''
    91         _version_str = '%s (%s%s)' % (_version, head[0:12], modified)
     198            sep = ''
     199        _revision = '%s-%s' % (head[0:12], modified)
     200        _version_str = '%s (%s%s%s)' % (_version, head[0:12], sep, modified)
    92201        _git = True
    93202    return _git
    94203
     204def load_release_settings(section, error = False):
     205    vc, v = _load_released_version_config()
     206    items = []
     207    if v is not None:
     208        try:
     209            items = v.items(section)
     210        except Exception as e:
     211            if not isinstance(error, bool):
     212                error(e)
     213            elif error:
     214                raise error.general('Invalid config section: %s: %s: %s' % (vc,
     215                                                                            section,
     216                                                                            e))
     217    return items
     218
     219def load_release_setting(section, option, raw = False, error = False):
     220    vc, v = _load_released_version_config()
     221    value = None
     222    if v is not None:
     223        try:
     224            value = v.get(section, option, raw = raw)
     225        except Exception as e:
     226            if not isinstance(error, bool):
     227                error(e)
     228            elif error:
     229                raise error.general('Invalid config section: %s: %s: %s.%s' % (vc,
     230                                                                               section,
     231                                                                               option,
     232                                                                               e))
     233    return value
     234
    95235def released():
    96236    return _load_released_version()
     
    99239    return _load_git_version()
    100240
    101 def str():
    102     if not _released and not _git:
    103         if not _load_released_version():
    104             _load_git_version()
     241def string():
     242    _load_released_version()
     243    _load_git_version()
    105244    return _version_str
    106245
    107246def version():
     247    _load_released_version()
     248    _load_git_version()
    108249    return _version
     250
     251def revision():
     252    _load_released_version()
     253    _load_git_version()
     254    return _revision
    109255
    110256if __name__ == '__main__':
  • tester/rt/check.py

    r5416cfa r3bd8def  
    6565max_build_label = 0
    6666
     67def _now():
     68    return datetime.datetime.now()
     69
    6770def rtems_version():
    6871    return version.version()
     
    100103
    101104def title():
    102     return 'RTEMS Tools Project - RTEMS Kernel BSP Builder, %s' % (version.str())
     105    return 'RTEMS Tools Project - RTEMS Kernel BSP Builder, %s' % (version.string())
    103106
    104107def command_line():
     
    157160
    158161    def start(self):
    159         self.start_time = datetime.datetime.now()
     162        self.start_time = _now()
    160163
    161164    def stop(self):
    162         self.stop_time = datetime.datetime.now()
     165        self.stop_time = _now()
    163166
    164167    def duration(self):
     
    989992                f.write(title() + os.linesep)
    990993                f.write(os.linesep)
    991                 f.write('Date: %s%s' % (datetime.datetime.now().strftime('%c'),
    992                                         os.linesep))
     994                f.write('Date: %s%s' % (_now().strftime('%c'), os.linesep))
    993995                f.write(os.linesep)
    994996                f.write(command_line() + os.linesep)
     
    10001002                f.write(title() + os.linesep)
    10011003                f.write(os.linesep)
    1002                 f.write('Date: %s%s' % (datetime.datetime.now().strftime('%c'),
    1003                                         os.linesep))
     1004                f.write('Date: %s%s' % (_now().strftime('%c'), os.linesep))
    10041005                f.write(os.linesep)
    10051006                f.write(command_line() + os.linesep)
     
    10231024            log.notice('Cleaning: %s' % (self.build_dir))
    10241025            path.removeall(self.build_dir)
    1025         self.start = datetime.datetime.now()
    1026         self.end = datetime.datetime.now()
     1026        self.start = _now()
     1027        self.end = _now()
    10271028        self.duration = self.end - self.start
    10281029        self.average = self.duration
     
    10641065                    pass
    10651066            raise
    1066         self.end = datetime.datetime.now()
     1067        self.end = _now()
    10671068        os.environ['PATH'] = env_path
    10681069        self.duration = self.end - self.start
     
    11241125        rtems.clean_windows_path()
    11251126
    1126         start = datetime.datetime.now()
    1127         top = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
     1127        start = _now()
    11281128        prefix = '/opt/rtems/%s' % (rtems_version())
    11291129        tools = prefix
    11301130        build_dir = 'bsp-builds'
    1131         logf = 'bsp-build-%s.txt' % \
    1132                (datetime.datetime.now().strftime('%Y%m%d-%H%M%S'))
    1133         config_file = path.join(top, 'config', 'rtems-bsps.ini')
    1134         if not path.exists(config_file):
    1135             config_file = path.join(top, 'share', 'rtems', 'config', 'rtems-bsps.ini')
     1131        logf = 'bsp-build-%s.txt' % (_now().strftime('%Y%m%d-%H%M%S'))
     1132        config_file = rtems.bsp_configuration_file()
    11361133
    11371134        argsp = argparse.ArgumentParser()
     
    12501247            what = 'Profile(s): %s' % (' '.join(profiles))
    12511248            b.build_profiles(profiles)
    1252         end = datetime.datetime.now()
     1249        end = _now()
    12531250
    12541251        #
  • tester/rt/options.py

    r5416cfa r3bd8def  
    110110    try:
    111111        _opts = load(args = args, defaults = defaults_mc)
    112         log.notice('RTEMS Test - Defaults, v%s' % (version.str()))
     112        log.notice('RTEMS Test - Defaults, v%s' % (version.string()))
    113113        _opts.log_info()
    114114        log.notice('Options:')
  • tester/rt/run.py

    r5416cfa r3bd8def  
    115115                            optargs = optargs,
    116116                            command_path = command_path)
    117         log.notice('RTEMS Testing - Run, %s' % (version.str()))
     117        log.notice('RTEMS Testing - Run, %s' % (version.string()))
    118118        if opts.find_arg('--list-bsps'):
    119119            bsps.list(opts)
  • tester/rt/test.py

    r5416cfa r3bd8def  
    251251                to_addr = 'build@rtems.org'
    252252            output = log_capture()
    253         log.notice('RTEMS Testing - Tester, %s' % (version.str()))
     253        log.notice('RTEMS Testing - Tester, %s' % (version.string()))
    254254        if opts.find_arg('--list-bsps'):
    255255            bsps.list(opts)
  • wscript

    r5416cfa r3bd8def  
    4141
    4242def get_version(ctx):
    43     version = '5'
    44     revision = 'not_released'
     43    from rtemstoolkit import version as rtemsversion
     44    try:
     45        version = rtemsversion.version()
     46        revision = rtemsversion.revision()
     47    except Exception as e:
     48        ctx.fatal('invalid version file: %s' % (e))
    4549    release = '%s.%s' % (version, revision)
    46     if os.path.exists('VERSION'):
    47         try:
    48             import configparser
    49         except ImportError:
    50             import ConfigParser as configparser
    51         v = configparser.SafeConfigParser()
    52         v.read('VERSION')
    53         release = v.get('version', 'release')
    54     else:
    55         #
    56         # waf after 1.9.9 does not place the current directory in Python's
    57         # system path which means importing the RTEMS toolkit
    58         # fails. Temporarily add it so we can import the git module.
    59         #
    60         import sys
    61         current_sys_path = sys.path
    62         try:
    63             sys.path = [os.getcwd()] + sys.path
    64             from rtemstoolkit import git
    65         finally:
    66             sys.path = current_sys_path
    67         repo = git.repo('.')
    68         if repo.valid():
    69             head = repo.head()
    70             if repo.dirty():
    71                 modified = '_modified'
    72             else:
    73                 modified = ''
    74             release = '%s.%s%s' % (version, head[0:12], modified)
    75     last_dot = release.rfind('.')
    76     if last_dot == -1:
    77         ctx.fatal('invalid VERSION file')
    78     revision = release[0:last_dot]
    79     return revision, release
     50    return version, release
    8051
    8152def recurse(ctx):
Note: See TracChangeset for help on using the changeset viewer.