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

4.104.11
Last change on this file since faa8181 was faa8181, checked in by Chris Johns <chrisj@…>, on Feb 22, 2011 at 3:46:44 AM

2011-02-22 Chris Johns <chrisj@…>

  • specbuilder/sb-versions, specbuilder/specbuilder/version.py: New. Print a suitable version message for automatic documentation updating from the spec files in CVS.
  • specbuilder/specbuilder/build.py: Add xz support. Add a function to return the name of a package.
  • specbuilder/specbuilder/crossgcc.py: Use the build name in the tmp path.
  • specbuilder/specbuilder/darwin.py: Add xz support.
  • specbuilder/specbuilder/defaults.py: Add xz support. Add Windows and Linux support.
  • specbuilder/specbuilder/setup.py: Reference the correct shell opts. Use the shell setup in the version probe command. Fix the version check. Add autotools to the list of spec files to install.
  • specbuilder/specbuilder/spec.py: Add changelog and configure tests. Manage sub-packages better.
  • specbuilder/specbuilder/version.py, specbuilder/specbuilder/windows.py: New.
  • Property mode set to 100644
File size: 4.9 KB
Line 
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):
75        what = _build.spec.expand('crossgcc-%(%{__id_u} -n)-' + _build.name())
76        path = os.path.join(_build.spec.abspath('%{_tmppath}'), what)
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)
89        _build.cleanup()
90
91    def last_package(self, _build, path):
92        tar = os.path.join('%{_rpmdir}', self.arch + '-tools.tar.bz2')
93        cmd = _build.spec.expand("'cd " + path + \
94                                     " && %{__tar} -cf - . | %{__bzip2} > " + tar + "'")
95        _build.run(cmd, shell_opts = '-c', cwd = path)
96        if not self.opts.no_clean():
97            _build.rmdir(path)
98
99    def make(self):
100
101        def _sort(specs):
102            _specs = {}
103            for spec in specs:
104                for order in crossgcc._order:
105                    if spec.lower().find(order) >= 0:
106                        _specs[spec] = crossgcc._order[order]
107            sorted_specs = sorted(_specs.iteritems(), key = operator.itemgetter(1))
108            specs = []
109            for s in range(0, len(sorted_specs)):
110                specs.append(sorted_specs[s][0])
111            return specs
112
113        _notice(self.opts, 'arch: ' + self.arch)
114        specs = self.opts.get_spec_files('*' + self.arch + '*')
115        arch_specs = []
116        for spec in specs:
117            if spec.lower().find(self.arch.lower()) >= 0:
118                arch_specs.append(spec)
119        arch_specs = _sort(arch_specs)
120        self.opts.opts['no-clean'] = '1'
121        current_path = os.environ['PATH']
122        try:
123            for s in range(0, len(arch_specs)):
124                b = build.build(arch_specs[s], _defaults = self.defaults, opts = self.opts)
125                if s == 0:
126                    path = self.first_package(b)
127                b.make()
128                self.every_package(b, path)
129                if s == len(arch_specs) - 1:
130                    self.last_package(b, path)
131                del b
132        finally:
133            os.environ['PATH'] = current_path
134
135def run():
136    import sys
137    try:
138        opts, _defaults = defaults.load(sys.argv)
139        log.default = log.log(opts.logfiles())
140        _notice(opts, 'RTEMS Tools, CrossGCC Spec Builder, v%s' % (version))
141        for arch in opts.params():
142            c = crossgcc(arch, _defaults = _defaults, opts = opts)
143            c.make()
144            del c
145    except error.general, gerr:
146        print gerr
147        sys.exit(1)
148    except error.internal, ierr:
149        print ierr
150        sys.exit(1)
151    except KeyboardInterrupt:
152        _notice(opts, 'user terminated')
153        sys.exit(1)
154    sys.exit(0)
155
156if __name__ == "__main__":
157    run()
Note: See TracBrowser for help on using the repository browser.