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, **kwargs): | 36 def does_patch_require_compile(self, exclusions=None, exes=None, **kwargs): |
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': []} |
| 74 |
59 kwargs.setdefault('env', {}) | 75 kwargs.setdefault('env', {}) |
60 kwargs['env'].update(self.m.chromium.c.gyp_env.as_jsonish()) | 76 kwargs['env'].update(self.m.chromium.c.gyp_env.as_jsonish()) |
61 | 77 |
62 step_result = self.m.python('analyze', | 78 step_result = self.m.python('analyze', |
63 self.m.path['checkout'].join('build', 'gyp_chromium'), | 79 self.m.path['checkout'].join('build', 'gyp_chromium'), |
64 ['--analyzer', | 80 args=['--analyzer2', |
65 self.m.raw_io.input(step_result.stdout)], | 81 self.m.json.input(analyze_input), |
66 stdout = self.m.raw_io.output(), | 82 self.m.json.output()], |
67 step_test_data=lambda: | 83 step_test_data=lambda: self.m.json.test_api.output( |
68 self.m.raw_io.test_api.stream_output('No dependency'), | 84 test_output), |
69 **kwargs) | 85 **kwargs) |
70 if step_result.stdout.find('Found dependency') != -1: | 86 if 'error' in step_result.json.output: |
| 87 self._result = True |
| 88 step_result.presentation.step_text = 'Error: ' + \ |
| 89 step_result.json.output['error'] |
| 90 elif step_result.json.output['status'] == 'Found dependency': |
| 91 self._matching_exes = step_result.json.output['targets'] |
71 self._result = True | 92 self._result = True |
72 else: | 93 else: |
73 step_result.presentation.step_text = 'No compile necessary' | 94 step_result.presentation.step_text = 'No compile necessary' |
OLD | NEW |