source: rtems-tools/specbuilder/specbuilder/crossgcc.py @ a86cd82

4.104.115
Last change on this file since a86cd82 was a86cd82, checked in by Chris Johns <chrisj@…>, on 06/09/11 at 05:59:32

2011-06-09 Chris Johns <chrisj@…>

  • specbuilder/specbuilder/build.py, specbuilder/specbuilder/crossgcc.py, specbuilder/specbuilder/defaults.py, specbuilder/specbuilder/linux.py, specbuilder/specbuilder/spec.py: Add CentOS support for older Pythons. Add options to build the tools with specific flags.
  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[7231f49]1#
2# $Id$
3#
4# RTEMS Tools Project (http://www.rtems.org/)
5# Copyright 2010 Chris Johns (chrisj@rtems.org)
6# All rights reserved.
7#
8# This file is part of the RTEMS Tools package in 'rtems-tools'.
9#
10# RTEMS Tools is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# RTEMS Tools is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with RTEMS Tools.  If not, see <http://www.gnu.org/licenses/>.
22#
23
24#
25# This code builds a cross-gcc compiler suite of tools given an architecture.
26#
27
28import distutils.dir_util
29import operator
30import os
31
32import build
33import defaults
34import error
35import log
36
37#
38# Version of Spec CrossGCC Builder.
39#
40version = '0.1'
41
42def _notice(opts, text):
43    if not opts.quiet() and not log.default.has_stdout():
44        print text
45    log.output(text)
46    log.flush()
47
48class crossgcc:
49    """Build a Cross GCC Compiler tool suite."""
50
51    _order = { 'binutils': 0,
52               'gcc'     : 1,
53               'gdb'     : 2 }
54
55    def __init__(self, arch, _defaults, opts):
56        self.arch = arch
57        self.opts = opts
58        self.defaults = _defaults
59
60    def _output(self, text):
61        if not self.opts.quiet():
62            log.output(text)
63
64    def copy(self, src, dst):
65        what = src + ' -> ' + dst
66        _notice(self.opts, 'coping: ' + what)
67        try:
68            files = distutils.dir_util.copy_tree(src, dst)
69            for f in files:
70                self._output(f)
71        except IOError, err:
72            raise error.general('coping tree: ' + what + ': ' + str(err))
73
74    def first_package(self, _build):
[faa8181]75        what = _build.spec.expand('crossgcc-%(%{__id_u} -n)-' + _build.name())
76        path = os.path.join(_build.spec.abspath('%{_tmppath}'), what)
[7231f49]77        _build.rmdir(path)
78        _build.mkdir(path)
79        prefix = os.path.join(_build.spec.expand('%{_prefix}'), 'bin')
80        if prefix[0] == os.sep:
81            prefix = prefix[1:]
82        binpath = os.path.join(path, prefix)
83        os.environ['PATH'] = binpath + os.pathsep + os.environ['PATH']
84        self._output('path: ' + os.environ['PATH'])
85        return path
86
87    def every_package(self, _build, path):
88        self.copy(_build.spec.abspath('%{buildroot}'), path)
[a86cd82]89        if not self.opts.no_clean():
90            _build.cleanup()
[7231f49]91
92    def last_package(self, _build, path):
93        tar = os.path.join('%{_rpmdir}', self.arch + '-tools.tar.bz2')
94        cmd = _build.spec.expand("'cd " + path + \
95                                     " && %{__tar} -cf - . | %{__bzip2} > " + tar + "'")
96        _build.run(cmd, shell_opts = '-c', cwd = path)
97        if not self.opts.no_clean():
98            _build.rmdir(path)
99
100    def make(self):
101
102        def _sort(specs):
103            _specs = {}
104            for spec in specs:
105                for order in crossgcc._order:
106                    if spec.lower().find(order) >= 0:
107                        _specs[spec] = crossgcc._order[order]
108            sorted_specs = sorted(_specs.iteritems(), key = operator.itemgetter(1))
109            specs = []
110            for s in range(0, len(sorted_specs)):
111                specs.append(sorted_specs[s][0])
112            return specs
113
114        _notice(self.opts, 'arch: ' + self.arch)
115        specs = self.opts.get_spec_files('*' + self.arch + '*')
116        arch_specs = []
117        for spec in specs:
118            if spec.lower().find(self.arch.lower()) >= 0:
119                arch_specs.append(spec)
120        arch_specs = _sort(arch_specs)
121        self.opts.opts['no-clean'] = '1'
122        current_path = os.environ['PATH']
123        try:
124            for s in range(0, len(arch_specs)):
125                b = build.build(arch_specs[s], _defaults = self.defaults, opts = self.opts)
126                if s == 0:
127                    path = self.first_package(b)
128                b.make()
129                self.every_package(b, path)
130                if s == len(arch_specs) - 1:
131                    self.last_package(b, path)
132                del b
[a86cd82]133        except:
[7231f49]134            os.environ['PATH'] = current_path
[a86cd82]135            raise
136        os.environ['PATH'] = current_path
[7231f49]137
138def run():
139    import sys
140    try:
141        opts, _defaults = defaults.load(sys.argv)
142        log.default = log.log(opts.logfiles())
143        _notice(opts, 'RTEMS Tools, CrossGCC Spec Builder, v%s' % (version))
144        for arch in opts.params():
145            c = crossgcc(arch, _defaults = _defaults, opts = opts)
146            c.make()
147            del c
148    except error.general, gerr:
149        print gerr
150        sys.exit(1)
151    except error.internal, ierr:
152        print ierr
153        sys.exit(1)
154    except KeyboardInterrupt:
155        _notice(opts, 'user terminated')
156        sys.exit(1)
157    sys.exit(0)
158
159if __name__ == "__main__":
160    run()
Note: See TracBrowser for help on using the repository browser.