Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import re | 5 import re |
| 6 | 6 |
| 7 from slave import recipe_api | 7 from slave import recipe_api |
| 8 | 8 |
| 9 class FilterApi(recipe_api.RecipeApi): | 9 class FilterApi(recipe_api.RecipeApi): |
| 10 def __init__(self, **kwargs): | 10 def __init__(self, **kwargs): |
| 11 super(FilterApi, self).__init__(**kwargs) | 11 super(FilterApi, self).__init__(**kwargs) |
| 12 self._result = False | 12 self._result = False |
| 13 self._matching_exes = [] | |
| 13 | 14 |
| 14 def __is_path_in_exclusion_list(self, path, exclusions): | 15 def __is_path_in_exclusion_list(self, path, exclusions): |
| 15 """Returns true if |path| matches any of the regular expressions in | 16 """Returns true if |path| matches any of the regular expressions in |
| 16 |exclusions|.""" | 17 |exclusions|.""" |
| 17 for regex in exclusions: | 18 for regex in exclusions: |
| 18 match = regex.match(path) | 19 match = regex.match(path) |
| 19 if match and match.end() == len(path): | 20 if match and match.end() == len(path): |
| 20 return regex.pattern | 21 return regex.pattern |
| 21 return False | 22 return False |
| 22 | 23 |
| 23 @property | 24 @property |
| 24 def result(self): | 25 def result(self): |
| 25 """Returns the result from most recent call to | 26 """Returns the result from most recent call to |
| 26 does_patch_require_compile.""" | 27 does_patch_require_compile.""" |
| 27 return self._result | 28 return self._result |
| 28 | 29 |
| 30 @property | |
| 31 def matching_exes(self): | |
| 32 """Returns the set of exes passed to does_patch_require_compile() that | |
| 33 are effected by the set of files that have changed.""" | |
| 34 return self._matching_exes | |
| 29 | 35 |
| 30 def does_patch_require_compile(self, exclusions=None): | 36 def does_patch_require_compile(self, exclusions=None, exes=None): |
| 31 """Return true if the current patch requires a build (and tests to run). | 37 """Return true if the current patch requires a build (and exes to run). |
| 32 Return value can be accessed by call to result(). | 38 Return value can be accessed by call to result(). |
| 33 | 39 |
| 34 Args: | 40 Args: |
| 35 exclusions: list of python regular expressions (as strings). If any of | 41 exclusions: list of python regular expressions (as strings). If any of |
| 36 the files in the current patch match one of the values in |exclusions| | 42 the files in the current patch match one of the values in |exclusions| |
| 37 True is returned.""" | 43 True is returned (by way of result()). |
| 44 exes: the possible set of executables that are desired to run. When done | |
| 45 matching_exes() returns the set of exes that are effected by the files | |
| 46 that have changed.""" | |
| 38 | 47 |
| 39 exclusions = exclusions or self.m.properties.get('filter_exclusions', []) | 48 exclusions = exclusions or self.m.properties.get('filter_exclusions', []) |
| 49 self._matching_exes = exes or self.m.properties.get('matching_exes', []) | |
| 40 | 50 |
| 41 # Get the set of files in the current patch. | 51 # Get the set of files in the current patch. |
| 42 step_result = self.m.git('diff', '--cached', '--name-only', | 52 step_result = self.m.git('diff', '--cached', '--name-only', |
| 43 name='git diff to analyze patch', | 53 name='git diff to analyze patch', |
| 44 stdout=self.m.raw_io.output(), | 54 stdout=self.m.raw_io.output(), |
| 45 step_test_data=lambda: | 55 step_test_data=lambda: |
| 46 self.m.raw_io.test_api.stream_output('foo.cc')) | 56 self.m.raw_io.test_api.stream_output('foo.cc')) |
| 47 | 57 |
| 48 # Check the path of each file against the exclusion list. If found, no need | 58 # Check the path of each file against the exclusion list. If found, no need |
| 49 # to check dependencies. | 59 # to check dependencies. |
| 50 exclusion_regexs = [re.compile(exclusion) for exclusion in exclusions] | 60 exclusion_regexs = [re.compile(exclusion) for exclusion in exclusions] |
| 61 paths = [] | |
| 51 for path in step_result.stdout.split(): | 62 for path in step_result.stdout.split(): |
| 63 paths.append(path) | |
| 52 first_match = self.__is_path_in_exclusion_list(path, exclusion_regexs) | 64 first_match = self.__is_path_in_exclusion_list(path, exclusion_regexs) |
| 53 if first_match: | 65 if first_match: |
| 54 step_result.presentation.logs.setdefault('excluded_files', []).append( | 66 step_result.presentation.logs.setdefault('excluded_files', []).append( |
| 55 '%s (regex = \'%s\')' % (path, first_match)) | 67 '%s (regex = \'%s\')' % (path, first_match)) |
| 56 self._result = 1 | 68 self._result = 1 |
| 57 return | 69 return |
| 58 | 70 |
| 71 analyze_input = {'files': paths, 'targets': self._matching_exes} | |
| 72 | |
| 73 test_output = {'status': 'No dependency', 'targets': []} | |
|
iannucci
2014/08/05 18:59:24
I'd inline this
| |
| 74 | |
| 59 step_result = self.m.python('analyze', | 75 step_result = self.m.python('analyze', |
| 60 self.m.path['checkout'].join('build', 'gyp_chromium'), | 76 self.m.path['checkout'].join('build', 'gyp_chromium'), |
| 61 ['--analyzer', | 77 args=['--analyzer2', |
| 62 self.m.raw_io.input(step_result.stdout)], | 78 self.m.json.input(analyze_input), |
| 63 stdout = self.m.raw_io.output(), | 79 self.m.json.output()], |
| 64 step_test_data=lambda: | 80 step_test_data=lambda: self.m.json.test_api.output( |
| 65 self.m.raw_io.test_api.stream_output('No dependency')) | 81 test_output)) |
| 66 if step_result.stdout.find('Found dependency') != -1: | 82 if 'error' in step_result.json.output: |
| 83 self._result = True | |
| 84 step_result.presentation.step_text = 'Error: ' + \ | |
| 85 step_result.json.output['error'] | |
| 86 elif step_result.json.output['status'] == 'Found dependency': | |
| 87 self._matching_exes = step_result.json.output['targets'] | |
| 67 self._result = True | 88 self._result = True |
| 68 else: | 89 else: |
| 69 step_result.presentation.step_text = 'No compile necessary' | 90 step_result.presentation.step_text = 'No compile necessary' |
| OLD | NEW |