[waf] default for waf to be ./waf, as system-wide waf is not supported
[jhbuild/xnox.git] / jhbuild / modtypes / waf.py
blobf8c5fe9522a3a1df460ef323b49820e271bab67c
1 # jhbuild - a build script for GNOME 1.x and 2.x
2 # Copyright (C) 2001-2006 James Henstridge
3 # Copyright (C) 2007 Gustavo Carneiro
4 # Copyright (C) 2008 Frederic Peters
6 # waf.py: waf module type definitions.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 __metaclass__ = type
24 import os
25 import re
27 from jhbuild.errors import FatalError, BuildStateError, CommandError
28 from jhbuild.modtypes import \
29 Package, DownloadableModule, get_dependencies, get_branch, register_module_type
30 from jhbuild.commands.sanitycheck import inpath
32 __all__ = [ 'WafModule' ]
34 class WafModule(Package, DownloadableModule):
35 '''Base type for modules that are distributed with a WAF script.'''
36 type = 'waf'
38 PHASE_CHECKOUT = DownloadableModule.PHASE_CHECKOUT
39 PHASE_FORCE_CHECKOUT = DownloadableModule.PHASE_FORCE_CHECKOUT
40 PHASE_CLEAN = 'clean'
41 PHASE_CONFIGURE = 'configure'
42 PHASE_BUILD = 'build'
43 PHASE_CHECK = 'check'
44 PHASE_DIST = 'dist'
45 PHASE_INSTALL = 'install'
47 def __init__(self, name, branch, dependencies=[], after=[], suggests=[],
48 waf_cmd='./waf'):
49 Package.__init__(self, name, dependencies, after, suggests)
50 self.branch = branch
51 self.waf_cmd = waf_cmd
53 def get_srcdir(self, buildscript):
54 return self.branch.srcdir
56 def get_builddir(self, buildscript):
57 return self.get_srcdir(buildscript)
59 def get_revision(self):
60 return self.branch.tree_id()
62 def skip_configure(self, buildscript, last_phase):
63 # don't skip this stage if we got here from one of the
64 # following phases:
65 if last_phase in [self.PHASE_FORCE_CHECKOUT,
66 self.PHASE_CLEAN,
67 self.PHASE_BUILD,
68 self.PHASE_INSTALL]:
69 return False
71 # skip if the .lock-wscript file exists and we don't have the
72 # alwaysautogen flag turned on:
73 builddir = self.get_builddir(buildscript)
74 return (os.path.exists(os.path.join(builddir, '.lock-wscript')) and
75 not buildscript.config.alwaysautogen)
77 def do_configure(self, buildscript):
78 builddir = self.get_builddir(buildscript)
79 buildscript.set_action(_('Configuring'), self)
80 if buildscript.config.buildroot and not os.path.exists(builddir):
81 os.makedirs(builddir)
82 cmd = [self.waf_cmd, 'configure', '--prefix', buildscript.config.prefix]
83 if buildscript.config.use_lib64:
84 cmd += ["--libdir", os.path.join(buildscript.config.prefix, "lib64")]
85 buildscript.execute(cmd, cwd=builddir)
86 do_configure.depends = [PHASE_CHECKOUT]
87 do_configure.error_phases = [PHASE_FORCE_CHECKOUT]
89 def do_clean(self, buildscript):
90 buildscript.set_action(_('Cleaning'), self)
91 cmd = [self.waf_cmd, 'clean']
92 buildscript.execute(cmd, cwd=self.get_builddir(buildscript))
93 do_clean.depends = [PHASE_CONFIGURE]
94 do_clean.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
96 def do_build(self, buildscript):
97 buildscript.set_action(_('Building'), self)
98 cmd = [self.waf_cmd, 'build']
99 buildscript.execute(cmd, cwd=self.get_builddir(buildscript))
100 do_build.depends = [PHASE_CONFIGURE]
101 do_build.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
103 def skip_check(self, buildscript, last_phase):
104 if self.name in buildscript.config.module_makecheck:
105 return not buildscript.config.module_makecheck[self.name]
106 if 'check' not in buildscript.config.build_targets:
107 return True
108 return False
110 def do_check(self, buildscript):
111 buildscript.set_action(_('Checking'), self)
112 cmd = [self.waf_cmd, 'check']
113 try:
114 buildscript.execute(cmd, cwd=self.get_builddir(buildscript))
115 except CommandError:
116 if not buildscript.config.makecheck_advisory:
117 raise
118 do_check.depends = [PHASE_BUILD]
119 do_check.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
121 def do_dist(self, buildscript):
122 buildscript.set_action(_('Creating tarball for'), self)
123 if buildscript.config.makedistcheck:
124 cmd = [self.waf_cmd, 'distcheck']
125 else:
126 cmd = [self.waf_cmd, 'dist']
127 buildscript.execute(cmd, cwd=self.get_builddir(buildscript))
128 do_dist.depends = [PHASE_BUILD]
129 do_dist.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
131 def do_install(self, buildscript):
132 buildscript.set_action(_('Installing'), self)
133 cmd = [self.waf_cmd, 'install']
134 buildscript.execute(cmd, cwd=self.get_builddir(buildscript))
135 buildscript.packagedb.add(self.name, self.get_revision() or '')
136 do_install.depends = [PHASE_BUILD]
138 def do_uninstall(self, buildscript):
139 buildscript.set_action(_('Uninstalling'), self)
140 cmd = [self.waf_cmd, 'uninstall']
141 buildscript.execute(cmd, cwd=self.get_builddir(buildscript))
142 buildscript.packagedb.remove(self.name)
143 do_install.depends = [PHASE_BUILD]
145 def xml_tag_and_attrs(self):
146 return 'waf', [('id', 'name', None),
147 ('waf-command', 'waf_cmd', 'waf')]
150 def parse_waf(node, config, uri, repositories, default_repo):
151 module_id = node.getAttribute('id')
152 waf_cmd = './waf'
153 if node.hasAttribute('waf-command'):
154 waf_cmd = node.getAttribute('waf-command')
156 # override revision tag if requested.
157 dependencies, after, suggests = get_dependencies(node)
158 branch = get_branch(node, repositories, default_repo, config)
160 return WafModule(module_id, branch, dependencies=dependencies, after=after,
161 suggests=suggests, waf_cmd=waf_cmd)
163 register_module_type('waf', parse_waf)