2012-11-14 08:59:48 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
"""
|
2014-08-14 18:03:30 +04:00
|
|
|
This script runs every build as the first hook (See DEPS). If it detects that
|
2014-09-04 01:28:23 +04:00
|
|
|
the build should be clobbered, it will delete the contents of the build
|
|
|
|
directory.
|
2012-11-14 08:59:48 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
build is clobbered.
|
2017-06-27 19:04:46 +03:00
|
|
|
|
|
|
|
Before adding or changing a landmine consider the consequences of doing so.
|
|
|
|
Doing so will wipe out every output directory on every Chrome developer's
|
|
|
|
machine. This can be particularly problematic on Windows where the directory
|
|
|
|
deletion may well fail (locked files, command prompt in the directory, etc.),
|
|
|
|
and generated .sln and .vcxproj files will be deleted.
|
|
|
|
|
|
|
|
This output directory deletion will be repated when going back and forth across
|
|
|
|
the change that added the landmine, adding to the cost. There are usually less
|
|
|
|
troublesome alternatives.
|
2012-11-14 08:59:48 +04:00
|
|
|
"""
|
|
|
|
|
|
|
|
import difflib
|
2014-04-23 08:19:23 +04:00
|
|
|
import errno
|
2012-11-15 06:53:03 +04:00
|
|
|
import logging
|
|
|
|
import optparse
|
2012-11-14 08:59:48 +04:00
|
|
|
import os
|
|
|
|
import sys
|
2013-08-21 06:44:58 +04:00
|
|
|
import subprocess
|
2012-11-14 08:59:48 +04:00
|
|
|
import time
|
|
|
|
|
2015-06-22 15:41:49 +03:00
|
|
|
import clobber
|
2013-08-21 06:44:58 +04:00
|
|
|
import landmine_utils
|
2012-11-14 08:59:48 +04:00
|
|
|
|
|
|
|
|
2016-07-30 03:35:24 +03:00
|
|
|
def get_build_dir(src_dir):
|
2019-05-15 08:10:34 +03:00
|
|
|
r"""
|
2012-11-14 08:59:48 +04:00
|
|
|
Returns output directory absolute path dependent on build and targets.
|
|
|
|
Examples:
|
2014-08-14 18:03:30 +04:00
|
|
|
r'c:\b\build\slave\win\build\src\out'
|
|
|
|
'/mnt/data/b/build/slave/linux/build/src/out'
|
2016-07-30 03:35:24 +03:00
|
|
|
'/b/build/slave/ios_rel_device/build/src/out'
|
2012-11-14 08:59:48 +04:00
|
|
|
|
|
|
|
Keep this function in sync with tools/build/scripts/slave/compile.py
|
|
|
|
"""
|
2016-07-30 03:35:24 +03:00
|
|
|
if 'CHROMIUM_OUT_DIR' in os.environ:
|
|
|
|
output_dir = os.environ.get('CHROMIUM_OUT_DIR').strip()
|
|
|
|
if not output_dir:
|
|
|
|
raise Error('CHROMIUM_OUT_DIR environment variable is set but blank!')
|
2012-11-14 08:59:48 +04:00
|
|
|
else:
|
2018-02-21 02:27:59 +03:00
|
|
|
output_dir = 'out'
|
2016-07-30 03:35:24 +03:00
|
|
|
return os.path.abspath(os.path.join(src_dir, output_dir))
|
2012-11-14 08:59:48 +04:00
|
|
|
|
|
|
|
|
2020-07-08 20:32:10 +03:00
|
|
|
def clobber_if_necessary(new_landmines, src_dir, landmines_path):
|
2012-11-15 06:53:03 +04:00
|
|
|
"""Does the work of setting, planting, and triggering landmines."""
|
2016-07-30 03:35:24 +03:00
|
|
|
out_dir = get_build_dir(src_dir)
|
2014-04-23 08:19:23 +04:00
|
|
|
try:
|
2012-11-15 06:53:03 +04:00
|
|
|
os.makedirs(out_dir)
|
2014-04-23 08:19:23 +04:00
|
|
|
except OSError as e:
|
|
|
|
if e.errno == errno.EEXIST:
|
|
|
|
pass
|
2012-11-14 08:59:48 +04:00
|
|
|
|
2014-05-23 02:12:48 +04:00
|
|
|
if os.path.exists(landmines_path):
|
2012-11-15 06:53:03 +04:00
|
|
|
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)
|
2014-08-14 18:03:30 +04:00
|
|
|
sys.stdout.write('Clobbering due to:\n')
|
|
|
|
sys.stdout.writelines(diff)
|
2016-05-03 21:00:05 +03:00
|
|
|
sys.stdout.flush()
|
2014-08-14 18:03:30 +04:00
|
|
|
|
2015-06-22 15:41:49 +03:00
|
|
|
clobber.clobber(out_dir)
|
2012-11-15 06:53:03 +04:00
|
|
|
|
2014-08-14 18:03:30 +04:00
|
|
|
# Save current set of landmines for next time.
|
2014-05-23 02:12:48 +04:00
|
|
|
with open(landmines_path, 'w') as f:
|
|
|
|
f.writelines(new_landmines)
|
2012-11-15 06:53:03 +04:00
|
|
|
|
|
|
|
|
Revert 220853 "Revert 220846 "Make landmines.py take an extra sc..."
r220846 was not the root cause of the failure.
> Revert 220846 "Make landmines.py take an extra script via an env..."
>
> It broke telemetry_unittests.
> http://build.chromium.org/p/chromium.win/builders/Win%207%20Tests%20x64%20%283%29/builds/8782/steps/telemetry_unittests/logs/stdio
>
> E:\b\depot_tools\python_bin\python_slave.exe src\tools\telemetry\run_tests --browser=release_x64
> No adb found in $PATH, fallback to checked in binary.
> Traceback (most recent call last):
> File "src\tools\telemetry\run_tests", line 8, in <module>
> from telemetry.unittest import gtest_testrunner
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\__init__.py", line 12, in <module>
> from telemetry.core.browser_options import BrowserFinderOptions
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\browser_options.py", line 12, in <module>
> from telemetry.core import browser_finder
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\browser_finder.py", line 9, in <module>
> from telemetry.core.backends.chrome import android_browser_finder
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\android_browser_finder.py", line 17, in <module>
> from telemetry.core.backends.chrome import android_browser_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\android_browser_backend.py", line 15, in <module>
> from telemetry.core.backends.chrome import chrome_browser_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\chrome_browser_backend.py", line 19, in <module>
> from telemetry.core.backends.chrome import extension_dict_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\extension_dict_backend.py", line 9, in <module>
> from telemetry.core.backends.chrome import inspector_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\inspector_backend.py", line 19, in <module>
> from telemetry.core.jsheap import model
> ImportError: No module named jsheap
>
> > Make landmines.py take an extra script via an env var.
> >
> > The extra Python script to run can be specified via env var
> > EXTRA_LANDMINES_SCRIPT.
> >
> > BUG=223636
> >
> > Review URL: https://chromiumcodereview.appspot.com/23604016
>
> TBR=sivachandra@chromium.org
>
> Review URL: https://codereview.chromium.org/23533016
TBR=tkent@chromium.org
Review URL: https://codereview.chromium.org/23532029
git-svn-id: http://src.chromium.org/svn/trunk/src/build@220870 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
2013-09-03 01:51:18 +04:00
|
|
|
def process_options():
|
2015-10-14 22:28:06 +03:00
|
|
|
"""Returns an options object containing the configuration for this script."""
|
2012-11-15 06:53:03 +04:00
|
|
|
parser = optparse.OptionParser()
|
2013-08-21 06:44:58 +04:00
|
|
|
parser.add_option(
|
|
|
|
'-s', '--landmine-scripts', action='append',
|
|
|
|
help='Path to the script which emits landmines to stdout. The target '
|
Revert 220853 "Revert 220846 "Make landmines.py take an extra sc..."
r220846 was not the root cause of the failure.
> Revert 220846 "Make landmines.py take an extra script via an env..."
>
> It broke telemetry_unittests.
> http://build.chromium.org/p/chromium.win/builders/Win%207%20Tests%20x64%20%283%29/builds/8782/steps/telemetry_unittests/logs/stdio
>
> E:\b\depot_tools\python_bin\python_slave.exe src\tools\telemetry\run_tests --browser=release_x64
> No adb found in $PATH, fallback to checked in binary.
> Traceback (most recent call last):
> File "src\tools\telemetry\run_tests", line 8, in <module>
> from telemetry.unittest import gtest_testrunner
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\__init__.py", line 12, in <module>
> from telemetry.core.browser_options import BrowserFinderOptions
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\browser_options.py", line 12, in <module>
> from telemetry.core import browser_finder
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\browser_finder.py", line 9, in <module>
> from telemetry.core.backends.chrome import android_browser_finder
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\android_browser_finder.py", line 17, in <module>
> from telemetry.core.backends.chrome import android_browser_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\android_browser_backend.py", line 15, in <module>
> from telemetry.core.backends.chrome import chrome_browser_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\chrome_browser_backend.py", line 19, in <module>
> from telemetry.core.backends.chrome import extension_dict_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\extension_dict_backend.py", line 9, in <module>
> from telemetry.core.backends.chrome import inspector_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\inspector_backend.py", line 19, in <module>
> from telemetry.core.jsheap import model
> ImportError: No module named jsheap
>
> > Make landmines.py take an extra script via an env var.
> >
> > The extra Python script to run can be specified via env var
> > EXTRA_LANDMINES_SCRIPT.
> >
> > BUG=223636
> >
> > Review URL: https://chromiumcodereview.appspot.com/23604016
>
> TBR=sivachandra@chromium.org
>
> Review URL: https://codereview.chromium.org/23533016
TBR=tkent@chromium.org
Review URL: https://codereview.chromium.org/23532029
git-svn-id: http://src.chromium.org/svn/trunk/src/build@220870 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
2013-09-03 01:51:18 +04:00
|
|
|
'is passed to this script via option -t. Note that an extra '
|
|
|
|
'script can be specified via an env var EXTRA_LANDMINES_SCRIPT.')
|
2015-10-14 22:28:06 +03:00
|
|
|
parser.add_option('-d', '--src-dir',
|
|
|
|
help='Path of the source root dir. Overrides the default location of the '
|
|
|
|
'source root dir when calculating the build directory.')
|
2020-07-08 20:32:10 +03:00
|
|
|
parser.add_option(
|
|
|
|
'-l',
|
|
|
|
'--landmines-path',
|
|
|
|
help='Path to the landmines file to use (defaults to .landmines)')
|
2012-11-15 06:53:03 +04:00
|
|
|
parser.add_option('-v', '--verbose', action='store_true',
|
|
|
|
default=('LANDMINES_VERBOSE' in os.environ),
|
|
|
|
help=('Emit some extra debugging information (default off). This option '
|
|
|
|
'is also enabled by the presence of a LANDMINES_VERBOSE environment '
|
|
|
|
'variable.'))
|
2013-08-21 06:44:58 +04:00
|
|
|
|
2012-11-15 06:53:03 +04:00
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
if args:
|
|
|
|
parser.error('Unknown arguments %s' % args)
|
|
|
|
|
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.DEBUG if options.verbose else logging.ERROR)
|
2012-11-14 08:59:48 +04:00
|
|
|
|
2015-10-14 22:28:06 +03:00
|
|
|
if options.src_dir:
|
|
|
|
if not os.path.isdir(options.src_dir):
|
|
|
|
parser.error('Cannot find source root dir at %s' % options.src_dir)
|
|
|
|
logging.debug('Overriding source root dir. Using: %s', options.src_dir)
|
|
|
|
else:
|
|
|
|
options.src_dir = \
|
|
|
|
os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
|
|
|
|
|
|
|
if not options.landmine_scripts:
|
|
|
|
options.landmine_scripts = [os.path.join(options.src_dir, 'build',
|
|
|
|
'get_landmines.py')]
|
|
|
|
|
Revert 220853 "Revert 220846 "Make landmines.py take an extra sc..."
r220846 was not the root cause of the failure.
> Revert 220846 "Make landmines.py take an extra script via an env..."
>
> It broke telemetry_unittests.
> http://build.chromium.org/p/chromium.win/builders/Win%207%20Tests%20x64%20%283%29/builds/8782/steps/telemetry_unittests/logs/stdio
>
> E:\b\depot_tools\python_bin\python_slave.exe src\tools\telemetry\run_tests --browser=release_x64
> No adb found in $PATH, fallback to checked in binary.
> Traceback (most recent call last):
> File "src\tools\telemetry\run_tests", line 8, in <module>
> from telemetry.unittest import gtest_testrunner
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\__init__.py", line 12, in <module>
> from telemetry.core.browser_options import BrowserFinderOptions
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\browser_options.py", line 12, in <module>
> from telemetry.core import browser_finder
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\browser_finder.py", line 9, in <module>
> from telemetry.core.backends.chrome import android_browser_finder
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\android_browser_finder.py", line 17, in <module>
> from telemetry.core.backends.chrome import android_browser_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\android_browser_backend.py", line 15, in <module>
> from telemetry.core.backends.chrome import chrome_browser_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\chrome_browser_backend.py", line 19, in <module>
> from telemetry.core.backends.chrome import extension_dict_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\extension_dict_backend.py", line 9, in <module>
> from telemetry.core.backends.chrome import inspector_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\inspector_backend.py", line 19, in <module>
> from telemetry.core.jsheap import model
> ImportError: No module named jsheap
>
> > Make landmines.py take an extra script via an env var.
> >
> > The extra Python script to run can be specified via env var
> > EXTRA_LANDMINES_SCRIPT.
> >
> > BUG=223636
> >
> > Review URL: https://chromiumcodereview.appspot.com/23604016
>
> TBR=sivachandra@chromium.org
>
> Review URL: https://codereview.chromium.org/23533016
TBR=tkent@chromium.org
Review URL: https://codereview.chromium.org/23532029
git-svn-id: http://src.chromium.org/svn/trunk/src/build@220870 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
2013-09-03 01:51:18 +04:00
|
|
|
extra_script = os.environ.get('EXTRA_LANDMINES_SCRIPT')
|
|
|
|
if extra_script:
|
2015-10-14 22:28:06 +03:00
|
|
|
options.landmine_scripts += [extra_script]
|
|
|
|
|
|
|
|
return options
|
Revert 220853 "Revert 220846 "Make landmines.py take an extra sc..."
r220846 was not the root cause of the failure.
> Revert 220846 "Make landmines.py take an extra script via an env..."
>
> It broke telemetry_unittests.
> http://build.chromium.org/p/chromium.win/builders/Win%207%20Tests%20x64%20%283%29/builds/8782/steps/telemetry_unittests/logs/stdio
>
> E:\b\depot_tools\python_bin\python_slave.exe src\tools\telemetry\run_tests --browser=release_x64
> No adb found in $PATH, fallback to checked in binary.
> Traceback (most recent call last):
> File "src\tools\telemetry\run_tests", line 8, in <module>
> from telemetry.unittest import gtest_testrunner
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\__init__.py", line 12, in <module>
> from telemetry.core.browser_options import BrowserFinderOptions
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\browser_options.py", line 12, in <module>
> from telemetry.core import browser_finder
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\browser_finder.py", line 9, in <module>
> from telemetry.core.backends.chrome import android_browser_finder
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\android_browser_finder.py", line 17, in <module>
> from telemetry.core.backends.chrome import android_browser_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\android_browser_backend.py", line 15, in <module>
> from telemetry.core.backends.chrome import chrome_browser_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\chrome_browser_backend.py", line 19, in <module>
> from telemetry.core.backends.chrome import extension_dict_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\extension_dict_backend.py", line 9, in <module>
> from telemetry.core.backends.chrome import inspector_backend
> File "E:\b\build\slave\Win_7_Tests_x64__3_\build\src\tools\telemetry\telemetry\core\backends\chrome\inspector_backend.py", line 19, in <module>
> from telemetry.core.jsheap import model
> ImportError: No module named jsheap
>
> > Make landmines.py take an extra script via an env var.
> >
> > The extra Python script to run can be specified via env var
> > EXTRA_LANDMINES_SCRIPT.
> >
> > BUG=223636
> >
> > Review URL: https://chromiumcodereview.appspot.com/23604016
>
> TBR=sivachandra@chromium.org
>
> Review URL: https://codereview.chromium.org/23533016
TBR=tkent@chromium.org
Review URL: https://codereview.chromium.org/23532029
git-svn-id: http://src.chromium.org/svn/trunk/src/build@220870 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
2013-09-03 01:51:18 +04:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2015-10-14 22:28:06 +03:00
|
|
|
options = process_options()
|
2014-02-15 09:23:29 +04:00
|
|
|
|
2014-08-14 18:03:30 +04:00
|
|
|
landmines = []
|
2015-10-14 22:28:06 +03:00
|
|
|
for s in options.landmine_scripts:
|
2019-08-08 22:58:25 +03:00
|
|
|
proc = subprocess.Popen([sys.executable, s], stdout=subprocess.PIPE,
|
|
|
|
universal_newlines=True)
|
2014-08-14 18:03:30 +04:00
|
|
|
output, _ = proc.communicate()
|
|
|
|
landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()])
|
2020-07-08 20:32:10 +03:00
|
|
|
if options.landmines_path:
|
|
|
|
landmines_path = options.landmines_path
|
|
|
|
else:
|
|
|
|
landmines_path = os.path.join(options.src_dir, '.landmines')
|
|
|
|
clobber_if_necessary(landmines, options.src_dir,
|
|
|
|
os.path.normpath(landmines_path))
|
2012-11-14 08:59:48 +04:00
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-11-15 06:53:03 +04:00
|
|
|
sys.exit(main())
|