[Pkg-bazaar-commits] r192 ./bzr-builddeb/people/jdw/dev: Hook up the hooks to the builddeb command.

James Westby jw+debian at jameswestby.net
Sun Sep 16 18:11:30 UTC 2007


------------------------------------------------------------
revno: 192
committer: James Westby <jw+debian at jameswestby.net>
branch nick: dev
timestamp: Sun 2007-09-16 19:11:30 +0100
message:
  Hook up the hooks to the builddeb command.
  
  There are currently 3 hooks, 'pre-export' that is run before the the package
  is exported so that the branch/working tree can be modified. However the
  tree is grabbed first if -r is specified, which may be suprsing. It is run
  with the branch as the cwd.
  
  The next two are 'pre-build' and 'post-build' that are run before and after
  the builder, with the exported source as the working directory.
  
  More points could be added, and the other commands may want to hook in to the
  hooks, especially bd-do.
  
  There could also be an option to disable hooks, for one run on the command
  line, or through the config files, and perhaps an option to enable them, as
  discussed in the spec.
modified:
  __init__.py
  tests/blackbox/test_builddeb.py
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2007-09-16 16:59:59 +0000
+++ b/__init__.py	2007-09-16 18:11:30 +0000
@@ -43,6 +43,7 @@
 from config import DebBuildConfig
 from errors import (StopBuild,
                     )
+from hooks import run_hook
 from properties import BuildProperties
 from util import goto_branch, find_changelog, tarball_name
 
@@ -283,6 +284,8 @@
 
     build.prepare(use_existing)
 
+    run_hook('pre-export', config)
+
     try:
       build.export(use_existing)
     except StopBuild, e:
@@ -290,7 +293,9 @@
       return
 
     if not export_only:
+      run_hook('pre-build', config, wd=properties.source_dir())
       build.build(builder)
+      run_hook('post-build', config, wd=properties.source_dir())
       if not dont_purge:
         build.clean()
       if result is not None:

=== modified file 'tests/blackbox/test_builddeb.py'
--- a/tests/blackbox/test_builddeb.py	2007-09-13 21:56:04 +0000
+++ b/tests/blackbox/test_builddeb.py	2007-09-16 18:11:30 +0000
@@ -74,11 +74,15 @@
 
   def assertInBuildDir(self, files):
     build_dir = self.build_dir()
+    if isinstance(files, basestring):
+      files = [files]
     for filename in files:
       self.failUnlessExists(os.path.join(build_dir, filename))
 
   def assertNotInBuildDir(self, files):
     build_dir = self.build_dir()
+    if isinstance(files, basestring):
+      files = [files]
     for filename in files:
       self.failIfExists(os.path.join(build_dir, filename))
 
@@ -126,3 +130,32 @@
     self.assertNotInBuildDir([self.commited_file, self.unadded_file,
                               self.uncommited_file])
 
+  def orig_dir(self):
+    return os.path.join('..', 'tarballs')
+
+  def make_upstream_tarball(self):
+    os.mkdir(self.orig_dir())
+    f = open(os.path.join(self.orig_dir(), self.package_name + "_" +
+                          str(self.package_version.upstream_version) +
+                          ".orig.tar.gz"), 'wb')
+    f.close()
+
+  def test_builder(self):
+    tree = self.make_unpacked_source()
+    self.run_bzr('bd --dont-purge --native --builder "touch built"')
+    self.assertInBuildDir('built')
+
+  def test_hooks(self):
+    tree = self.make_unpacked_source()
+    self.make_upstream_tarball()
+    os.mkdir('.bzr-builddeb/')
+    f = open('.bzr-builddeb/default.conf', 'wb')
+    try:
+      f.write('[HOOKS]\npre-export = touch pre-export\n')
+      f.write('pre-build = touch pre-build\npost-build = touch post-build\n')
+    finally:
+      f.close()
+    self.run_bzr('bd --dont-purge --builder true')
+    self.failUnlessExists('pre-export')
+    self.assertInBuildDir(['pre-build', 'post-build'])
+



More information about the Pkg-bazaar-commits mailing list