Blob Blame History Raw
diff --git a/module_build_service/utils/reuse.py b/module_build_service/utils/reuse.py
index efbbc0a..dcdbc07 100644
--- a/module_build_service/utils/reuse.py
+++ b/module_build_service/utils/reuse.py
@@ -25,7 +25,7 @@
 import kobo.rpmlib
 
 import module_build_service.messaging
-from module_build_service import log, models, conf
+from module_build_service import log, models, conf, glib
 
 
 def reuse_component(component, previous_component_build,
@@ -110,6 +110,27 @@ def _get_reusable_module(session, module):
         log.info("Cannot re-use.  %r is the first module build." % module)
         return None
 
+    xmd = glib.from_variant_dict(mmd.get_xmd())
+    old_mmd = previous_module_build.mmd()
+    old_xmd = glib.from_variant_dict(old_mmd.get_xmd())
+
+    try:
+        # Make sure that the module buildrequires commit hashes are exactly the same
+        for br_module_name, br_module in xmd['mbs']['buildrequires'].items():
+            # Assumes that the streams have been replaced with commit hashes, so we
+            # can compare to see if they have changed. Since a build is unique to
+            # a commit hash, this is a safe test.
+            ref1 = br_module.get('ref')
+            ref2 = old_xmd['mbs']['buildrequires'][br_module_name].get('ref')
+            if not (ref1 and ref2) or ref1 != ref2:
+                log.info('Cannot re-use.  The buildrequired module %s ref hash changed',
+                         br_module_name)
+                return None
+    except KeyError:
+        log.info('Cannot re-use.  The buildrequired module %s does not have the same '
+                 'set of buildrequires.', br_module_name)
+        return None
+
     return previous_module_build