source: rtems-source-builder/source-builder/sb/sources.py @ 4b7af07

5
Last change on this file since 4b7af07 was 4b7af07, checked in by Chris Johns <chrisj@…>, on 09/12/19 at 10:09:13

5/llvm: Add LLVM as a package for RTEMS.

  • Add '%source download <source>' to only download the source and do not unpack and prep. This can used when a package internally needs another source package.
  • Install the staging root only if it is present. A package may internally build another package that is not staged as it is not suitable for installing.

Updates #3250
Updatew #3797

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