[Pkg-bazaar-commits] ./bzr-builddeb/trunk r236: Support building remote branches, thanks Jelmer!

James Westby jw+debian at jameswestby.net
Thu May 29 22:51:16 UTC 2008


------------------------------------------------------------
revno: 236
committer: James Westby <jw+debian at jameswestby.net>
branch nick: trunk
timestamp: Thu 2008-05-29 23:51:16 +0100
message:
  Support building remote branches, thanks Jelmer!
modified:
  __init__.py
  config.py
  debian/changelog
  hooks.py
  tests/blackbox/test_builddeb.py
  tests/test_hooks.py
  tests/test_util.py
  util.py
    ------------------------------------------------------------
    revno: 226.2.2
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: remote
    timestamp: Sun 2008-05-18 01:07:18 +0200
    message:
      Support building from remote branch.
    modified:
      __init__.py
    ------------------------------------------------------------
    revno: 226.2.3
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: remote
    timestamp: Sun 2008-05-18 01:38:07 +0200
    message:
      Use Tree functions for accessing link properties.
    modified:
      util.py
    ------------------------------------------------------------
    revno: 226.2.4
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: remote
    timestamp: Sun 2008-05-18 01:45:09 +0200
    message:
      Specify tree to use to hooks explicitly so we notice when trying to run the pre-export one without a local working tree.
    modified:
      __init__.py
      debian/changelog
      hooks.py
    ------------------------------------------------------------
    revno: 226.2.5
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: remote
    timestamp: Sun 2008-05-18 01:48:32 +0200
    message:
      Remove unused utility function goto_branch.
    modified:
      util.py
    ------------------------------------------------------------
    revno: 226.2.6
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: remote
    timestamp: Sun 2008-05-18 02:04:21 +0200
    message:
      Fix some broken tests.
    modified:
      hooks.py
      tests/test_hooks.py
      tests/test_util.py
    ------------------------------------------------------------
    revno: 226.2.7
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: remote
    timestamp: Sun 2008-05-18 03:34:44 +0200
    message:
      Support loading .bzr-builddeb/default.conf when not building from a 
      working tree.
      
      Also avoid loading .bzr-builddeb/local.conf when it is versioned to avoid 
      security problems when pulling in changes from somebody else.
    modified:
      __init__.py
      config.py
      tests/blackbox/test_builddeb.py
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2008-05-15 13:39:55 +0000
+++ b/__init__.py	2008-05-29 22:51:16 +0000
@@ -25,6 +25,7 @@
 import os
 import subprocess
 
+from bzrlib.branch import Branch
 from bzrlib.commands import Command, register_command
 from bzrlib.errors import (BzrCommandError,
                            NoWorkingTree,
@@ -49,7 +50,7 @@
                     )
 from bzrlib.plugins.builddeb.hooks import run_hook
 from bzrlib.plugins.builddeb.properties import BuildProperties
-from bzrlib.plugins.builddeb.util import goto_branch, find_changelog, tarball_name
+from bzrlib.plugins.builddeb.util import find_changelog, tarball_name
 from bzrlib.plugins.builddeb.version import version_info
 
 
@@ -92,9 +93,10 @@
   If BRANCH is specified it is assumed that the branch you wish to build is
   located there. If it is not specified then the current directory is used.
 
-  By default the working tree is used to build. If you wish to build the
-  last committed revision use --revision -1. You can specify any other
-  revision using the --revision option.
+  By default the if a working tree is found it is used to build and otherwise
+  the last committed revision was used. To force building the last committed 
+  revision use --revision -1. You can specify any other revision using the 
+  --revision option.
 
   If you only wish to export the package, and not build it (especially useful
   for merge mode), use --export-only.
@@ -167,16 +169,40 @@
           export_upstream=None, export_upstream_revision=None,
           source=False, revision=None, no_user_config=False):
 
-    goto_branch(branch)
-
-    tree, relpath = WorkingTree.open_containing('.')
-    
-    if no_user_config:
-        config_files = [(local_conf, True), (default_conf, False)]
+    if branch is None:
+      branch = "."
+
+    try:
+      tree, _ = WorkingTree.open_containing(branch)
+      branch = tree.branch
+    except NoWorkingTree:
+      tree = None
+      branch, _ = Branch.open_containing(branch)
+
+    if revision is None and tree is not None:
+      info("Building using working tree")
+      working_tree = True
     else:
-        config_files = [(local_conf, True), (global_conf, True),
-                             (default_conf, False)]
-    config = DebBuildConfig(config_files, branch=tree.branch)
+      if revision is None:
+        revid = branch.last_revision()
+      elif len(revision) == 1:
+        revid = revision[0].in_history(branch).rev_id
+      else:
+        raise BzrCommandError('bzr builddeb --revision takes exactly one '
+                              'revision specifier.')
+      info("Building branch from revision %s", revid)
+      tree = branch.repository.revision_tree(revid)
+      working_tree = False
+
+    config_files = []
+    if (working_tree and 
+        tree.has_filename(local_conf) and tree.path2id(local_conf) is None):
+      config_files.append((tree.get_file_byname(local_conf), True))
+    if not no_user_config:
+      config_files.append((global_conf, True))
+    if tree.path2id(default_conf):
+      config_files.append((tree.get_file(tree.path2id(default_conf)), False))
+    config = DebBuildConfig(config_files)
 
     if reuse:
       info("Reusing existing build dir")
@@ -221,21 +247,7 @@
           if builder is None:
             builder = "dpkg-buildpackage -uc -us -rfakeroot"
 
-    if revision is None:
-      info("Building using working tree")
-      t = tree
-      working_tree = True
-    else:
-      if len(revision) != 1:
-        raise BzrCommandError('bzr builddeb --revision takes exactly one '
-                              'revision specifier.')
-      b = tree.branch
-      rev = revision[0].in_history(b)
-      info("Building branch from revision %s", rev.rev_id)
-      t = b.repository.revision_tree(rev.rev_id)
-      working_tree = False
-
-    (changelog, larstiq) = find_changelog(t, merge)
+    (changelog, larstiq) = find_changelog(tree, merge)
 
     config.set_version(changelog.version)
 
@@ -255,30 +267,30 @@
       if orig_dir is None:
         orig_dir = default_orig_dir
     
-    properties = BuildProperties(changelog,build_dir,orig_dir,larstiq)
+    properties = BuildProperties(changelog, build_dir, orig_dir, larstiq)
 
     if merge:
       if export_upstream is None:
-        build = DebMergeBuild(properties, t, _is_working_tree=working_tree)
+        build = DebMergeBuild(properties, tree, _is_working_tree=working_tree)
       else:
         prepull_upstream = config.prepull_upstream
         stop_on_no_change = config.prepull_upstream_stop
-        build = DebMergeExportUpstreamBuild(properties, t, export_upstream,
+        build = DebMergeExportUpstreamBuild(properties, tree, export_upstream,
                                             export_upstream_revision,
                                             prepull_upstream,
                                             stop_on_no_change,
                                             _is_working_tree=working_tree)
     elif native:
-      build = DebNativeBuild(properties, t, _is_working_tree=working_tree)
+      build = DebNativeBuild(properties, tree, _is_working_tree=working_tree)
     elif split:
-      build = DebSplitBuild(properties, t, _is_working_tree=working_tree)
+      build = DebSplitBuild(properties, tree, _is_working_tree=working_tree)
     else:
       if export_upstream is None:
-        build = DebBuild(properties, t, _is_working_tree=working_tree)
+        build = DebBuild(properties, tree, _is_working_tree=working_tree)
       else:
         prepull_upstream = config.prepull_upstream
         stop_on_no_change = config.prepull_upstream_stop
-        build = DebExportUpstreamBuild(properties, t, export_upstream,
+        build = DebExportUpstreamBuild(properties, tree, export_upstream,
                                        export_upstream_revision,
                                        prepull_upstream,
                                        stop_on_no_change,
@@ -286,7 +298,7 @@
 
     build.prepare(use_existing)
 
-    run_hook('pre-export', config)
+    run_hook(tree, 'pre-export', config)
 
     try:
       build.export(use_existing)
@@ -295,9 +307,9 @@
       return
 
     if not export_only:
-      run_hook('pre-build', config, wd=properties.source_dir())
+      run_hook(tree, 'pre-build', config, wd=properties.source_dir())
       build.build(builder)
-      run_hook('post-build', config, wd=properties.source_dir())
+      run_hook(tree, 'post-build', config, wd=properties.source_dir())
       if not dont_purge:
         build.clean()
       if result is not None:
@@ -343,7 +355,7 @@
     if version is None:
       raise BzrCommandError("You must supply the --version argument.")
 
-    tree, relpath = WorkingTree.open_containing('.')
+    tree, _ = WorkingTree.open_containing('.')
 
     config = DebBuildConfig([(local_conf, True), (global_conf, True),
                              (default_conf, False)])

=== modified file 'config.py'
--- a/config.py	2008-03-05 17:00:51 +0000
+++ b/config.py	2008-05-18 01:34:44 +0000
@@ -63,7 +63,6 @@
     """
     self._config_files = []
     self.version = version
-    assert(len(files) > 0)
     for input in files:
       config = ConfigObj(input[0])
       self._config_files.append((config, input[1]))

=== modified file 'debian/changelog'
--- a/debian/changelog	2008-05-16 11:29:16 +0000
+++ b/debian/changelog	2008-05-29 22:51:16 +0000
@@ -1,6 +1,8 @@
 bzr-builddeb (0.95) UNRELEASED; urgency=low
 
-  * 
+  [ Jelmer Vernooij ]
+  * Support building from remote branches,
+    "bzr builddeb http://wherever/package.debian" will now work.
 
  -- James Westby <james.westby at canonical.com>  Fri, 16 May 2008 12:29:08 +0100
 

=== modified file 'hooks.py'
--- a/hooks.py	2008-03-05 17:00:51 +0000
+++ b/hooks.py	2008-05-18 00:04:21 +0000
@@ -25,15 +25,13 @@
 from bzrlib.plugins.builddeb.errors import HookFailedError
 
 
-def run_hook(hook_name, config, wd=None):
+def run_hook(tree, hook_name, config, wd="."):
   hook = config.get_hook(hook_name)
   if hook is None:
     return
   info("Running %s as %s hook" % (hook, hook_name))
-  kwargs = {}
-  if wd is not None:
-    kwargs['cwd'] = wd
-  proc = subprocess.Popen(hook, shell=True, **kwargs)
+  proc = subprocess.Popen(hook, shell=True, 
+                          cwd=tree.abspath(wd))
   proc.wait()
   if proc.returncode != 0:
     raise HookFailedError(hook_name)

=== modified file 'tests/blackbox/test_builddeb.py'
--- a/tests/blackbox/test_builddeb.py	2008-03-19 21:33:05 +0000
+++ b/tests/blackbox/test_builddeb.py	2008-05-18 01:34:44 +0000
@@ -138,6 +138,7 @@
       f.write('pre-build = touch pre-build\npost-build = touch post-build\n')
     finally:
       f.close()
+    self.run_bzr('add .bzr-builddeb/default.conf')
     self.run_bzr('bd --no-user-conf --dont-purge --builder true')
     self.failUnlessExists('pre-export')
     self.assertInBuildDir(['pre-build', 'post-build'])
@@ -160,6 +161,7 @@
       f.write('export-upstream-revision = tag:test-$UPSTREAM_VERSION\n')
     finally:
       f.close()
+    self.run_bzr('add .bzr-builddeb/default.conf')
     self.run_bzr('bd --no-user-conf --dont-purge --builder true')
     self.assertInBuildDir(['a'])
     self.assertNotInBuildDir(['b'])

=== modified file 'tests/test_hooks.py'
--- a/tests/test_hooks.py	2008-03-05 17:00:51 +0000
+++ b/tests/test_hooks.py	2008-05-18 00:04:21 +0000
@@ -26,6 +26,9 @@
 from bzrlib.plugins.builddeb.errors import HookFailedError
 from bzrlib.plugins.builddeb.hooks import run_hook
 
+class MockTree:
+  def abspath(self, relpath):
+    return os.path.abspath(relpath)
 
 class HookTests(TestCaseInTempDir):
 
@@ -36,7 +39,7 @@
     f = open(self.default_conf, 'wb')
     f.close()
     config = DebBuildConfig([(self.default_conf, False)])
-    run_hook('pre-build', config)
+    run_hook(MockTree(), 'pre-build', config)
 
   def test_run_hook_raises_when_hook_fails(self):
     f = open(self.default_conf, 'wb')
@@ -45,7 +48,7 @@
     finally:
       f.close()
     config = DebBuildConfig([(self.default_conf, False)])
-    self.assertRaises(HookFailedError, run_hook, 'pre-build', config)
+    self.assertRaises(HookFailedError, run_hook, MockTree(), 'pre-build', config)
 
   def test_run_hook_when_hook_passes(self):
     f = open(self.default_conf, 'wb')
@@ -54,7 +57,7 @@
     finally:
       f.close()
     config = DebBuildConfig([(self.default_conf, False)])
-    run_hook('pre-build', config)
+    run_hook(MockTree(), 'pre-build', config)
 
   def test_run_hook_uses_cwd_by_default(self):
     f = open(self.default_conf, 'wb')
@@ -63,7 +66,7 @@
     finally:
       f.close()
     config = DebBuildConfig([(self.default_conf, False)])
-    run_hook('pre-build', config)
+    run_hook(MockTree(), 'pre-build', config)
     self.failUnlessExists('a')
 
   def test_run_hook_uses_passed_wd(self):
@@ -74,7 +77,7 @@
     finally:
       f.close()
     config = DebBuildConfig([(self.default_conf, False)])
-    run_hook('pre-build', config, wd='dir')
+    run_hook(MockTree(), 'pre-build', config, wd='dir')
     self.failUnlessExists('dir/a')
 
   def test_run_hook_uses_shell(self):
@@ -84,7 +87,7 @@
     finally:
       f.close()
     config = DebBuildConfig([(self.default_conf, False)])
-    run_hook('post-build', config)
+    run_hook(MockTree(), 'post-build', config)
     self.failUnlessExists('a')
     self.failUnlessExists('b')
 
@@ -101,7 +104,7 @@
       f.close()
     config = DebBuildConfig([(self.local_conf, False),
                              (self.default_conf, False)])
-    run_hook('post-build', config)
+    run_hook(MockTree(), 'post-build', config)
     self.failIfExists('a')
     self.failUnlessExists('b')
 

=== modified file 'tests/test_util.py'
--- a/tests/test_util.py	2008-05-15 15:11:55 +0000
+++ b/tests/test_util.py	2008-05-29 22:51:16 +0000
@@ -136,6 +136,7 @@
     self.write_changelog('changelog')
     tree.add(['changelog'])
     os.symlink('.', 'debian')
+    tree.add(['debian'])
     (cl, lq) = find_changelog(tree, True)
     self.assertEqual(str(cl), cl_block1)
     self.assertEqual(lq, True)

=== modified file 'util.py'
--- a/util.py	2008-05-15 15:11:55 +0000
+++ b/util.py	2008-05-29 22:51:16 +0000
@@ -47,12 +47,6 @@
       shutil.copy(path, todir)
 
 
-def goto_branch(branch):
-  """Changes to the specified branch dir if it is not None"""
-  if branch is not None:
-    info("Building using branch at %s", branch)
-    os.chdir(branch)
-
 def find_changelog(t, merge):
     changelog_file = 'debian/changelog'
     larstiq = False
@@ -69,7 +63,8 @@
           raise MissingChangelogError("debian/changelog")
       else:
         if merge and t.has_filename('changelog'):
-          if os.path.islink('debian') and os.readlink('debian') == '.':
+          if (t.kind(t.path2id('debian')) == 'symlink' and 
+              t.get_symlink_target(t.path2id('debian')) == '.'):
             changelog_file = 'changelog'
             larstiq = True
       mutter("Using '%s' to get package information", changelog_file)
@@ -84,7 +79,7 @@
     return changelog, larstiq
 
 def tarball_name(package, version):
-  """Return the name of the .orig.tar.gz for the given pakcage and version."""
+  """Return the name of the .orig.tar.gz for the given package and version."""
 
   return "%s_%s.orig.tar.gz" % (package, str(version))
 



More information about the Pkg-bazaar-commits mailing list