jhbuild r2595 - in trunk: . jhbuild/commands jhbuild/modtypes jhbuild/utils jhbuild/versioncontrol
- From: apwingo svn gnome org
- To: svn-commits-list gnome org
- Subject: jhbuild r2595 - in trunk: . jhbuild/commands jhbuild/modtypes jhbuild/utils jhbuild/versioncontrol
- Date: Mon, 22 Dec 2008 15:07:58 +0000 (UTC)
Author: apwingo
Date: Mon Dec 22 15:07:58 2008
New Revision: 2595
URL: http://svn.gnome.org/viewvc/jhbuild?rev=2595&view=rev
Log:
2008-12-22 Andy Wingo <wingo pobox com>
* jhbuild/commands/snapshot.py: New file, implements the new
command, "jhbuild snapshot". (closes: #564873)
* jhbuild/utils/sxml.py: New helper lib for xml serialization.
* jhbuild/versioncontrol/svn.py (SubversionRepository.to_sxml)
(SubversionBranch.to_sxml):
* jhbuild/versioncontrol/git.py (GitRepository.to_sxml)
(GitBranch.to_sxml):
* jhbuild/versioncontrol/tarball.py (TarballRepository.to_sxml)
(TarballBranch.to_sxml):
* jhbuild/versioncontrol/__init__.py (Repository.to_sxml)
(Branch.to_sxml):
* jhbuild/versioncontrol/cvs.py (CVSRepository.to_sxml)
(CVSBranch.to_sxml):
* jhbuild/modtypes/__init__.py (Package.to_sxml)
(MetaModule.to_sxml): Plug in to_sxml() methods for serialization.
* jhbuild/modtypes/autotools.py (AutogenModule.xml_tag_and_attrs):
* jhbuild/modtypes/mozillamodule.py (MozillaModule):
* jhbuild/modtypes/waf.py (WafModule.xml_tag_and_attrs):
* jhbuild/modtypes/linux.py (LinuxModule.xml_tag_and_attrs):
* jhbuild/modtypes/perl.py (PerlModule.xml_tag_and_attrs):
* jhbuild/modtypes/ant.py (AntModule.xml_tag_and_attrs):
* jhbuild/modtypes/distutils.py (DistutilsModule.xml_tag_and_attrs):
* jhbuild/modtypes/mesa.py (MesaModule.xml_tag_and_attrs):
* jhbuild/modtypes/testmodule.py (TestModule.xml_tag_and_attrs):
Plug bits so we can serialize all the types of modules. There are
still some version control backends that aren't yet serialized
though.
Added:
trunk/jhbuild/commands/snapshot.py
trunk/jhbuild/utils/sxml.py
Modified:
trunk/ChangeLog
trunk/jhbuild/modtypes/__init__.py
trunk/jhbuild/modtypes/ant.py
trunk/jhbuild/modtypes/autotools.py
trunk/jhbuild/modtypes/cmake.py
trunk/jhbuild/modtypes/distutils.py
trunk/jhbuild/modtypes/linux.py
trunk/jhbuild/modtypes/mesa.py
trunk/jhbuild/modtypes/mozillamodule.py
trunk/jhbuild/modtypes/perl.py
trunk/jhbuild/modtypes/testmodule.py
trunk/jhbuild/modtypes/waf.py
trunk/jhbuild/versioncontrol/__init__.py
trunk/jhbuild/versioncontrol/cvs.py
trunk/jhbuild/versioncontrol/git.py
trunk/jhbuild/versioncontrol/svn.py
trunk/jhbuild/versioncontrol/tarball.py
Added: trunk/jhbuild/commands/snapshot.py
==============================================================================
--- (empty file)
+++ trunk/jhbuild/commands/snapshot.py Mon Dec 22 15:07:58 2008
@@ -0,0 +1,61 @@
+# jhbuild - a build script for GNOME 1.x and 2.x
+# Copyright (C) 2001-2004 James Henstridge
+# Copyright (C) 2008 Andy Wingo
+#
+# snapshot.py: output a moduleset corresponding to the exact versions
+# that are checked out
+#
+# 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 urllib2
+from optparse import make_option
+
+import jhbuild.moduleset
+from jhbuild.commands import Command, register_command
+
+from jhbuild.utils.sxml import sxml, sxml_to_string
+
+
+class cmd_snapshot(Command):
+ doc = _('Print out a moduleset for the exact versions that are checked out')
+ name = 'snapshot'
+
+ def __init__(self):
+ Command.__init__(self)
+
+ def run(self, config, options, args):
+ module_set = jhbuild.moduleset.load(config)
+ module_list = module_set.get_module_list(args or config.modules,
+ config.skip)
+ meta = [m for m in module_list if m.type == 'meta']
+ checked_out_mods = [m for m in module_list
+ if getattr(m, 'branch', None) and m.branch.tree_id()]
+ checked_out_repos = []
+
+ for mod in checked_out_mods:
+ if mod.branch.repository not in checked_out_repos:
+ checked_out_repos.append(mod.branch.repository)
+
+ x = ([sxml.moduleset]
+ + [r.to_sxml() for r in checked_out_repos]
+ + [m.to_sxml() for m in checked_out_mods]
+ + [m.to_sxml() for m in meta])
+
+ print '<?xml version="1.0"?>\n'
+ print sxml_to_string(x)
+
+register_command(cmd_snapshot)
Modified: trunk/jhbuild/modtypes/__init__.py
==============================================================================
--- trunk/jhbuild/modtypes/__init__.py (original)
+++ trunk/jhbuild/modtypes/__init__.py Mon Dec 22 15:07:58 2008
@@ -30,6 +30,7 @@
import os
from jhbuild.errors import FatalError, CommandError, BuildStateError
+from jhbuild.utils.sxml import sxml
_module_types = {}
def register_module_type(name, parse_func):
@@ -234,6 +235,44 @@
return True
return False
+ def xml_tag_and_attrs(self):
+ """Return a (tag, attrs) pair, describing how to serialize this
+ module.
+
+ "attrs" is expected to be a list of (xmlattrname, pyattrname,
+ default) tuples. The xmlattr will be serialized iff
+ getattr(self, pyattrname) != default. See AutogenModule for an
+ example."""
+ raise NotImplementedError
+
+ def to_sxml(self):
+ """Serialize this module as sxml.
+
+ By default, calls sxml_tag_and_attrs() to get the tag name and
+ attributes, serializing those attribute values that are
+ different from their defaults, and embedding the dependencies
+ and checkout branch. You may however override this method to
+ implement a different behavior."""
+ tag, attrs = self.xml_tag_and_attrs()
+ xmlattrs = {}
+ for xmlattr, pyattr, default in attrs:
+ val = getattr(self, pyattr)
+ if val != default:
+ if type(val) == bool:
+ val = val and 'true' or 'no'
+ xmlattrs[xmlattr] = val
+ return [getattr(sxml, tag)(**xmlattrs), self.deps_to_sxml(),
+ self.branch_to_sxml()]
+
+ def deps_to_sxml(self):
+ """Serialize this module's dependencies as sxml."""
+ return ([sxml.dependencies]
+ + [[sxml.dep(package=d)] for d in self.dependencies])
+
+ def branch_to_sxml(self):
+ """Serialize this module's checkout branch as sxml."""
+ return self.branch.to_sxml()
+
class MetaModule(Package):
"""A simple module type that consists only of dependencies."""
@@ -250,6 +289,12 @@
do_start.next_state = Package.STATE_DONE
do_start.error_states = []
+ def to_sxml(self):
+ return [sxml.metamodule(id=self.name),
+ [sxml.dependencies]
+ + [[sxml.dep(package=d)] for d in self.dependencies]]
+
+
def parse_metamodule(node, config, url, repos, default_repo):
id = node.getAttribute('id')
dependencies, after, suggests = get_dependencies(node)
Modified: trunk/jhbuild/modtypes/ant.py
==============================================================================
--- trunk/jhbuild/modtypes/ant.py (original)
+++ trunk/jhbuild/modtypes/ant.py Mon Dec 22 15:07:58 2008
@@ -112,6 +112,11 @@
do_install.next_state = Package.STATE_DONE
do_install.error_states = []
+ def xml_tag_and_attrs(self):
+ return 'ant', [('id', 'name', None),
+ ('supports-non-srcdir-builds',
+ 'supports_non_srcdir_builds', False)]
+
def parse_ant(node, config, uri, repositories, default_repo):
id = node.getAttribute('id')
Modified: trunk/jhbuild/modtypes/autotools.py
==============================================================================
--- trunk/jhbuild/modtypes/autotools.py (original)
+++ trunk/jhbuild/modtypes/autotools.py Mon Dec 22 15:07:58 2008
@@ -291,6 +291,19 @@
do_force_distclean.next_state = STATE_CONFIGURE
do_force_distclean.error_states = []
+ def xml_tag_and_attrs(self):
+ return ('autotools',
+ [('autogenargs', 'autogenargs', ''),
+ ('id', 'name', None),
+ ('makeargs', 'makeargs', ''),
+ ('makeinstallargs', 'makeinstallargs', ''),
+ ('supports-non-srcdir-builds',
+ 'supports_non_srcdir_builds', True),
+ ('skip-autogen', 'skip_autogen', False),
+ ('autogen-sh', 'autogen_sh', 'autogen.sh'),
+ ('makefile', 'makefile', 'Makefile'),
+ ('autogen-template', 'autogen_template', None)])
+
def parse_autotools(node, config, uri, repositories, default_repo):
id = node.getAttribute('id')
Modified: trunk/jhbuild/modtypes/cmake.py
==============================================================================
--- trunk/jhbuild/modtypes/cmake.py (original)
+++ trunk/jhbuild/modtypes/cmake.py Mon Dec 22 15:07:58 2008
@@ -126,6 +126,9 @@
do_install.next_state = Package.STATE_DONE
do_install.error_states = []
+ def xml_tag_and_attrs(self):
+ return 'cmake', [('id', 'name', None)]
+
def parse_cmake(node, config, uri, repositories, default_repo):
id = node.getAttribute('id')
Modified: trunk/jhbuild/modtypes/distutils.py
==============================================================================
--- trunk/jhbuild/modtypes/distutils.py (original)
+++ trunk/jhbuild/modtypes/distutils.py Mon Dec 22 15:07:58 2008
@@ -109,6 +109,11 @@
do_install.next_state = Package.STATE_DONE
do_install.error_states = []
+ def xml_tag_and_attrs(self):
+ return 'distutils', [('id', 'name', None),
+ ('supports-non-srcdir-builds',
+ 'supports_non_srcdir_builds', True)]
+
def parse_distutils(node, config, uri, repositories, default_repo):
id = node.getAttribute('id')
Modified: trunk/jhbuild/modtypes/linux.py
==============================================================================
--- trunk/jhbuild/modtypes/linux.py (original)
+++ trunk/jhbuild/modtypes/linux.py Mon Dec 22 15:07:58 2008
@@ -189,6 +189,11 @@
do_install.next_state = Package.STATE_DONE
do_install.error_states = []
+ def xml_tag_and_attrs(self):
+ return 'linux', [('id', 'name', None),
+ ('makeargs', 'makeargs', '')]
+
+
def get_kconfigs(node, repositories, default_repo):
id = node.getAttribute('id')
Modified: trunk/jhbuild/modtypes/mesa.py
==============================================================================
--- trunk/jhbuild/modtypes/mesa.py (original)
+++ trunk/jhbuild/modtypes/mesa.py Mon Dec 22 15:07:58 2008
@@ -130,6 +130,10 @@
do_install.next_state = Package.STATE_DONE
do_install.error_states = []
+ def xml_tag_and_attrs(self):
+ return 'mesa', [('id', 'name', None),
+ ('makeargs', 'makeargs', '')]
+
def parse_mesa(node, config, uri, repositories, default_repo):
id = node.getAttribute('id')
Modified: trunk/jhbuild/modtypes/mozillamodule.py
==============================================================================
--- trunk/jhbuild/modtypes/mozillamodule.py (original)
+++ trunk/jhbuild/modtypes/mozillamodule.py Mon Dec 22 15:07:58 2008
@@ -165,6 +165,13 @@
do_install.next_state = AutogenModule.STATE_DONE
do_install.error_states = []
+ def xml_tag_and_attrs(self):
+ # NB, we don't do cvsroot or revision. That should probably be
+ # done with branches.
+ return 'mozillamodule', [('id', 'name', None),
+ ('autogenargs', 'autogenargs', ''),
+ ('makeargs', 'makeargs', '')]
+
def parse_mozillamodule(node, config, uri, repositories, default_repo):
name = node.getAttribute('id')
projects = node.getAttribute('projects')
Modified: trunk/jhbuild/modtypes/perl.py
==============================================================================
--- trunk/jhbuild/modtypes/perl.py (original)
+++ trunk/jhbuild/modtypes/perl.py Mon Dec 22 15:07:58 2008
@@ -102,6 +102,10 @@
do_install.next_state = Package.STATE_DONE
do_install.error_states = []
+ def xml_tag_and_attrs(self):
+ return 'perl', [('id', 'name', None),
+ ('makeargs', 'makeargs', '')]
+
def parse_perl(node, config, uri, repositories, default_repo):
id = node.getAttribute('id')
Modified: trunk/jhbuild/modtypes/testmodule.py
==============================================================================
--- trunk/jhbuild/modtypes/testmodule.py (original)
+++ trunk/jhbuild/modtypes/testmodule.py Mon Dec 22 15:07:58 2008
@@ -342,6 +342,9 @@
if e.returncode != 0:
raise BuildStateError('%s failed' % test_case)
+ def xml_tag_and_attrs(self):
+ return 'testmodule', [('id', 'name', None),
+ ('type', 'test_type', None)]
def get_tested_packages(node):
tested_pkgs = []
Modified: trunk/jhbuild/modtypes/waf.py
==============================================================================
--- trunk/jhbuild/modtypes/waf.py (original)
+++ trunk/jhbuild/modtypes/waf.py Mon Dec 22 15:07:58 2008
@@ -176,6 +176,10 @@
do_install.next_state = Package.STATE_DONE
do_install.error_states = []
+ def xml_tag_and_attrs(self):
+ return 'waf', [('id', 'name', None),
+ ('waf-command', 'waf_cmd', 'waf')]
+
def parse_waf(node, config, uri, repositories, default_repo):
module_id = node.getAttribute('id')
Added: trunk/jhbuild/utils/sxml.py
==============================================================================
--- (empty file)
+++ trunk/jhbuild/utils/sxml.py Mon Dec 22 15:07:58 2008
@@ -0,0 +1,91 @@
+# jhbuild - a build script for GNOME 1.x and 2.x
+# Copyright (C) 2008 Andy Wingo <wingo pobox com>
+#
+# sxml.py: xml as s-expressions
+#
+# 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
+
+
+
+"""
+An s-expression syntax for XML documents, together with a serializer to
+UTF-8.
+
+Use like this:
+
+>>> x = [sxml.h1, "text"]
+>>> sxml_to_string (x)
+"<h1>text</h1>"
+
+>>> x = [sxml.a(href="about:blank", title="foo"), [sxml.i, "italics & stuff"]]
+>>> sxml_to_string (x)
+"<a href="about:blank" title="foo"><i>italics & stuff</i></a>"
+"""
+
+
+__all__ = ['sxml', 'sxml_to_string']
+
+
+# from Django, originally. used to make sure xml is utf-8.
+def smart_str(s, encoding='utf-8', errors='strict'):
+ # Returns a bytestring version of 's', encoded as specified in 'encoding'.
+ if not isinstance(s, basestring):
+ try:
+ return str(s)
+ except UnicodeEncodeError:
+ return unicode(s).encode(encoding, errors)
+ elif isinstance(s, unicode):
+ return s.encode(encoding, errors)
+ elif s and encoding != 'utf-8':
+ return s.decode('utf-8', errors).encode(encoding, errors)
+ else:
+ return s
+
+def quote(s):
+ quoted = {'"': '"',
+ '&': '&',
+ '<': '<',
+ '>': '>'}
+ return ''.join([quoted.get(c,c) for c in s])
+
+def sxml_to_string(expr):
+ if not isinstance(expr, list):
+ return smart_str(quote(expr))
+ operator = expr[0]
+ args = [sxml_to_string(arg) for arg in expr[1:]]
+ return smart_str(operator(args))
+
+class sxml:
+ def __getattr__(self, attr):
+ def _trans(k):
+ table = {'klass': 'class'}
+ return table.get(k, k)
+ def tag(*targs, **kw):
+ def render(args):
+ return ('<%s%s>%s</%s>'
+ % (attr,
+ ''.join([' %s="%s"' % (_trans(k), quote(v))
+ for k, v in kw.items()]),
+ '\n'.join(args),
+ attr))
+ render.__name__ = attr
+ if targs:
+ return render(targs[0])
+ else:
+ return render
+ # this only works with python2.4
+ tag.__name__ = attr
+ return tag
+sxml = sxml()
Modified: trunk/jhbuild/versioncontrol/__init__.py
==============================================================================
--- trunk/jhbuild/versioncontrol/__init__.py (original)
+++ trunk/jhbuild/versioncontrol/__init__.py Mon Dec 22 15:07:58 2008
@@ -60,6 +60,10 @@
kws['branch_id'] = branchnode.getAttribute('id')
return self.branch(name, **kws)
+ def to_sxml(self):
+ """Return an sxml representation of this repository."""
+ raise NotImplementedError
+
class Branch:
"""An abstract class representing a branch in a repository."""
@@ -115,6 +119,10 @@
todir = os.path.join(self.config.checkoutroot, os.path.basename(module))
buildscript.execute(['cp', '-R', fromdir, todir])
+ def to_sxml(self):
+ """Return an sxml representation of this checkout."""
+ raise NotImplementedError
+
_repo_types = {}
def register_repo_type(name, repo_class):
_repo_types[name] = repo_class
Modified: trunk/jhbuild/versioncontrol/cvs.py
==============================================================================
--- trunk/jhbuild/versioncontrol/cvs.py (original)
+++ trunk/jhbuild/versioncontrol/cvs.py Mon Dec 22 15:07:58 2008
@@ -36,6 +36,7 @@
from jhbuild.errors import BuildStateError
from jhbuild.versioncontrol import Repository, Branch, register_repo_type
from jhbuild.commands.sanitycheck import inpath
+from jhbuild.utils.sxml import sxml
# table used to scramble passwords in ~/.cvspass files
@@ -205,6 +206,9 @@
update_new_dirs=update_new_dirs != 'no',
override_checkoutdir=override_checkoutdir != 'no')
+ def to_sxml(self):
+ return [sxml.repository(type='cvs', name=self.name, cvsroot=self.cvsroot)]
+
class CVSBranch(Branch):
"""A class representing a CVS branch inside a CVS repository"""
@@ -323,4 +327,10 @@
_process_directory(self.srcdir, '', md5sum.update)
return 'jhbuild-cvs-treeid:%s' % md5sum.hexdigest()
+ def to_sxml(self):
+ # FIXME: fix the current revision
+ return [sxml.branch(repo=self.repository.name,
+ module=self.module)]
+
+
register_repo_type('cvs', CVSRepository)
Modified: trunk/jhbuild/versioncontrol/git.py
==============================================================================
--- trunk/jhbuild/versioncontrol/git.py (original)
+++ trunk/jhbuild/versioncontrol/git.py Mon Dec 22 15:07:58 2008
@@ -33,6 +33,7 @@
from jhbuild.versioncontrol import Repository, Branch, register_repo_type
import jhbuild.versioncontrol.svn
from jhbuild.commands.sanitycheck import inpath
+from jhbuild.utils.sxml import sxml
# Make sure that the urlparse module considers git:// and git+ssh://
# schemes to be netloc aware and set to allow relative URIs.
@@ -80,6 +81,9 @@
module = urlparse.urljoin(self.href, module)
return GitBranch(self, module, subdir, checkoutdir, revision, tag)
+ def to_sxml(self):
+ return [sxml.repository(type='git', name=self.name, href=self.href)]
+
class GitBranch(Branch):
"""A class representing a GIT branch."""
@@ -262,6 +266,15 @@
return None
return output.strip()
+ def to_sxml(self):
+ attrs = {}
+ if self.branch:
+ attrs['branch'] = self.branch
+ return [sxml.branch(repo=self.repository.name,
+ module=self.module,
+ tag=self.tree_id(),
+ **attrs)]
+
class GitSvnBranch(GitBranch):
def __init__(self, repository, module, checkoutdir, revision=None):
Modified: trunk/jhbuild/versioncontrol/svn.py
==============================================================================
--- trunk/jhbuild/versioncontrol/svn.py (original)
+++ trunk/jhbuild/versioncontrol/svn.py Mon Dec 22 15:07:58 2008
@@ -28,6 +28,7 @@
from jhbuild.utils.cmds import get_output, check_version
from jhbuild.versioncontrol import Repository, Branch, register_repo_type
from jhbuild.commands.sanitycheck import inpath
+from jhbuild.utils.sxml import sxml
import bzr, git
@@ -100,6 +101,13 @@
% filename)
return info['url']
+def call_with_info(proc, filename, *keys):
+ info = get_info(filename)
+ try:
+ return proc(*[info[k] for k in keys])
+ except KeyError:
+ return None
+
class SubversionRepository(Repository):
"""A class used to work with a Subversion repository"""
@@ -161,6 +169,9 @@
else:
return SubversionBranch(self, module_href, name, checkoutdir, revision)
+ def to_sxml(self):
+ return [sxml.repository(type='svn', name=self.name, href=self.href)]
+
class SubversionBranch(Branch):
"""A class representing a Subversion branch"""
@@ -346,5 +357,14 @@
return '%s,%s,%s' % (uuid.lower(), rev, path)
+ def to_sxml(self):
+ return (call_with_info(lambda rev:
+ [sxml.branch(repo=self.repository.name,
+ module=self.module,
+ revision=rev)],
+ self.srcdir, 'last changed rev')
+ or [sxml.branch(repo=self.repository.name,
+ module=self.module)])
+
register_repo_type('svn', SubversionRepository)
Modified: trunk/jhbuild/versioncontrol/tarball.py
==============================================================================
--- trunk/jhbuild/versioncontrol/tarball.py (original)
+++ trunk/jhbuild/versioncontrol/tarball.py Mon Dec 22 15:07:58 2008
@@ -34,6 +34,7 @@
from jhbuild.modtypes import get_branch
from jhbuild.utils.unpack import unpack_archive
from jhbuild.utils import httpcache
+from jhbuild.utils.sxml import sxml
jhbuild_directory = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', '..'))
@@ -94,6 +95,9 @@
branch.quilt = get_branch(childnode, repositories, default_repo)
return branch
+ def to_sxml(self):
+ return [sxml.repository(type='tarball', name=self.name, href=self.href)]
+
class TarballBranch(Branch):
"""A class representing a Tarball."""
@@ -276,4 +280,14 @@
extra_env={'QUILT_PATCHES' : self.quilt.srcdir}))
return '%s-%s' % (self.version, md5sum.hexdigest())
+ def to_sxml(self):
+ return ([sxml.branch(module=self.module,
+ repo=self.repository.name,
+ version=self.version,
+ size=str(self.source_size),
+ md5sum=self.source_md5)]
+ + [[sxml.patch(file=patch, strip=str(strip))]
+ for patch, strip in self.patches])
+
+
register_repo_type('tarball', TarballRepository)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]