Make landmines work on the first landmine.
authormachenbach@chromium.org <machenbach@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 23 Jul 2014 11:33:29 +0000 (11:33 +0000)
committermachenbach@chromium.org <machenbach@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 23 Jul 2014 11:33:29 +0000 (11:33 +0000)
With the original script, landmines don't work if the initial commit of the landmine script and the first landmine are in the same build. In this case, the landmine file wouldn't exist yet and no landmine would be triggered. But the updated landmine content would have still been written, omitting the landmine.

Now, the script will initialize an empty landmine file if none exists. This will make sure that a landmine is set on the branch builders after the next branch point.

This also adds some debugging output to better trace when landmines are set/deleted.

BUG=
R=jkummerow@chromium.org

Review URL: https://codereview.chromium.org/410893002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22557 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

build/landmines.py

index 2b3d775..fb8246f 100755 (executable)
@@ -58,21 +58,26 @@ def set_up_landmines(target, new_landmines):
   if not os.path.exists(out_dir):
     return
 
-  if os.path.exists(landmines_path):
-    triggered = os.path.join(out_dir, '.landmines_triggered')
-    with open(landmines_path, 'r') as f:
-      old_landmines = f.readlines()
-    if old_landmines != new_landmines:
-      old_date = time.ctime(os.stat(landmines_path).st_ctime)
-      diff = difflib.unified_diff(old_landmines, new_landmines,
-          fromfile='old_landmines', tofile='new_landmines',
-          fromfiledate=old_date, tofiledate=time.ctime(), n=0)
-
-      with open(triggered, 'w') as f:
-        f.writelines(diff)
-    elif os.path.exists(triggered):
-      # Remove false triggered landmines.
-      os.remove(triggered)
+  # Make sure the landmines tracker exists.
+  open(landmines_path, 'a').close()
+
+  triggered = os.path.join(out_dir, '.landmines_triggered')
+  with open(landmines_path, 'r') as f:
+    old_landmines = f.readlines()
+  if old_landmines != new_landmines:
+    old_date = time.ctime(os.stat(landmines_path).st_ctime)
+    diff = difflib.unified_diff(old_landmines, new_landmines,
+        fromfile='old_landmines', tofile='new_landmines',
+        fromfiledate=old_date, tofiledate=time.ctime(), n=0)
+
+    with open(triggered, 'w') as f:
+      f.writelines(diff)
+    print "Setting landmine: %s" % triggered
+    print "Reason:\n%s" % diff
+  elif os.path.exists(triggered):
+    # Remove false triggered landmines.
+    os.remove(triggered)
+    print "Removing landmine: %s" % triggered
   with open(landmines_path, 'w') as f:
     f.writelines(new_landmines)