source: rtems-source-builder/source-builder/sb/sources.py @ 158ad68

4.11
Last change on this file since 158ad68 was 158ad68, checked in by Chris Johns <chrisj@…>, on 10/03/20 at 11:53:04

sb: Back port the RTEMS 5 and 6 RSB engine.

  • Build GDb first as we do for RTEMS 5 and later
  • Update GDB to 9.1 for all archs expect SPARC. The SIS patches only apply to 7.9. Disable Python for SPARC

Closes #4111

  • Property mode set to 100644
File size: 5.7 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2014 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# Manage sources and patches
22#
23
24from . import log
25
26def _args(args):
27    return [i for s in [ii.split() for ii in args] for i in s]
28
29def _make_key(label, index):
30    return '%s%04d' % (label, index)
31
32def add(label, args, macros, error):
33    args = _args(args)
34    if len(args) < 2:
35        error('%%%s requires at least 2 arguments' % (label))
36    _map = '%s-%s' % (label, args[0])
37    _value = ' '.join(args[1:])
38    macros.create_map(_map)
39    index = 0
40    while True:
41        key = _make_key(label, index)
42        if key not in macros.map_keys(_map):
43            break
44        macros.set_read_map(_map)
45        value = macros.get_value(key)
46        macros.unset_read_map(_map)
47        if value == _value:
48            error('%%%s duplicate add: %s' % (label, _value))
49        index += 1
50    macros.set_write_map(_map)
51    macros.define(key, _value)
52    macros.unset_write_map()
53    return None
54
55def set(label, args, macros, error):
56    args = _args(args)
57    if len(args) < 2:
58        error('%%%s set requires at least 2 arguments' % (label))
59        return []
60    _map = '%s-%s' % (label, args[0])
61    macros.create_map(_map)
62    key = _make_key(label, 0)
63    if key not in macros.map_keys(_map):
64        macros.set_write_map(_map)
65        macros.define(key, ' '.join(args[1:]))
66        macros.unset_write_map()
67    return None
68
69def setup(label, args, macros, error):
70    args = _args(args)
71    if len(args) < 2:
72        error('%%%s setup requires at least 2 arguments: %s' % (label, ' '.join(args)))
73    ss = '%%setup %s %s' % (label, ' '.join(args))
74    _map = '%s-%s' % (label, args[0])
75    if 'setup' in macros.map_keys(_map):
76        error('%%%s already setup source: %s' % (label, ' '.join(args)))
77        return []
78    macros.set_write_map(_map)
79    macros.define('setup', ss)
80    macros.unset_write_map()
81    return [ss]
82
83def download(label, args, macros, error):
84    args = _args(args)
85    if len(args) != 1:
86        error('%%%s download requires 1 argument: %s' % (label, ' '.join(args)))
87    ss = '%%setup %s %s -g' % (label, ' '.join(args))
88    _map = '%s-%s' % (label, args[0])
89    if 'setup' in macros.map_keys(_map):
90        error('%%%s already setup source: %s' % (label, ' '.join(args)))
91        return []
92    macros.set_write_map(_map)
93    macros.define('setup', ss)
94    macros.unset_write_map()
95    return [ss]
96
97def process(label, args, macros, error):
98    if label != 'source' and label != 'patch':
99        error('invalid source type: %s' % (label))
100    args = _args(args)
101    log.trace('sources: %s' % (' '.join(args)))
102    if args[0] == 'set':
103        return set(label, args[1:], macros, error)
104    elif args[0] == 'add':
105        return add(label, args[1:], macros, error)
106    elif args[0] == 'setup':
107        return setup(label, args[1:], macros, error)
108    elif args[0] == 'download':
109        return download(label, args[1:], macros, error)
110    error('invalid %%%s command: %s' % (label, args[0]))
111
112def hash(args, macros, error):
113    args = _args(args)
114    if len(args) != 3:
115        error('invalid number of hash args')
116        return
117    _map = 'hashes'
118    _file = macros.expand(args[1])
119    new_value = '%s %s' % (args[0], args[2])
120    existing_value = get_hash(_file, macros)
121    if existing_value is not None:
122        if existing_value != new_value:
123            error('conflicting hash definitions for: %s' % (args[1]))
124            return
125    else:
126        macros.create_map(_map)
127        macros.set_write_map(_map)
128        macros.define(_file, new_value)
129        macros.unset_write_map()
130    return None
131
132def get(label, name, macros, error):
133    _map = '%s-%s' % (label, name)
134    keys = macros.map_keys(_map)
135    if len(keys) == 0:
136        error('no %s set: %s (%s)' % (label, name, _map))
137        return
138    srcs = []
139    for s in keys:
140        sm = macros.get(s, globals = False, maps = _map)
141        if sm is None:
142            error('source macro not found: %s in %s (%s)' % (s, name, _map))
143        srcs += [sm[2]]
144    return srcs
145
146def get_sources(name, macros, error):
147    return get('source', name, macros, error)
148
149def get_patches(name, macros, error):
150    return get('patch', name, macros, error)
151
152def get_keys(label, name, macros, error):
153    _map = '%s-%s' % (label, name)
154    return macros.map_keys(_map)
155
156def get_source_keys(name, macros, error):
157    return get_keys('source', name, macros, error)
158
159def get_patch_keys(name, macros, error):
160    return get_keys('patch', name, macros, error)
161
162def get_names(label, macros, error):
163    names = []
164    for m in macros.maps():
165        if m.startswith('%s-' % (label)):
166            names += [m[len('%s-' % (label)):]]
167    return names
168
169def get_source_names(macros, error):
170    return get_names('source', macros, error)
171
172def get_patch_names(macros, error):
173    return get_names('patch', macros, error)
174
175def get_hash(name, macros):
176    hash = None
177    if name in macros.map_keys('hashes'):
178        m1, m2, hash = macros.get(name, globals = False, maps = 'hashes')
179    return hash
Note: See TracBrowser for help on using the repository browser.