1 | # |
---|
2 | # RTEMS Tools Project (http://www.rtems.org/) |
---|
3 | # Copyright 2010-2013 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 | # This code builds a package given a config file. It only builds to be |
---|
22 | # installed not to be package unless you run a packager around this. |
---|
23 | # |
---|
24 | |
---|
25 | import os |
---|
26 | import sys |
---|
27 | |
---|
28 | import build |
---|
29 | import check |
---|
30 | import config |
---|
31 | import defaults |
---|
32 | import error |
---|
33 | import log |
---|
34 | import setbuilder |
---|
35 | |
---|
36 | # |
---|
37 | # Version of Sourcer Builder Build. |
---|
38 | # |
---|
39 | version = '0.1' |
---|
40 | |
---|
41 | def _notice(opts, text): |
---|
42 | if not opts.quiet() and not log.default.has_stdout(): |
---|
43 | print text |
---|
44 | log.output(text) |
---|
45 | log.flush() |
---|
46 | |
---|
47 | class report: |
---|
48 | """Report the build details about a package given a config file.""" |
---|
49 | |
---|
50 | line_len = 78 |
---|
51 | |
---|
52 | def __init__(self, name, format, _configs, _defaults, opts): |
---|
53 | self.format = format |
---|
54 | self.name = name |
---|
55 | self.configs = _configs |
---|
56 | self.defaults = _defaults |
---|
57 | self.opts = opts |
---|
58 | self.bset_nesting = 0 |
---|
59 | self.configs_active = False |
---|
60 | |
---|
61 | def _output(self, text): |
---|
62 | if not self.opts.quiet(): |
---|
63 | log.output(text) |
---|
64 | |
---|
65 | def is_text(self): |
---|
66 | return self.format == 'text' |
---|
67 | |
---|
68 | def is_asciidoc(self): |
---|
69 | return self.format == 'asciidoc' |
---|
70 | |
---|
71 | def setup(self): |
---|
72 | if self.is_asciidoc(): |
---|
73 | pass |
---|
74 | |
---|
75 | def header(self): |
---|
76 | pass |
---|
77 | |
---|
78 | def footer(self): |
---|
79 | pass |
---|
80 | |
---|
81 | def introduction(self, name): |
---|
82 | if self.is_asciidoc(): |
---|
83 | h = 'RTEMS Source Builder Report' |
---|
84 | log.output(h) |
---|
85 | log.output('=' * len(h)) |
---|
86 | log.output(':doctype: book') |
---|
87 | log.output(':toc2:') |
---|
88 | log.output(':toclevels: 5') |
---|
89 | log.output(':icons:') |
---|
90 | log.output(':numbered:') |
---|
91 | log.output(' ') |
---|
92 | log.output('RTEMS Project <rtems-user@rtems.org>') |
---|
93 | log.output('28th Feb 2013') |
---|
94 | log.output(' ') |
---|
95 | else: |
---|
96 | log.output('report: %s' % (name)) |
---|
97 | |
---|
98 | def config_start(self, name): |
---|
99 | first = not self.configs_active |
---|
100 | self.configs_active = True |
---|
101 | if self.is_asciidoc(): |
---|
102 | log.output('.Config: %s' % name) |
---|
103 | log.output('') |
---|
104 | else: |
---|
105 | log.output('-' * self.line_len) |
---|
106 | log.output('config: %s' % (name)) |
---|
107 | |
---|
108 | def config_end(self, name): |
---|
109 | if self.is_asciidoc(): |
---|
110 | log.output(' ') |
---|
111 | log.output("'''") |
---|
112 | log.output(' ') |
---|
113 | |
---|
114 | def buildset_start(self, name): |
---|
115 | if self.is_asciidoc(): |
---|
116 | h = '%s' % (name) |
---|
117 | log.output('=%s %s' % ('=' * self.bset_nesting, h)) |
---|
118 | else: |
---|
119 | log.output('=' * self.line_len) |
---|
120 | log.output('build set: %s' % (name)) |
---|
121 | |
---|
122 | def buildset_end(self, name): |
---|
123 | self.configs_active = False |
---|
124 | |
---|
125 | def source(self, package, source_tag): |
---|
126 | return package.sources() |
---|
127 | |
---|
128 | def patch(self, package, args): |
---|
129 | return package.patches() |
---|
130 | |
---|
131 | def config(self, name): |
---|
132 | self.config_start(name) |
---|
133 | _config = config.file(name, _defaults = self.defaults, opts = self.opts) |
---|
134 | packages = _config.packages() |
---|
135 | package = packages['main'] |
---|
136 | name = package.name() |
---|
137 | if self.is_asciidoc(): |
---|
138 | log.output('*Package*: _%s_' % name) |
---|
139 | log.output(' ') |
---|
140 | else: |
---|
141 | log.output(' package: %s' % (name)) |
---|
142 | sources = package.sources() |
---|
143 | if self.is_asciidoc(): |
---|
144 | log.output('*Sources*;;') |
---|
145 | if len(sources) == 0: |
---|
146 | log.output('No sources') |
---|
147 | else: |
---|
148 | log.output(' sources: %d' % (len(sources))) |
---|
149 | c = 0 |
---|
150 | for s in sources: |
---|
151 | c += 1 |
---|
152 | if self.is_asciidoc(): |
---|
153 | log.output('. %s' % (sources[s][0])) |
---|
154 | else: |
---|
155 | log.output(' %2d: %s' % (c, sources[s][0])) |
---|
156 | patches = package.patches() |
---|
157 | if self.is_asciidoc(): |
---|
158 | log.output(' ') |
---|
159 | log.output('*Patches*:;;') |
---|
160 | if len(patches) == 0: |
---|
161 | log.output('No patches') |
---|
162 | else: |
---|
163 | log.output(' patches: %s' % (len(patches))) |
---|
164 | c = 0 |
---|
165 | for p in patches: |
---|
166 | c += 1 |
---|
167 | if self.is_asciidoc(): |
---|
168 | log.output('. %s' % (patches[p][0])) |
---|
169 | else: |
---|
170 | log.output(' %2d: %s' % (c, patches[p][0])) |
---|
171 | self.config_end(name) |
---|
172 | |
---|
173 | def buildset(self, name): |
---|
174 | try_config = False |
---|
175 | try: |
---|
176 | self.bset_nesting += 1 |
---|
177 | self.buildset_start(name) |
---|
178 | bset = setbuilder.buildset(name, |
---|
179 | _configs = self.configs, |
---|
180 | _defaults = self.defaults, |
---|
181 | opts = self.opts) |
---|
182 | for c in bset.load(): |
---|
183 | if c.endswith('.bset'): |
---|
184 | self.buildset(c) |
---|
185 | elif c.endswith('.cfg'): |
---|
186 | self.config(c) |
---|
187 | else: |
---|
188 | raise error.general('invalid config type: %s' % (c)) |
---|
189 | self.buildset_end(name) |
---|
190 | self.bset_nesting -= 1 |
---|
191 | except error.general, gerr: |
---|
192 | if gerr.msg.startswith('no build set file found'): |
---|
193 | try_config = True |
---|
194 | else: |
---|
195 | raise |
---|
196 | if try_config: |
---|
197 | self.config(name) |
---|
198 | |
---|
199 | def generate(self): |
---|
200 | self.introduction(self.name) |
---|
201 | self.buildset(self.name) |
---|
202 | |
---|
203 | def run(args): |
---|
204 | try: |
---|
205 | optargs = { '--list-bsets': 'List available build sets', |
---|
206 | '--list-configs': 'List available configurations', |
---|
207 | '--asciidoc': 'Output report as asciidoc' } |
---|
208 | opts, _defaults = defaults.load(args, optargs) |
---|
209 | log.default = log.log(opts.logfiles()) |
---|
210 | print 'RTEMS Source Builder, Reporter v%s' % (version) |
---|
211 | if not check.host_setup(opts, _defaults): |
---|
212 | _notice(opts, 'warning: forcing build with known host setup problems') |
---|
213 | configs = build.get_configs(opts, _defaults) |
---|
214 | if not setbuilder.list_bset_cfg_files(opts, configs): |
---|
215 | format = 'text' |
---|
216 | if opts.get_arg('--asciidoc'): |
---|
217 | format = 'asciidoc' |
---|
218 | for _file in opts.params(): |
---|
219 | r = report(_file, |
---|
220 | format = format, |
---|
221 | _configs = configs, |
---|
222 | _defaults = _defaults, |
---|
223 | opts = opts) |
---|
224 | r.generate() |
---|
225 | del r |
---|
226 | except error.general, gerr: |
---|
227 | print gerr |
---|
228 | sys.exit(1) |
---|
229 | except error.internal, ierr: |
---|
230 | print ierr |
---|
231 | sys.exit(1) |
---|
232 | except error.exit, eerr: |
---|
233 | pass |
---|
234 | except KeyboardInterrupt: |
---|
235 | _notice(opts, 'user terminated') |
---|
236 | sys.exit(1) |
---|
237 | sys.exit(0) |
---|
238 | |
---|
239 | if __name__ == "__main__": |
---|
240 | run(sys.argv) |
---|