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 | |
59 step_result = self.m.python('analyze', | 73 step_result = self.m.python('analyze', |
60 self.m.path['checkout'].join('build', 'gyp_chromium'), | 74 self.m.path['checkout'].join('build', 'gyp_chromium'), |
61 ['--analyzer', | 75 args=['--analyzer2', |
62 self.m.raw_io.input(step_result.stdout)], | 76 self.m.json.input(analyze_input)], |
63 stdout = self.m.raw_io.output(), | 77 stdout=self.m.json.output()) |
64 step_test_data=lambda: | 78 if 'error' in step_result.stdout: |
sky
2014/07/30 01:00:26
For the life of me I couldn't get step_test_data t
iannucci
2014/07/30 01:20:36
did you try duplicating the raw_io/test_api.py:str
| |
65 self.m.raw_io.test_api.stream_output('No dependency')) | 79 self._result = True |
66 if step_result.stdout.find('Found dependency') != -1: | 80 step_result.presentation.step_text = 'Error: ' + \ |
81 step_result.stdout['error'] | |
82 elif step_result.stdout['status'] == 'Found dependency': | |
83 self._matching_exes = step_result.stdout['targets'] | |
67 self._result = True | 84 self._result = True |
68 else: | 85 else: |
69 step_result.presentation.step_text = 'No compile necessary' | 86 step_result.presentation.step_text = 'No compile necessary' |
OLD | NEW |