X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-dev.git/blobdiff_plain/1df2c5ee4af289b6c68d28b021cceaacecb61b61..209f1da1f4b13941e75a41e1091e79bdda4c4f56:/invirtibuilder diff --git a/invirtibuilder b/invirtibuilder index aa70b53..9198549 100755 --- a/invirtibuilder +++ b/invirtibuilder @@ -129,7 +129,7 @@ def sbuildAll(package, ref, workdir): sbuild(package, ref, 'i386', workdir) -def tagSubmodule(pocket, package, principal, version, env): +def tagSubmodule(pocket, package, commit, principal, version, env): """Tag a new version of a submodule. If this pocket does not allow_backtracking, then this will create @@ -153,26 +153,32 @@ def tagSubmodule(pocket, package, principal, version, env): c.captureOutput( ['git', 'tag', '-m', tag_msg, commit], - stdout=None, - env=env) + env=env, + cwd=b.getRepo(package)) -def updateSubmoduleBranch(pocket, package, ref): +def updateSubmoduleBranch(pocket, package, commit): """Update the appropriately named branch in the submodule.""" branch = b.pocketToGit(pocket) c.captureOutput( - ['git', 'update-ref', 'refs/heads/%s' % branch, ref], cwd=b.getRepo(package)) + ['git', 'update-ref', 'refs/heads/%s' % branch, commit], cwd=b.getRepo(package)) def uploadBuild(pocket, workdir): """Upload all build products in the work directory.""" + force = config.build.pockets[pocket].get('allow_backtracking', False) apt = b.pocketToApt(pocket) for changes in glob.glob(os.path.join(workdir, '*.changes')): - c.captureOutput(['reprepro-env', - '--ignore=wrongdistribution', - 'include', - apt, - changes]) + upload = ['reprepro-env', '--ignore=wrongdistribution', + 'include', apt, changes] + try: + c.captureOutput(upload) + except subprocess.CalledProcessError, e: + if not force: + raise + package = deb822.Changes(open(changes).read())['Binary'] + c.captureOutput(['reprepro-env', 'remove', apt, package]) + c.captureOutput(upload) def updateSuperproject(pocket, package, commit, principal, version, env): @@ -249,16 +255,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 +284,19 @@ 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) + version = b.getVersion(package, commit) + db.version = str(version) + b.runHook('pre-build', [str(db.build_id), db.pocket, db.package, + db.commit, db.principal, db.version, str(db.inserted_at)]) - db.version = str(b.getVersion(package, commit)) + env = dict(os.environ) + env['GIT_COMMITTER_NAME'] = config.build.tagger.name + env['GIT_COMMITTER_EMAIL'] = config.build.tagger.email # If validateBuild returns something other than True, then # it means we should copy from that pocket to our pocket. @@ -302,8 +304,16 @@ def build(): # (If the validation failed, validateBuild would have # raised an exception) if src != True: + # TODO: cut out this code duplication + db.failed_stage = 'tagging submodule before copying package' + tagSubmodule(pocket, package, commit, principal, version, env) + db.failed_stage = 'updating submodule branches before copying package' + updateSubmoduleBranch(pocket, package, commit) + db.failed_stage = 'updating superproject before copying package' + updateSuperproject(pocket, package, commit, principal, version, env) db.failed_stage = 'copying package from another pocket' aptCopy(package, commit, pocket, src) + # If we can't copy the package from somewhere, but # validateBuild didn't raise an exception, then we need to # do the build ourselves @@ -335,14 +345,8 @@ def build(): for log in glob.glob(os.path.join(workdir, 'build-*.log')): os.copy(log, logdir) - db.failed_stage = 'processing metadata' - env = dict(os.environ) - env['GIT_COMMITTER_NAME'] = config.build.tagger.name - env['GIT_COMMITTER_EMAIL'] = config.build.tagger.email - version = b.getVersion(package, commit) - db.failed_stage = 'tagging submodule' - tagSubmodule(pocket, package, principal, version, env) + tagSubmodule(pocket, package, commit, principal, version, env) db.failed_stage = 'updating submodule branches' updateSubmoduleBranch(pocket, package, commit) db.failed_stage = 'updating superproject' @@ -366,8 +370,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."""