Do work from correct cwd
[invirt/packages/invirt-dev.git] / invirtibuilder
index d2a571c..a42ce55 100755 (executable)
@@ -113,11 +113,11 @@ def aptCopy(package, commit, dst_pocket, src_pocket):
 
 def sbuild(package, ref, arch, workdir, arch_all=False):
     """Build a package for a particular architecture."""
-    args = ['sbuild', '-d', DISTRIBUTION, '--arch', arch]
+    args = ['sbuild', '-v', '-d', DISTRIBUTION, '--arch', arch]
     if arch_all:
         args.append('-A')
     args.append(getDscName(package, ref))
-    c.captureOutput(args, cwd=workdir, stdout=None)
+    c.captureOutput(args, cwd=workdir)
 
 
 def sbuildAll(package, ref, workdir):
@@ -249,16 +249,6 @@ def packageWorkdir(package, commit):
     finally:
         shutil.rmtree(workdir)
 
-
-def reportBuild(build):
-    """Run hooks to report the results of a build attempt."""
-
-    c.captureOutput(['run-parts',
-                   '--arg=%s' % build.build_id,
-                   '--',
-                   b._HOOKS_DIR])
-
-
 def build():
     """Deal with items in the build queue.
 
@@ -288,13 +278,15 @@ def build():
 
         try:
             db.failed_stage = 'validating job'
-            src = b.validateBuild(pocket, package, commit)
             # Don't expand the commit in the DB until we're sure the user
             # isn't trying to be tricky.
-            db.commit = commit = c.captureOutput(['git', 'rev-parse', commit],
-                                                 cwd=b.getRepo(package)).strip()
+            b.ensureValidPackage(package)
+            db.commit = commit = b.canonicalize_commit(package, commit)
+            src = b.validateBuild(pocket, package, commit)
 
             db.version = str(b.getVersion(package, commit))
+            b.runHook('pre-build', [str(db.build_id), db.pocket, db.package,
+                                    db.commit, db.principal, db.version, str(db.inserted_at)])
 
             # If validateBuild returns something other than True, then
             # it means we should copy from that pocket to our pocket.
@@ -332,8 +324,8 @@ def build():
                         if not os.path.exists(logdir):
                             os.makedirs(logdir)
 
-                        for log in glob.glob(os.path.join(workdir, '*.build')):
-                            os.copy2(log, logdir)
+                        for log in glob.glob(os.path.join(workdir, 'build-*.log')):
+                            os.copy(log, logdir)
 
                     db.failed_stage = 'processing metadata'
                     env = dict(os.environ)
@@ -366,8 +358,10 @@ def build():
             # build queue item
             os.unlink(os.path.join(b._QUEUE_DIR, build))
 
-            reportBuild(db)
-
+            if db.succeeded:
+                b.runHook('post-build', [str(db.build_id)])
+            else:
+                b.runHook('failed-build', [str(db.build_id)])
 
 class Invirtibuilder(pyinotify.ProcessEvent):
     """Process inotify triggers to build new packages."""