2 # Copyright 2014 the V8 project authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
7 This script runs every build as a hook. If it detects that the build should
8 be clobbered, it will touch the file <build_dir>/.landmine_triggered. The
9 various build scripts will then check for the presence of this file and clobber
10 accordingly. The script will also emit the reasons for the clobber to stdout.
12 A landmine is tripped when a builder checks out a different revision, and the
13 diff between the new landmines and the old ones is non-null. At this point, the
28 SRC_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
31 def get_target_build_dir(build_tool, target):
33 Returns output directory absolute path dependent on build and targets.
35 r'c:\b\build\slave\win\build\src\out\Release'
36 '/mnt/data/b/build/slave/linux/build/src/out/Debug'
37 '/b/build/slave/ios_rel_device/build/src/xcodebuild/Release-iphoneos'
39 Keep this function in sync with tools/build/scripts/slave/compile.py
42 if build_tool == 'xcode':
43 ret = os.path.join(SRC_DIR, 'xcodebuild', target)
44 elif build_tool in ['make', 'ninja', 'ninja-ios']: # TODO: Remove ninja-ios.
45 ret = os.path.join(SRC_DIR, 'out', target)
46 elif build_tool in ['msvs', 'vs', 'ib']:
47 ret = os.path.join(SRC_DIR, 'build', target)
49 raise NotImplementedError('Unexpected GYP_GENERATORS (%s)' % build_tool)
50 return os.path.abspath(ret)
53 def set_up_landmines(target, new_landmines):
54 """Does the work of setting, planting, and triggering landmines."""
55 out_dir = get_target_build_dir(landmine_utils.builder(), target)
57 landmines_path = os.path.join(out_dir, '.landmines')
58 if not os.path.exists(out_dir):
61 if not os.path.exists(landmines_path):
62 print "Landmines tracker didn't exists."
64 # FIXME(machenbach): Clobber deletes the .landmines tracker. Difficult
65 # to know if we are right after a clobber or if it is first-time landmines
66 # deployment. Also, a landmine-triggered clobber right after a clobber is
67 # not possible. Different clobber methods for msvs, xcode and make all
68 # have different blacklists of files that are not deleted.
69 if os.path.exists(landmines_path):
70 triggered = os.path.join(out_dir, '.landmines_triggered')
71 with open(landmines_path, 'r') as f:
72 old_landmines = f.readlines()
73 if old_landmines != new_landmines:
74 old_date = time.ctime(os.stat(landmines_path).st_ctime)
75 diff = difflib.unified_diff(old_landmines, new_landmines,
76 fromfile='old_landmines', tofile='new_landmines',
77 fromfiledate=old_date, tofiledate=time.ctime(), n=0)
79 with open(triggered, 'w') as f:
81 print "Setting landmine: %s" % triggered
82 elif os.path.exists(triggered):
83 # Remove false triggered landmines.
85 print "Removing landmine: %s" % triggered
86 with open(landmines_path, 'w') as f:
87 f.writelines(new_landmines)
90 def process_options():
91 """Returns a list of landmine emitting scripts."""
92 parser = optparse.OptionParser()
94 '-s', '--landmine-scripts', action='append',
95 default=[os.path.join(SRC_DIR, 'build', 'get_landmines.py')],
96 help='Path to the script which emits landmines to stdout. The target '
97 'is passed to this script via option -t. Note that an extra '
98 'script can be specified via an env var EXTRA_LANDMINES_SCRIPT.')
99 parser.add_option('-v', '--verbose', action='store_true',
100 default=('LANDMINES_VERBOSE' in os.environ),
101 help=('Emit some extra debugging information (default off). This option '
102 'is also enabled by the presence of a LANDMINES_VERBOSE environment '
105 options, args = parser.parse_args()
108 parser.error('Unknown arguments %s' % args)
111 level=logging.DEBUG if options.verbose else logging.ERROR)
113 extra_script = os.environ.get('EXTRA_LANDMINES_SCRIPT')
115 return options.landmine_scripts + [extra_script]
117 return options.landmine_scripts
121 landmine_scripts = process_options()
123 if landmine_utils.builder() in ('dump_dependency_json', 'eclipse'):
127 for s in landmine_scripts:
128 proc = subprocess.Popen([sys.executable, s], stdout=subprocess.PIPE)
129 output, _ = proc.communicate()
130 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()])
132 for target in ('Debug', 'Release'):
133 set_up_landmines(target, landmines)
138 if __name__ == '__main__':