Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sjhbuild
diff options
context:
space:
mode:
authorbuild <buildmaster@sugarlabs.org>2009-01-21 18:52:50 (GMT)
committer build <buildmaster@sugarlabs.org>2009-01-21 18:52:50 (GMT)
commit220b57d90956fe7daf09865da4de48c645350909 (patch)
tree27b2968aa763217de8c1d186ef39e6229267ab2b /sjhbuild
parent14a2da2cd57e16bafc6d9a25848eb1094b8e2947 (diff)
add sjhbuild dir
Diffstat (limited to 'sjhbuild')
-rw-r--r--sjhbuild/bundlemodule.py94
-rw-r--r--sjhbuild/config.py75
-rw-r--r--sjhbuild/main.py155
-rw-r--r--sjhbuild/sysdeps.py91
4 files changed, 415 insertions, 0 deletions
diff --git a/sjhbuild/bundlemodule.py b/sjhbuild/bundlemodule.py
new file mode 100644
index 0000000..3a662c1
--- /dev/null
+++ b/sjhbuild/bundlemodule.py
@@ -0,0 +1,94 @@
+__metaclass__ = type
+
+import os
+
+from jhbuild.errors import BuildStateError
+from jhbuild.modtypes import Package, get_branch, register_module_type
+
+__all__ = [ 'BundleModule' ]
+
+class BundleModule(Package):
+ type = 'bundle'
+
+ STATE_CHECKOUT = 'checkout'
+ STATE_FORCE_CHECKOUT = 'force_checkout'
+ STATE_BUILD = 'build'
+ STATE_INSTALL = 'install'
+
+ def __init__(self, name, branch, dependencies=[], after=[]):
+ Package.__init__(self, name, dependencies, after)
+ self.branch = branch
+
+ def get_srcdir(self, buildscript):
+ return self.branch.srcdir
+
+ def get_builddir(self, buildscript):
+ return self.get_srcdir(buildscript)
+
+ def get_revision(self):
+ return self.branch.branchname
+
+ def do_start(self, buildscript):
+ pass
+ do_start.next_state = STATE_CHECKOUT
+ do_start.error_states = []
+
+ def skip_checkout(self, buildscript, last_state):
+ # skip the checkout stage if the nonetwork flag is set
+ return buildscript.config.nonetwork
+
+ def do_checkout(self, buildscript):
+ srcdir = self.get_srcdir(buildscript)
+ buildscript.set_action('Checking out', self)
+ self.branch.checkout(buildscript)
+ # did the checkout succeed?
+ if not os.path.exists(srcdir):
+ raise BuildStateError('source directory %s was not created'
+ % srcdir)
+ do_checkout.next_state = STATE_BUILD
+ do_checkout.error_states = [STATE_FORCE_CHECKOUT]
+
+ def skip_force_checkout(self, buildscript, last_state):
+ return False
+
+ def do_force_checkout(self, buildscript):
+ buildscript.set_action('Checking out', self)
+ self.branch.force_checkout(buildscript)
+ do_force_checkout.next_state = STATE_BUILD
+ do_force_checkout.error_states = [STATE_FORCE_CHECKOUT]
+
+ def skip_build(self, buildscript, last_state):
+ return buildscript.config.nobuild
+
+ def do_build(self, buildscript):
+ buildscript.set_action('Building', self)
+ srcdir = self.get_srcdir(buildscript)
+ builddir = self.get_builddir(buildscript)
+ python = os.environ.get('PYTHON', 'python')
+ cmd = [python, 'setup.py', 'build']
+ buildscript.execute(cmd, cwd=srcdir)
+ do_build.next_state = STATE_INSTALL
+ do_build.error_states = [STATE_FORCE_CHECKOUT]
+
+ def skip_install(self, buildscript, last_state):
+ return buildscript.config.nobuild
+
+ def do_install(self, buildscript):
+ buildscript.set_action('Installing', self)
+ srcdir = self.get_srcdir(buildscript)
+ builddir = self.get_builddir(buildscript)
+ python = os.environ.get('PYTHON', 'python')
+ cmd = [python, 'setup.py', 'install']
+ cmd.extend(['--prefix', buildscript.config.prefix])
+ buildscript.execute(cmd, cwd=srcdir)
+ buildscript.packagedb.add(self.name, self.get_revision() or '')
+ do_install.next_state = Package.STATE_DONE
+ do_install.error_states = []
+
+
+def parse_bundle(node, config, uri, repositories, default_repo):
+ id = node.getAttribute('id')
+ branch = get_branch(node, repositories, default_repo, config)
+ return BundleModule(id, branch)
+
+register_module_type('bundle', parse_bundle)
diff --git a/sjhbuild/config.py b/sjhbuild/config.py
new file mode 100644
index 0000000..4efe4e6
--- /dev/null
+++ b/sjhbuild/config.py
@@ -0,0 +1,75 @@
+import os
+import sys
+
+import jhbuild.config
+
+import sysdeps
+
+class Config(jhbuild.config.Config):
+ def __init__(self, base_dir, rc_file):
+ self.base_dir = base_dir
+ jhbuild.config.Config.__init__(self, os.path.join(self.base_dir, 'sugar.jhbuildrc'))
+ self._setup()
+
+ def _setup(self):
+ self.autogenargs = ''
+
+ self.checkoutroot = os.path.join(self.base_dir, 'source')
+ self.tarballdir = os.path.join(self.base_dir, 'source')
+
+ for package, source in sysdeps.get_packages():
+ if source and source not in self.skip:
+ self.skip.append(source)
+
+ def setup_env(self):
+ # Hack to replace the default prefix
+ if self.prefix == '/opt/gnome2':
+ self.prefix = os.path.join(self.base_dir, 'install')
+
+ #Hack to allow sugar-jhbuild to find its self again.
+
+ MY_PATH = os.getenv('PATH', 'Error')
+ os.environ["PATH"] = MY_PATH + ':' + self.base_dir
+
+ jhbuild.config.Config.setup_env(self)
+
+ jhbuild.config.addpath('XDG_DATA_DIRS', '/usr/share')
+ jhbuild.config.addpath('XDG_DATA_DIRS', os.path.join(self.prefix, 'share'))
+
+ if self.use_lib64:
+ path = 'lib64/gtk-2.0/'
+ else:
+ path = 'lib/gtk-2.0/'
+ jhbuild.config.addpath('GTK_PATH', os.path.join(self.prefix, path))
+ jhbuild.config.addpath('GTK_DATA_PREFIX', self.prefix)
+
+ os.environ['SUGAR_PREFIX'] = self.prefix
+ os.environ['SUGAR_PATH'] = os.path.join(self.prefix, 'share', 'sugar')
+ os.environ['SUGAR_LOGGER_LEVEL'] = 'debug'
+
+ # Enable debug log of the Telepathy components
+ os.environ['GABBLE_DEBUG'] = 'all'
+ os.environ['SALUT_DEBUG'] = 'all'
+ os.environ['STREAM_ENGINE_DEBUG'] = 'all'
+
+ # We need to add the gtk-2.0 directory explicitly to
+ # the Python path since '.pth' files (here pygtk.pth)
+ # only work properly in system directories
+ pythonversion = 'python' + str(sys.version_info[0]) + '.' + \
+ str(sys.version_info[1])
+ if self.use_lib64:
+ pythonpath = os.path.join(self.prefix, 'lib64', pythonversion,
+ 'site-packages', 'gtk-2.0')
+ else:
+ pythonpath = os.path.join(self.prefix, 'lib', pythonversion,
+ 'site-packages', 'gtk-2.0')
+ jhbuild.config.addpath('PYTHONPATH', pythonpath)
+
+ python_lib = os.path.join(self.prefix, 'lib', 'python2.5', 'site-packages')
+ os.environ['PYTHON_LIB'] = python_lib
+
+ if 'DBUS_SESSION_BUS_ADDRESS' in os.environ:
+ del os.environ['DBUS_SESSION_BUS_ADDRESS']
+
+ if not 'SUGAR_PROFILE' in os.environ:
+ os.environ['SUGAR_PROFILE'] = 'default'
diff --git a/sjhbuild/main.py b/sjhbuild/main.py
new file mode 100644
index 0000000..be988b9
--- /dev/null
+++ b/sjhbuild/main.py
@@ -0,0 +1,155 @@
+#!/usr/bin/env python
+# jhbuild - a build script for GNOME 1.x and 2.x
+# Copyright (C) 2001-2006 James Henstridge
+#
+# main.py: parses command line arguments and starts the build
+#
+# 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
+
+import sys, os, errno
+import optparse
+import traceback
+
+import gettext
+localedir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../mo'))
+gettext.install('jhbuild', localedir=localedir, unicode=True)
+import __builtin__
+__builtin__.__dict__['N_'] = lambda x: x
+
+import jhbuild.commands
+from jhbuild.errors import UsageError, FatalError
+from jhbuild.utils.cmds import get_output
+from jhbuild.moduleset import warn_local_modulesets
+
+import bundlemodule
+
+from config import Config
+
+if sys.platform == 'darwin':
+ # work around locale.getpreferredencoding() returning an empty string in
+ # Mac OS X, see http://bugzilla.gnome.org/show_bug.cgi?id=534650 and
+ # http://bazaar-vcs.org/DarwinCommandLineArgumentDecoding
+ sys.platform = 'posix'
+ try:
+ import locale
+ finally:
+ sys.platform = 'darwin'
+else:
+ import locale
+
+try:
+ _encoding = locale.getpreferredencoding()
+ assert _encoding
+except (locale.Error, AssertionError):
+ _encoding = 'ascii'
+
+def uencode(s):
+ if type(s) is unicode:
+ return s.encode(_encoding, 'replace')
+ else:
+ return s
+
+def uprint(*args):
+ '''Print Unicode string encoded for the terminal'''
+ for s in args[:-1]:
+ print uencode(s),
+ s = args[-1]
+ print uencode(s)
+
+__builtin__.__dict__['uprint'] = uprint
+__builtin__.__dict__['uencode'] = uencode
+
+def help_commands(option, opt_str, value, parser):
+ thisdir = os.path.abspath(os.path.dirname(__file__))
+
+ # import all available commands
+ for fname in os.listdir(os.path.join(thisdir, 'commands')):
+ name, ext = os.path.splitext(fname)
+ if not ext == '.py':
+ continue
+ try:
+ __import__('jhbuild.commands.%s' % name)
+ except ImportError:
+ pass
+
+ uprint(_('JHBuild commands are:'))
+ commands = [(x.name, x.doc) for x in jhbuild.commands.get_commands().values()]
+ commands.sort()
+ for name, description in commands:
+ uprint(' %-15s %s' % (name, description))
+ print
+ uprint(_('For more information run "jhbuild <command> --help"'))
+ parser.exit()
+
+def main(base_dir, args):
+ parser = optparse.OptionParser(
+ usage=_('%prog [ -f config ] command [ options ... ]'),
+ description=_('Build a set of modules from diverse repositories in correct dependency order (such as GNOME).'))
+ parser.disable_interspersed_args()
+ parser.add_option('--help-commands', action='callback',
+ callback=help_commands,
+ help=_('Information about available jhbuild commands'))
+ parser.add_option('-f', '--file', action='store', metavar='CONFIG',
+ type='string', dest='configfile',
+ default=os.environ.get("JHBUILDRC", os.path.join(os.environ['HOME'], '.jhbuildrc')),
+ help=_('use a non default configuration file'))
+ parser.add_option('-m', '--moduleset', action='store', metavar='URI',
+ type='string', dest='moduleset', default=None,
+ help=_('use a non default module set'))
+ parser.add_option('--no-interact', action='store_true',
+ dest='nointeract', default=False,
+ help=_('do not prompt for input'))
+
+ options, args = parser.parse_args(args)
+
+ try:
+ config = Config(base_dir, options.configfile)
+ except FatalError, exc:
+ sys.stderr.write('sugar-jhbuild: %s\n' % exc.args[0].encode(_encoding, 'replace'))
+ sys.exit(1)
+
+ if options.moduleset: config.moduleset = options.moduleset
+ if options.nointeract: config.interact = False
+
+ if not args or args[0][0] == '-':
+ command = 'build' # default to cvs update + compile
+ else:
+ command = args[0]
+ args = args[1:]
+
+ warn_local_modulesets(config)
+
+ try:
+ rc = jhbuild.commands.run(command, config, args)
+ except UsageError, exc:
+ sys.stderr.write('sugar-jhbuild %s: %s\n' % (command, exc.args[0].encode(_encoding, 'replace')))
+ parser.print_usage()
+ sys.exit(1)
+ except FatalError, exc:
+ sys.stderr.write('sugar-jhbuild %s: %s\n' % (command, exc.args[0].encode(_encoding, 'replace')))
+ sys.exit(1)
+ except KeyboardInterrupt:
+ uprint(_('Interrupted'))
+ sys.exit(1)
+ except EOFError:
+ uprint(_('EOF'))
+ sys.exit(1)
+ except IOError, e:
+ if e.errno != errno.EPIPE:
+ raise
+ sys.exit(0)
+ if rc:
+ sys.exit(rc)
+
diff --git a/sjhbuild/sysdeps.py b/sjhbuild/sysdeps.py
new file mode 100644
index 0000000..b398cff
--- /dev/null
+++ b/sjhbuild/sysdeps.py
@@ -0,0 +1,91 @@
+import os
+import subprocess
+
+from xml.dom import minidom
+
+scripts_dir = os.path.dirname(__file__)
+base_dir = os.path.dirname(scripts_dir)
+
+def get_distribution():
+ if 'SJH_DISTRIBUTION' in os.environ:
+ return os.environ['SJH_DISTRIBUTION'].split('-')
+
+ # Fedora
+ if os.path.exists('/etc/fedora-release'):
+ name = 'fedora'
+
+ f = open('/etc/fedora-release')
+ full_name = f.read()
+ f.close()
+
+ if 'Rawhide' in full_name:
+ version = 'rawhide'
+ else:
+ version = full_name.split(' ')[2]
+
+ return name, version
+
+ # Debian and Ubuntu
+ try:
+ out, err = subprocess.Popen(['lsb_release', '-is'],
+ stdout=subprocess.PIPE).communicate()
+ name = out.strip().lower()
+
+ out, err = subprocess.Popen(['lsb_release', '-rs'],
+ stdout=subprocess.PIPE).communicate()
+ version = out.strip()
+
+ if name == 'debian' and version == 'testing':
+ version = 'unstable'
+
+ return name, version
+ except OSError:
+ pass
+
+ return None, None
+
+def check_package(package):
+ name, version = get_distribution()
+ if name == 'fedora':
+ ret = subprocess.call(['rpm', '--quiet', '-q', package])
+ return ret == 0
+ elif name in ['ubuntu', 'debian']:
+ cmd = ["dpkg-query", "-f='${status}'", "-W", package]
+ out, err = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
+ return out.find('install ok installed') != -1
+
+ return None
+
+def parse_dependencies():
+ name, version = get_distribution()
+ if name is None or version is None:
+ return None
+
+ filename = os.path.join(base_dir, 'config', 'sysdeps',
+ '%s-%s.xml' % (name, version))
+
+ if not os.path.exists(filename):
+ return None
+
+ return minidom.parse(filename)
+
+def get_packages():
+ document = parse_dependencies()
+ if document is None:
+ return []
+
+ packages = []
+ root = document.childNodes[0]
+
+ for node in root.childNodes:
+ if node.nodeType == node.ELEMENT_NODE:
+ if node.nodeName == 'package':
+ name = node.getAttribute('name')
+ if node.hasAttribute('source'):
+ source = node.getAttribute('source')
+ else:
+ source = None
+
+ packages.append((name, source))
+
+ return packages