~ubuntu-branches/ubuntu/natty/jhbuild/natty

« back to all changes in this revision

Viewing changes to jhbuild/modtypes/linux.py

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort, Loic Minier, Emilio Pozuelo Monfort
  • Date: 2009-11-09 20:28:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091109202848-m9ec7dmzptqtchtj
Tags: 2.28.0-1
[ Loic Minier ]
* Cleanups.
* Ship scripts.
* Don't set GNOME_MODULE as it equals the name of the source package.

[ Emilio Pozuelo Monfort ]
* New upstream release. Closes: #524504.
  - Use 'git rev-parse' rather than 'git-rev-parse'. Closes: #544642.
* Ship install-check. Closes: #441008.
* Uploaders list regenerated. Closes: #523542, #554071.
* debian/control.in,
  debian/rules:
  - Stop shipping a copy of subprocess.py. Require python >= 2.4.
  - Switch to python-support.
* debian/control.in:
  - Bump Standards-Version to 3.8.3, no changes needed.
  - Build depend on intltool >= 0.35.0.
  - Build depend on pkg-config, gnome-doc-utils and rarian-compat to build
    the documentation.
  - Make jhbuild arch any since install-check is a binary. Depend on
    ${shlibs:Depends}.
  - Recommend, and not suggest, git-core. Also recommend mercurial.
* debian/watch:
  - Added.
* debian/patches/01_import_from_pkgdatadir.patch:
  - Added, import jhbuild from pkgdatadir if everything else fails.
    This way we can ship the jhbuild private modules in /usr/sharejhbuild.
* debian/jhbuild.docs:
  - Removed, the necessary docs are now installed by the upstream Makefile.
* debian/rules:
  - Include autotools.mk and gnome.mk.
  - Remove all the manual build process, autotools.mk does everything now.
  - Install the jhbuild modules in /usr/share/jhbuild.
* debian/install:
  - Install the modulesets and patches from here since the upstream build
    system doesn't install them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright (C) 2001-2006  James Henstridge
 
3
# Copyright (C) 2007  Red Hat, Inc.
 
4
#
 
5
#   linux.py: support for building the linux kernel
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; either version 2 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program; if not, write to the Free Software
 
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
 
 
21
__metaclass__ = type
 
22
 
 
23
import os
 
24
import re
 
25
import shutil
 
26
import errno
 
27
 
 
28
from jhbuild.errors import FatalError, BuildStateError
 
29
from jhbuild.modtypes import \
 
30
     Package, get_dependencies, get_branch, register_module_type
 
31
 
 
32
__all__ = [ 'LinuxModule' ]
 
33
 
 
34
 
 
35
class LinuxConfig:
 
36
 
 
37
    def __init__(self, version, path, branch):
 
38
        self.version = version
 
39
        self.path = path
 
40
        self.branch = branch
 
41
 
 
42
    def checkout(self, buildscript):
 
43
        if self.branch:
 
44
            self.branch.checkout(buildscript)
 
45
            if not os.path.exists(self.path):
 
46
                raise BuildStateError(_('kconfig file %s was not created') % self.path)
 
47
 
 
48
 
 
49
class LinuxModule(Package):
 
50
    '''For modules that are built with the linux kernel method of
 
51
    make config, make, make install and make modules_install.'''
 
52
    type = 'linux'
 
53
 
 
54
    PHASE_CHECKOUT        = 'checkout'
 
55
    PHASE_FORCE_CHECKOUT  = 'force_checkout'
 
56
    PHASE_CLEAN           = 'clean'
 
57
    PHASE_MRPROPER        = 'mrproper'
 
58
    PHASE_CONFIGURE       = 'configure'
 
59
    PHASE_BUILD           = 'build'
 
60
    PHASE_KERNEL_INSTALL  = 'kernel_install'
 
61
    PHASE_MODULES_INSTALL = 'modules_install'
 
62
    PHASE_HEADERS_INSTALL = 'headers_install'
 
63
    PHASE_INSTALL         = 'install'
 
64
 
 
65
    def __init__(self, name, branch, kconfigs, makeargs,
 
66
            dependencies, after, suggests):
 
67
        Package.__init__(self, name, dependencies, after, suggests)
 
68
        self.branch = branch
 
69
        self.kconfigs = kconfigs
 
70
        self.makeargs = makeargs
 
71
 
 
72
    def get_srcdir(self, buildscript):
 
73
        return self.branch.srcdir
 
74
 
 
75
    def get_builddir(self, buildscript):
 
76
        return self.get_srcdir(buildscript)
 
77
 
 
78
    def get_revision(self):
 
79
        return self.branch.branchname
 
80
 
 
81
    def skip_checkout(self, buildscript, last_phase):
 
82
        # skip the checkout stage if the nonetwork flag is set
 
83
        # (can't just call Package.skip_checkout() as build policy won't work
 
84
        # with kconfigs)
 
85
        return buildscript.config.nonetwork
 
86
 
 
87
    def do_checkout(self, buildscript):
 
88
        buildscript.set_action(_('Checking out'), self)
 
89
        self.checkout(buildscript)
 
90
        for kconfig in self.kconfigs:
 
91
            kconfig.checkout(buildscript)
 
92
    do_checkout.error_phases = [PHASE_MRPROPER]
 
93
 
 
94
    def do_force_checkout(self, buildscript):
 
95
        buildscript.set_action(_('Checking out'), self)
 
96
        self.branch.force_checkout(buildscript)
 
97
    do_force_checkout.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_MRPROPER]
 
98
 
 
99
    def get_makeargs(self):
 
100
        return self.makeargs + ' ' + self.config.module_makeargs.get(self.name, self.config.makeargs)
 
101
 
 
102
    def do_mrproper(self, buildscript):
 
103
        buildscript.set_action(_('make mrproper'), self)
 
104
        for kconfig in self.kconfigs:
 
105
            cmd = '%s %s mrproper EXTRAVERSION=%s O=%s' % (
 
106
                    os.environ.get('MAKE', 'make'),
 
107
                    self.get_makeargs(),
 
108
                    kconfig.version,
 
109
                    'build-' + kconfig.version)
 
110
            buildscript.execute(cmd, cwd = self.branch.srcdir,
 
111
                    extra_env = self.extra_env)
 
112
 
 
113
        cmd = '%s mrproper' % os.environ.get('MAKE', 'make')
 
114
        buildscript.execute(cmd, cwd = self.branch.srcdir,
 
115
                    extra_env = self.extra_env)
 
116
    do_mrproper.depends = [PHASE_CHECKOUT]
 
117
 
 
118
    def do_configure(self, buildscript):
 
119
        buildscript.set_action(_('Configuring'), self)
 
120
 
 
121
        for kconfig in self.kconfigs:
 
122
            if kconfig.path:
 
123
                shutil.copyfile(kconfig.path, os.path.join(self.branch.srcdir, ".config"))
 
124
 
 
125
            try:
 
126
                os.makedirs(os.path.join(self.branch.srcdir, 'build-' + kconfig.version))
 
127
            except OSError, (e, msg):
 
128
                if e != errno.EEXIST:
 
129
                    raise
 
130
 
 
131
            if kconfig.branch:
 
132
                cmd = '%s oldconfig EXTRAVERSION=%s O=%s'
 
133
            else:
 
134
                cmd = '%s defconfig EXTRAVERSION=%s O=%s'
 
135
 
 
136
            cmd = cmd % (
 
137
                    os.environ.get('MAKE', 'make'),
 
138
                    kconfig.version,
 
139
                    'build-' + kconfig.version)
 
140
 
 
141
            buildscript.execute(cmd, cwd = self.branch.srcdir,
 
142
                    extra_env = self.extra_env)
 
143
 
 
144
            if kconfig.path:
 
145
                os.remove(os.path.join(self.branch.srcdir, ".config"))
 
146
 
 
147
    do_configure.depends = [PHASE_MRPROPER]
 
148
    do_configure.error_phases = [PHASE_FORCE_CHECKOUT]
 
149
 
 
150
    def do_clean(self, buildscript):
 
151
        buildscript.set_action(_('Cleaning'), self)
 
152
        for kconfig in self.kconfigs:
 
153
            cmd = '%s %s clean EXTRAVERSION=%s O=%s' % (
 
154
                    os.environ.get('MAKE', 'make'),
 
155
                    self.get_makeargs(),
 
156
                    kconfig.version,
 
157
                    'build-' + kconfig.version)
 
158
            buildscript.execute(cmd, cwd = self.branch.srcdir,
 
159
                    extra_env = self.extra_env)
 
160
 
 
161
    do_clean.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
 
162
 
 
163
    def do_build(self, buildscript):
 
164
        buildscript.set_action(_('Building'), self)
 
165
        for kconfig in self.kconfigs:
 
166
            cmd = '%s %s EXTRAVERSION=%s O=%s' % (os.environ.get('MAKE', 'make'),
 
167
                                                  self.get_makeargs(),
 
168
                                                  kconfig.version,
 
169
                                                  'build-' + kconfig.version)
 
170
            buildscript.execute(cmd, cwd = self.branch.srcdir,
 
171
                    extra_env = self.extra_env)
 
172
 
 
173
    do_build.depends = [PHASE_CONFIGURE]
 
174
    do_build.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_MRPROPER, PHASE_CONFIGURE]
 
175
 
 
176
    def do_kernel_install(self, buildscript):
 
177
        buildscript.set_action(_('Installing kernel'), self)
 
178
        bootdir = os.path.join(buildscript.config.prefix, 'boot')
 
179
        if not os.path.isdir(bootdir):
 
180
            os.makedirs(bootdir)
 
181
        for kconfig in self.kconfigs:
 
182
            # We do this on our own without 'make install' because things will go weird on the user
 
183
            # if they have a custom installkernel script in ~/bin or /sbin/ and we can't override this.
 
184
            for f in ("System.map", ".config", "vmlinux"):
 
185
                cmd = "cp %s %s" % (
 
186
                    os.path.join('build-'+kconfig.version, f),
 
187
                    os.path.join(bootdir, f+'-'+kconfig.version))
 
188
                buildscript.execute(cmd, cwd = self.branch.srcdir,
 
189
                    extra_env = self.extra_env)
 
190
 
 
191
    do_kernel_install.depends = [PHASE_BUILD]
 
192
    do_kernel_install.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
 
193
 
 
194
    def do_modules_install(self, buildscript):
 
195
        buildscript.set_action(_('Installing modules'), self)
 
196
        for kconfig in self.kconfigs:
 
197
            cmd = '%s %s modules_install EXTRAVERSION=%s O=%s INSTALL_MOD_PATH=%s' % (
 
198
                    os.environ.get('MAKE', 'make'),
 
199
                    self.get_makeargs(),
 
200
                    kconfig.version,
 
201
                    'build-' + kconfig.version,
 
202
                    buildscript.config.prefix)
 
203
            buildscript.execute(cmd, cwd = self.branch.srcdir,
 
204
                    extra_env = self.extra_env)
 
205
 
 
206
    do_modules_install.depends = [PHASE_BUILD]
 
207
    do_modules_install.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
 
208
 
 
209
    def do_headers_install(self, buildscript):
 
210
        buildscript.set_action(_('Installing kernel headers'), self)
 
211
        for kconfig in self.kconfigs:
 
212
            cmd = '%s %s headers_install EXTRAVERSION=%s O=%s INSTALL_HDR_PATH=%s' % (
 
213
                    os.environ.get('MAKE', 'make'),
 
214
                    self.get_makeargs(),
 
215
                    kconfig.version,
 
216
                    'build-' + kconfig.version,
 
217
                    buildscript.config.prefix)
 
218
            buildscript.execute(cmd, cwd = self.branch.srcdir,
 
219
                    extra_env = self.extra_env)
 
220
        buildscript.packagedb.add(self.name, self.get_revision() or '')
 
221
 
 
222
    do_headers_install.depends = [PHASE_BUILD]
 
223
    do_headers_install.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
 
224
 
 
225
    def do_install(self, buildscript):
 
226
        pass
 
227
    do_install.depends = [PHASE_KERNEL_INSTALL, PHASE_MODULES_INSTALL, PHASE_HEADERS_INSTALL]
 
228
 
 
229
    def xml_tag_and_attrs(self):
 
230
        return 'linux', [('id', 'name', None),
 
231
                         ('makeargs', 'makeargs', '')]
 
232
 
 
233
 
 
234
def get_kconfigs(node, repositories, default_repo):
 
235
    id = node.getAttribute('id')
 
236
 
 
237
    kconfigs = []
 
238
 
 
239
    for childnode in node.childNodes:
 
240
        if childnode.nodeType != childnode.ELEMENT_NODE or childnode.nodeName != 'kconfig':
 
241
            continue
 
242
 
 
243
        if childnode.hasAttribute('repo'):
 
244
            repo_name = childnode.getAttribute('repo')
 
245
            try:
 
246
                repo = repositories[repo_name]
 
247
            except KeyError:
 
248
                raise FatalError(_('Repository=%s not found for kconfig in linux id=%s. Possible repositories are %s') % (repo_name, id, repositories))
 
249
        else:
 
250
            try:
 
251
                repo = repositories[default_repo]
 
252
            except KeyError:
 
253
                raise FatalError(_('Default Repository=%s not found for kconfig in module id=%s. Possible repositories are %s') % (default_repo, id, repositories))
 
254
 
 
255
        branch = repo.branch_from_xml(id, childnode, repositories, default_repo)
 
256
 
 
257
        version = childnode.getAttribute('version')
 
258
 
 
259
        if childnode.hasAttribute('config'):
 
260
            path = os.path.join(kconfig.srcdir, childnode.getAttribute('config'))
 
261
        else:
 
262
            path = kconfig.srcdir
 
263
 
 
264
        kconfig = LinuxConfig(version, path, branch)
 
265
        kconfigs.append(kconfig)
 
266
 
 
267
    if not kconfigs:
 
268
        kconfig = LinuxConfig('default', None, None)
 
269
        kconfigs.append(kconfig)
 
270
 
 
271
    return kconfigs
 
272
 
 
273
def parse_linux(node, config, uri, repositories, default_repo):
 
274
    id = node.getAttribute('id')
 
275
 
 
276
    makeargs = ''
 
277
    if node.hasAttribute('makeargs'):
 
278
        makeargs = node.getAttribute('makeargs')
 
279
    # Make some substitutions; do special handling of '${prefix}' and '${libdir}'
 
280
    p = re.compile('(\${prefix})')
 
281
    makeargs = p.sub(config.prefix, makeargs)
 
282
 
 
283
    dependencies, after, suggests = get_dependencies(node)
 
284
    branch = get_branch(node, repositories, default_repo, config)
 
285
    kconfigs = get_kconfigs(node, repositories, default_repo)
 
286
 
 
287
    return LinuxModule(id, branch, kconfigs,
 
288
                       makeargs, dependencies, after, suggests)
 
289
 
 
290
register_module_type('linux', parse_linux)