Index: build/landmines.py |
diff --git a/build/landmines.py b/build/landmines.py |
index 220b8a7989f45cd7a037473be6db65b70d2551b4..c31bac7901c362a320d735596dba887aa2d34ba3 100755 |
--- a/build/landmines.py |
+++ b/build/landmines.py |
@@ -4,10 +4,8 @@ |
# found in the LICENSE file. |
""" |
-This script runs every build as a hook. If it detects that the build should |
-be clobbered, it will touch the file <build_dir>/.landmine_triggered. The |
-various build scripts will then check for the presence of this file and clobber |
-accordingly. The script will also emit the reasons for the clobber to stdout. |
+This script runs every build as the first hook (See DEPS). If it detects that |
+the build should be clobbered, it will remove the build directory. |
A landmine is tripped when a builder checks out a different revision, and the |
diff between the new landmines and the old ones is non-null. At this point, the |
@@ -16,9 +14,11 @@ build is clobbered. |
import difflib |
import errno |
+import gyp_environment |
import logging |
import optparse |
import os |
+import shutil |
import sys |
import subprocess |
import time |
@@ -29,35 +29,32 @@ import landmine_utils |
SRC_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
-def get_target_build_dir(build_tool, target, is_iphone=False): |
+def get_build_dir(build_tool, is_iphone=False): |
""" |
Returns output directory absolute path dependent on build and targets. |
Examples: |
- r'c:\b\build\slave\win\build\src\out\Release' |
- '/mnt/data/b/build/slave/linux/build/src/out/Debug' |
- '/b/build/slave/ios_rel_device/build/src/xcodebuild/Release-iphoneos' |
+ r'c:\b\build\slave\win\build\src\out' |
+ '/mnt/data/b/build/slave/linux/build/src/out' |
+ '/b/build/slave/ios_rel_device/build/src/xcodebuild' |
Keep this function in sync with tools/build/scripts/slave/compile.py |
""" |
ret = None |
if build_tool == 'xcode': |
- ret = os.path.join(SRC_DIR, 'xcodebuild', |
- target + ('-iphoneos' if is_iphone else '')) |
+ ret = os.path.join(SRC_DIR, 'xcodebuild') |
elif build_tool in ['make', 'ninja', 'ninja-ios']: # TODO: Remove ninja-ios. |
- ret = os.path.join(SRC_DIR, 'out', target) |
+ ret = os.path.join(SRC_DIR, 'out') |
elif build_tool in ['msvs', 'vs', 'ib']: |
- ret = os.path.join(SRC_DIR, 'build', target) |
+ ret = os.path.join(SRC_DIR, 'build') |
else: |
raise NotImplementedError('Unexpected GYP_GENERATORS (%s)' % build_tool) |
return os.path.abspath(ret) |
-def set_up_landmines(target, new_landmines): |
+def clobber_if_necessary(new_landmines): |
"""Does the work of setting, planting, and triggering landmines.""" |
- out_dir = get_target_build_dir(landmine_utils.builder(), target, |
- landmine_utils.platform() == 'ios') |
- |
- landmines_path = os.path.join(out_dir, '.landmines') |
+ out_dir = get_build_dir(landmine_utils.builder()) |
+ landmines_path = os.path.normpath(os.path.join(out_dir, '..', '.landmines')) |
try: |
os.makedirs(out_dir) |
except OSError as e: |
@@ -65,7 +62,6 @@ def set_up_landmines(target, new_landmines): |
pass |
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: |
@@ -73,12 +69,13 @@ def set_up_landmines(target, new_landmines): |
diff = difflib.unified_diff(old_landmines, new_landmines, |
fromfile='old_landmines', tofile='new_landmines', |
fromfiledate=old_date, tofiledate=time.ctime(), n=0) |
+ sys.stdout.write('Clobbering due to:\n') |
+ sys.stdout.writelines(diff) |
+ |
+ # Clobber. |
+ shutil.rmtree(out_dir) |
- with open(triggered, 'w') as f: |
- f.writelines(diff) |
- elif os.path.exists(triggered): |
- # Remove false triggered landmines. |
- os.remove(triggered) |
+ # Save current set of landmines for next time. |
with open(landmines_path, 'w') as f: |
f.writelines(new_landmines) |
@@ -119,14 +116,14 @@ def main(): |
if landmine_utils.builder() in ('dump_dependency_json', 'eclipse'): |
return 0 |
- for target in ('Debug', 'Release', 'Debug_x64', 'Release_x64'): |
- landmines = [] |
- for s in landmine_scripts: |
- proc = subprocess.Popen([sys.executable, s, '-t', target], |
- stdout=subprocess.PIPE) |
- output, _ = proc.communicate() |
- landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) |
- set_up_landmines(target, landmines) |
+ gyp_environment.SetEnvironment() |
+ |
+ landmines = [] |
+ for s in landmine_scripts: |
+ proc = subprocess.Popen([sys.executable, s], stdout=subprocess.PIPE) |
+ output, _ = proc.communicate() |
+ landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) |
+ clobber_if_necessary(landmines) |
return 0 |