Commit 87fdd0ac authored by prasadv's avatar prasadv Committed by Commit bot

Parse Git hash for dependency repositories from DEPS file.

BUG=409875
NOTRY=true

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

Cr-Commit-Position: refs/heads/master@{#293351}
parent c01d045b
......@@ -1389,6 +1389,48 @@ class BisectPerformanceMetrics(object):
'v8' in DEPOT_DEPS_NAME[depot]['from'])
return False
def UpdateDepsContents(self, deps_contents, depot, git_revision, deps_key):
"""Returns modified version of DEPS file contents.
Args:
deps_contents: DEPS file content.
depot: Current depot being bisected.
git_revision: A git hash to be updated in DEPS.
deps_key: Key in vars section of DEPS file to be searched.
Returns:
Updated DEPS content as string if deps key is found, otherwise None.
"""
# Check whether the depot and revision pattern in DEPS file vars
# e.g. for webkit the format is "webkit_revision": "12345".
deps_revision = re.compile(r'(?<="%s": ")([0-9]+)(?=")' % deps_key,
re.MULTILINE)
new_data = None
if re.search(deps_revision, deps_contents):
svn_revision = self.source_control.SVNFindRev(
git_revision, self._GetDepotDirectory(depot))
if not svn_revision:
print 'Could not determine SVN revision for %s' % git_revision
return None
# Update the revision information for the given depot
new_data = re.sub(deps_revision, str(svn_revision), deps_contents)
else:
# Check whether the depot and revision pattern in DEPS file vars
# e.g. for webkit the format is "webkit_revision": "559a6d4ab7a84c539..".
deps_revision = re.compile(
r'(?<=["\']%s["\']: ["\'])([a-fA-F0-9]{40})(?=["\'])' % deps_key,
re.MULTILINE)
if re.search(deps_revision, deps_contents):
new_data = re.sub(deps_revision, git_revision, deps_contents)
if new_data:
# For v8_bleeding_edge revisions change V8 branch in order
# to fetch bleeding edge revision.
if depot == 'v8_bleeding_edge':
new_data = _UpdateV8Branch(new_data)
if not new_data:
return None
return new_data
def UpdateDeps(self, revision, depot, deps_file):
"""Updates DEPS file with new revision of dependency repository.
......@@ -1423,28 +1465,11 @@ class BisectPerformanceMetrics(object):
try:
deps_contents = ReadStringFromFile(deps_file)
# Check whether the depot and revision pattern in DEPS file vars
# e.g. for webkit the format is "webkit_revision": "12345".
deps_revision = re.compile(r'(?<="%s": ")([0-9]+)(?=")' % deps_var,
re.MULTILINE)
match = re.search(deps_revision, deps_contents)
if match:
svn_revision = self.source_control.SVNFindRev(
revision, self._GetDepotDirectory(depot))
if not svn_revision:
print 'Could not determine SVN revision for %s' % revision
return False
# Update the revision information for the given depot
new_data = re.sub(deps_revision, str(svn_revision), deps_contents)
# For v8_bleeding_edge revisions change V8 branch in order
# to fetch bleeding edge revision.
if depot == 'v8_bleeding_edge':
new_data = _UpdateV8Branch(new_data)
if not new_data:
return False
# Write changes to DEPS file
WriteStringToFile(new_data, deps_file)
updated_deps_content = self.UpdateDepsContents(
deps_contents, depot, revision, deps_var)
# Write changes to DEPS file
if updated_deps_content:
WriteStringToFile(updated_deps_content, deps_file)
return True
except IOError, e:
print 'Something went wrong while updating DEPS file. [%s]' % e
......@@ -2482,7 +2507,6 @@ class BisectPerformanceMetrics(object):
# should bisect the changes there as well.
external_depot = self._FindNextDepotToBisect(
current_depot, min_revision_data, max_revision_data)
# If there was no change in any of the external depots, the search
# is over.
if not external_depot:
......
......@@ -3,6 +3,7 @@
# found in the LICENSE file.
import os
import re
import unittest
from auto_bisect import source_control as source_control_module
......@@ -10,6 +11,26 @@ from auto_bisect import source_control as source_control_module
# Special import necessary because filename contains dash characters.
bisect_perf_module = __import__('bisect-perf-regression')
def _GetBisectPerformanceMetricsInstance():
"""Returns an instance of the BisectPerformanceMetrics class."""
options_dict = {
'debug_ignore_build': True,
'debug_ignore_sync': True,
'debug_ignore_perf_test': True,
'command': 'fake_command',
'metric': 'fake/metric',
'good_revision': 280000,
'bad_revision': 280005,
}
bisect_options = bisect_perf_module.BisectOptions.FromDict(options_dict)
source_control = source_control_module.DetermineAndCreateSourceControl(
bisect_options)
bisect_instance = bisect_perf_module.BisectPerformanceMetrics(
source_control, bisect_options)
bisect_instance.src_cwd = os.path.abspath(
os.path.join(os.path.dirname(__file__), os.path.pardir))
return bisect_instance
class BisectPerfRegressionTest(unittest.TestCase):
"""Test case for other functions and classes in bisect-perf-regression.py."""
......@@ -227,48 +248,42 @@ class BisectPerfRegressionTest(unittest.TestCase):
This serves as a smoke test to catch errors in the basic execution of the
script.
"""
options_dict = {
'debug_ignore_build': True,
'debug_ignore_sync': True,
'debug_ignore_perf_test': True,
'command': 'fake_command',
'metric': 'fake/metric',
'good_revision': 280000,
'bad_revision': 280005,
}
bisect_options = bisect_perf_module.BisectOptions.FromDict(options_dict)
source_control = source_control_module.DetermineAndCreateSourceControl(
bisect_options)
bisect_instance = bisect_perf_module.BisectPerformanceMetrics(
source_control, bisect_options)
bisect_instance.src_cwd = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..'))
results = bisect_instance.Run(bisect_options.command,
bisect_options.bad_revision,
bisect_options.good_revision,
bisect_options.metric)
bisect_instance = _GetBisectPerformanceMetricsInstance()
results = bisect_instance.Run(bisect_instance.opts.command,
bisect_instance.opts.bad_revision,
bisect_instance.opts.good_revision,
bisect_instance.opts.metric)
bisect_instance.FormatAndPrintResults(results)
def testSVNFindRev(self):
"""Determine numerical SVN revision or Commit Position."""
options_dict = {
'debug_ignore_build': True,
'debug_ignore_sync': True,
'debug_ignore_perf_test': True,
'command': 'fake_command',
'metric': 'fake/metric',
'good_revision': 280000,
'bad_revision': 280005,
}
bisect_options = bisect_perf_module.BisectOptions.FromDict(options_dict)
source_control = source_control_module.DetermineAndCreateSourceControl(
bisect_options)
bisect_instance = _GetBisectPerformanceMetricsInstance()
cp_git_rev = '7017a81991de983e12ab50dfc071c70e06979531'
self.assertEqual(291765, source_control.SVNFindRev(cp_git_rev))
self.assertEqual(291765,
bisect_instance.source_control.SVNFindRev(cp_git_rev))
svn_git_rev = 'e6db23a037cad47299a94b155b95eebd1ee61a58'
self.assertEqual(291467, source_control.SVNFindRev(svn_git_rev))
self.assertEqual(291467,
bisect_instance.source_control.SVNFindRev(svn_git_rev))
def testUpdateDepsContent(self):
bisect_instance = _GetBisectPerformanceMetricsInstance()
deps_file = 'DEPS'
# We are intentionally reading DEPS file contents instead of string literal
# with few lines from DEPS because to check if the format we are expecting
# to search is not changed in DEPS content.
# TODO (prasadv): Add a separate test to validate the DEPS contents with the
# format that bisect script expects.
deps_contents = bisect_perf_module.ReadStringFromFile(deps_file)
deps_key = 'v8_revision'
depot = 'v8'
git_revision = 'a12345789a23456789a123456789a123456789'
updated_content = bisect_instance.UpdateDepsContents(
deps_contents, depot, git_revision, deps_key)
self.assertIsNotNone(updated_content)
ss = re.compile('["\']%s["\']: ["\']%s["\']' % (deps_key, git_revision))
self.assertIsNotNone(re.search(ss, updated_content))
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment