From d450954d31df8d22c96ccd76d6af1d983266a2d4 Mon Sep 17 00:00:00 2001 From: Daniel Narvaez Date: Tue, 25 Dec 2012 01:45:09 +0000 Subject: Rebuild if the source tree changed --- (limited to 'devbot') diff --git a/devbot/git.py b/devbot/git.py index 1e361f0..8f6699c 100644 --- a/devbot/git.py +++ b/devbot/git.py @@ -72,6 +72,10 @@ class Module: return subprocess.check_output(["git", "describe"]).strip() @_chdir + def diff(self): + return subprocess.check_output(["git", "diff"]) + + @_chdir def get_annotation(self, tag): # FIXME this is fragile, there must be a better way diff --git a/devbot/state.py b/devbot/state.py index beba837..ae7fafd 100644 --- a/devbot/state.py +++ b/devbot/state.py @@ -1,3 +1,4 @@ +import hashlib import os import json @@ -25,10 +26,19 @@ def _save_state(name, state): json.dump(state, f, indent=4) f.write('\n') +def _get_diff_hash(git_module): + diff = git_module.diff().strip() + if diff: + return hashlib.sha256(diff).hexdigest() + else: + return None + def touch_built_module(module): + git_module = module.get_git_module() built_modules = _load_state(_BUILT_MODULES, {}) - info = {"commit": module.get_commit_id()} + info = {"commit": module.get_commit_id(), + "diff_hash": _get_diff_hash(git_module)} built_modules[module.name] = info _save_state(_BUILT_MODULES, built_modules) @@ -41,9 +51,15 @@ def remove_built_module(module): _save_state(_BUILT_MODULES, built_modules) def check_built_module(module): + git_module = module.get_git_module() built_modules = _load_state(_BUILT_MODULES, {}) - info = built_modules.get(module.name, {}) - return module.get_commit_id() == info.get("commit", None) + if module.name not in built_modules: + return False + + info = built_modules[module.name] + + return info["diff_hash"] == _get_diff_hash(git_module) and \ + info["commit"] == module.get_commit_id() def get_last_system_check(): system_check = _load_state(_SYSTEM_CHECK, {}) -- cgit v0.9.1