OLD | NEW |
---|---|
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 from recipe_engine import recipe_api | 5 from recipe_engine import recipe_api |
6 | 6 |
7 class GomaApi(recipe_api.RecipeApi): | 7 class GomaApi(recipe_api.RecipeApi): |
8 """GomaApi contains helper functions for using goma.""" | 8 """GomaApi contains helper functions for using goma.""" |
9 | 9 |
10 def __init__(self, **kwargs): | 10 def __init__(self, **kwargs): |
11 super(GomaApi, self).__init__(**kwargs) | 11 super(GomaApi, self).__init__(**kwargs) |
12 self._goma_dir = None | 12 self._goma_dir = None |
13 self._goma_started = False | 13 self._goma_started = False |
14 | 14 |
15 self._goma_ctl_env = {} | |
16 | |
17 # options for upload_goma_logs.py | |
18 # TODO(tikuta) set these variables | |
19 self._ninja_log_outdir = None | |
20 self._ninja_log_compiler = None | |
21 self._ninja_log_command = None | |
22 self._ninja_log_exit_status = None | |
23 | |
24 self._build_data_dir = None | |
25 | |
26 | |
15 @property | 27 @property |
16 def service_account_json_path(self): | 28 def service_account_json_path(self): |
17 if self.m.platform.is_win: | 29 if self.m.platform.is_win: |
18 return 'C:\\creds\\service_accounts\\service-account-goma-client.json' | 30 return 'C:\\creds\\service_accounts\\service-account-goma-client.json' |
19 return '/creds/service_accounts/service-account-goma-client.json' | 31 return '/creds/service_accounts/service-account-goma-client.json' |
20 | 32 |
21 def ensure_goma(self, canary=False): | 33 def ensure_goma(self, canary=False): |
22 with self.m.step.nest('ensure_goma'): | 34 with self.m.step.nest('ensure_goma'): |
23 with self.m.step.context({'infra_step': True}): | 35 with self.m.step.context({'infra_step': True}): |
24 try: | 36 try: |
25 self.m.cipd.set_service_account_credentials( | 37 self.m.cipd.set_service_account_credentials( |
26 self.service_account_json_path) | 38 self.service_account_json_path) |
27 | 39 |
28 self.m.cipd.install_client() | 40 self.m.cipd.install_client() |
29 goma_package = ('infra_internal/goma/client/%s' % | 41 goma_package = ('infra_internal/goma/client/%s' % |
30 self.m.cipd.platform_suffix()) | 42 self.m.cipd.platform_suffix()) |
31 # For Windows there's only 64-bit goma client. | 43 # For Windows there's only 64-bit goma client. |
32 if self.m.platform.is_win: | 44 if self.m.platform.is_win: |
33 goma_package = goma_package.replace('386', 'amd64') | 45 goma_package = goma_package.replace('386', 'amd64') |
34 ref='release' | 46 ref='release' |
35 if canary: | 47 if canary: |
36 ref='candidate' | 48 ref='candidate' |
37 self._goma_dir = self.m.path['cache'].join('cipd', 'goma') | 49 self._goma_dir = self.m.path['cache'].join('cipd', 'goma') |
38 self.m.cipd.ensure(self._goma_dir, {goma_package: ref}) | 50 self.m.cipd.ensure(self._goma_dir, {goma_package: ref}) |
39 return self._goma_dir | 51 return self._goma_dir |
40 except self.m.step.StepFailure: | 52 except self.m.step.StepFailure: |
41 # TODO(phajdan.jr): make failures fatal after experiment. | 53 # TODO(phajdan.jr): make failures fatal after experiment. |
42 return None | 54 return None |
43 | 55 |
56 @property | |
57 def goma_ctl(self): | |
58 return self.m.path.join(self._goma_dir, 'goma_ctl.py') | |
59 | |
44 def start(self, env=None, **kwargs): | 60 def start(self, env=None, **kwargs): |
45 """Start goma compiler_proxy. | 61 """Start goma compiler_proxy. |
46 | 62 |
47 A user MUST execute ensure_goma beforehand. | 63 A user MUST execute ensure_goma beforehand. |
48 It is user's responsibility to handle failure of starting compiler_proxy. | 64 It is user's responsibility to handle failure of starting compiler_proxy. |
49 """ | 65 """ |
50 assert self._goma_dir | 66 assert self._goma_dir |
51 assert not self._goma_started | 67 assert not self._goma_started |
52 if not env: | |
53 env = {} | |
54 env.update({'GOMA_SERVICE_ACCOUNT_JSON_FILE': self.service_account_json_path }) | |
55 self.m.python( | |
56 name='start_goma', | |
57 script=self.m.path.join(self._goma_dir, 'goma_ctl.py'), | |
58 args=['restart'], env=env, **kwargs) | |
59 self._goma_started = True | |
60 | 68 |
61 def stop(self, goma_dir=None, **kwargs): | 69 if self.m.properties.get('build_data_dir'): |
70 self._build_data_dir = self.m.properties.get('build_data_dir') | |
71 self._goma_ctl_env['GOMA_DUMP_STATS_FILE'] = ( | |
72 self.m.path.join(self._build_data_dir, 'goma_stats_proto')) | |
73 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'] = ( | |
74 self.m.path.join(self._build_data_dir, 'crash_report_id_file')) | |
75 | |
76 self._goma_ctl_env['GOMA_SERVICE_ACCOUNT_JSON_FILE'] = ( | |
77 self.service_account_json_path) | |
78 | |
79 if env: | |
80 self._goma_ctl_env.update(env) | |
81 | |
82 try: | |
83 self.m.python( | |
84 name='start_goma', | |
85 script=self.goma_ctl, | |
86 args=['restart'], env=self._goma_ctl_env, **kwargs) | |
87 self._goma_started = True | |
88 except self.m.step.StepFailure as e: | |
89 self.m.python( | |
ukai
2016/08/09 05:47:18
if stop failed, will it raise InfraFailure? (or St
tikuta
2016/08/09 06:02:47
Done.
| |
90 name='stop_goma (start failure)', | |
91 script=self.goma_ctl, | |
92 args=['stop'], env=self._goma_ctl_env, **kwargs) | |
93 self.upload_logs('upload_goma_start_failed_logs') | |
94 | |
95 raise self.m.step.InfraFailure('Infra goma start failure: %s' % e) | |
96 | |
97 def stop(self, **kwargs): | |
62 """Stop goma compiler_proxy. | 98 """Stop goma compiler_proxy. |
63 | 99 |
64 A user MUST execute start beforehand. | 100 A user MUST execute start beforehand. |
65 It is user's responsibility to handle failure of stopping compiler_proxy. | 101 It is user's responsibility to handle failure of stopping compiler_proxy. |
66 """ | 102 """ |
67 assert self._goma_dir | 103 assert self._goma_dir |
68 assert self._goma_started | 104 assert self._goma_started |
69 self.m.python( | 105 self.m.python( |
70 name='stop_goma', | 106 name='stop_goma', |
71 script=self.m.path.join(self._goma_dir, 'goma_ctl.py'), | 107 script=self.goma_ctl, |
72 args=['stop'], **kwargs) | 108 args=['stop'], env=self._goma_ctl_env, **kwargs) |
109 | |
110 self.upload_logs() | |
111 | |
73 self._goma_started = False | 112 self._goma_started = False |
113 self._goma_ctl_env = {} | |
114 | |
115 | |
116 def upload_logs(self, name=None): | |
117 args = [ | |
118 '--upload-compiler-proxy-info' | |
119 ] | |
120 | |
121 if self._ninja_log_outdir: | |
122 args.extend([ | |
123 '--ninja-log-outdir', self._ninja_log_outdir, | |
124 '--ninja-log-compiler', self._ninja_log_compiler, | |
125 '--ninja-log-command', self._ninja_log_command, | |
126 '--ninja-log-exit-status', self._ninja_log_exit_status, | |
127 ]) | |
128 | |
129 if self._build_data_dir: | |
130 args.extend([ | |
131 '--goma-stats-file', self._goma_ctl_env['GOMA_DUMP_STATS_FILE'], | |
132 '--goma-crash-report-id-file', | |
133 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'], | |
134 '--build-data-dir', self._build_data_dir, | |
135 ]) | |
136 | |
137 self.m.python( | |
138 name=name or 'upload_log', | |
139 script=self.package_repo_resource('scripts', 'slave', 'upload_goma_logs.py '), | |
140 args=args | |
141 ) | |
OLD | NEW |