diff options
Diffstat (limited to 'regtest/builder')
-rw-r--r-- | regtest/builder/__init__.py | 86 | ||||
-rw-r--r-- | regtest/builder/autotools.py | 63 |
2 files changed, 149 insertions, 0 deletions
diff --git a/regtest/builder/__init__.py b/regtest/builder/__init__.py new file mode 100644 index 00000000..649c68d9 --- /dev/null +++ b/regtest/builder/__init__.py @@ -0,0 +1,86 @@ +# builder +# +# Copyright (C) 2012 Carlos Garcia Campos <carlosgc@gnome.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +from Config import Config +import os +import sys +import subprocess + +__all__ = [ 'register_builder', + 'get_builder', + 'UnknownBuilderError', + 'Builder' ] + +class UnknownBuilderError(Exception): + '''Unknown builder''' + +class Builder: + + def __init__(self): + self.config = Config() + self._srcdir = self.config.src_dir + self._prefix = self.config.prefix + + def number_of_cpus(self): + if not sys.platform.startswith("linux"): + # TODO + return 0 + + n_cpus = subprocess.Popen(['nproc'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] + if n_cpus: + return int(n_cpus) + + n_cpus = 0 + f = open('/proc/cpuinfo', 'r') + for line in f.readlines(): + if 'processor' in line: + n_cpus += 1 + f.close() + + return n_cpus + + def _configure(self): + raise NotImplementedError + + def _build(self): + raise NotImplementedError + + def build(self): + self._configure() + self._build() + + +_builders = {} +def register_builder(builder_name, builder_class): + _builders[builder_name] = builder_class + +def _get_builder(builder_name): + if builder_name not in _builders: + try: + __import__('builder.%s' % builder_name) + except ImportError: + pass + + if builder_name not in _builders: + raise UnknownBuilderError('Invalid %s builder' % builder_name) + + return _builders[builder_name] + +def get_builder(builder_name): + builder_class = _get_builder(builder_name) + return builder_class() diff --git a/regtest/builder/autotools.py b/regtest/builder/autotools.py new file mode 100644 index 00000000..4dd05659 --- /dev/null +++ b/regtest/builder/autotools.py @@ -0,0 +1,63 @@ +# autotools.py +# +# Copyright (C) 2012 Carlos Garcia Campos <carlosgc@gnome.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +from builder import Builder, register_builder +import os +import subprocess + +class Autotools(Builder): + + def _configure(self): + autogen = os.path.join(self._srcdir, 'autogen.sh') + cmd = [autogen, '--prefix=%s' % (self._prefix), '--enable-utils'] + + # Disable frontends and tests + cmd.extend(['--disable-poppler-glib', + '--disable-poppler-qt4', + '--disable-poppler-cpp', + '--disable-gtk-test']) + + backends = self.config.backends + if backends: + # Disable backends. Text and ps can't be disabled. + if 'cairo' not in backends: + cmd.append('--disable-cairo-output') + if 'splash' not in backends: + cmd.append('--disable-splash-output') + else: + cmd.extend(['--enable-cairo-output', + '--enable-splash-output']) + + p = subprocess.Popen(cmd, cwd=self._srcdir) + status = p.wait() + if not os.WIFEXITED(status) or os.WEXITSTATUS(status) != 0: + raise Exception('Command %s returned non-zero exit status %d' % (str(cmd), status)) + + def _build(self): + make = os.environ.get('MAKE', 'make') + cmd = [make] + n_cpus = self.number_of_cpus() + if n_cpus: + cmd.append('-j%d' % (n_cpus)) + + p = subprocess.Popen(cmd, cwd=self._srcdir) + status = p.wait() + if not os.WIFEXITED(status) or os.WEXITSTATUS(status) != 0: + raise Exception('Command %s returned non-zero exit status %d' % (str(cmd), status)) + +register_builder('autotools', Autotools) |