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._env = {} | |
Yoshisato Yanagisawa
2016/08/09 04:01:49
might be better to say goma_ctl_env or so?
tikuta
2016/08/09 05:30:39
Done.
| |
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 |
44 def start(self, env=None, **kwargs): | 56 @property |
57 def goma_ctl(self): | |
58 return self.m.path.join(self._goma_dir, 'goma_ctl.py') | |
59 | |
60 def start(self, build_data_dir, env=None, **kwargs): | |
Yoshisato Yanagisawa
2016/08/09 04:01:49
might be better to make build_data_dir optional?
o
tikuta
2016/08/09 05:30:40
Done.
| |
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: | 68 |
53 env = {} | 69 self._build_data_dir = build_data_dir |
54 env.update({'GOMA_SERVICE_ACCOUNT_JSON_FILE': self.service_account_json_path }) | 70 self._env['GOMA_DUMP_STATS_FILE'] = ( |
71 self.m.path.join(build_data_dir, 'goma_stats_proto')) | |
72 self._env['GOMACTL_CRASH_REPORT_ID_FILE'] = ( | |
73 self.m.path.join(build_data_dir, 'crash_report_id_file')) | |
74 | |
75 self._env['GOMA_SERVICE_ACCOUNT_JSON_FILE'] = self.service_account_json_path | |
76 | |
77 if env: | |
78 self._env.update(env) | |
79 | |
55 self.m.python( | 80 self.m.python( |
56 name='start_goma', | 81 name='start_goma', |
57 script=self.m.path.join(self._goma_dir, 'goma_ctl.py'), | 82 script=self.goma_ctl, |
58 args=['restart'], env=env, **kwargs) | 83 args=['restart'], env=self._env, **kwargs) |
Yoshisato Yanagisawa
2016/08/09 04:01:49
can you upload stats on goma_start failure?
tikuta
2016/08/09 05:30:39
Done.
| |
59 self._goma_started = True | 84 self._goma_started = True |
60 | 85 |
61 def stop(self, goma_dir=None, **kwargs): | 86 def stop(self, **kwargs): |
62 """Stop goma compiler_proxy. | 87 """Stop goma compiler_proxy. |
63 | 88 |
64 A user MUST execute start beforehand. | 89 A user MUST execute start beforehand. |
65 It is user's responsibility to handle failure of stopping compiler_proxy. | 90 It is user's responsibility to handle failure of stopping compiler_proxy. |
66 """ | 91 """ |
67 assert self._goma_dir | 92 assert self._goma_dir |
68 assert self._goma_started | 93 assert self._goma_started |
69 self.m.python( | 94 self.m.python( |
70 name='stop_goma', | 95 name='stop_goma', |
71 script=self.m.path.join(self._goma_dir, 'goma_ctl.py'), | 96 script=self.goma_ctl, |
72 args=['stop'], **kwargs) | 97 args=['stop'], env=self._env, **kwargs) |
73 self._goma_started = False | 98 self._goma_started = False |
Yoshisato Yanagisawa
2016/08/09 04:01:49
should clear self._goma_ctl_env?
tikuta
2016/08/09 05:30:39
Done.
| |
99 self.upload_logs() | |
100 | |
101 def upload_logs(self): | |
102 args = [ | |
103 '--upload-compiler-proxy-info' | |
104 ] | |
105 | |
106 if self._ninja_log_outdir: | |
107 args.extend([ | |
108 '--ninja-log-outdir', self._ninja_log_outdir, | |
109 '--ninja-log-compiler', self._ninja_log_compiler, | |
110 '--ninja-log-command', self._ninja_log_command, | |
111 '--ninja-log-exit-status', self._ninja_log_exit_status, | |
112 ]) | |
113 | |
114 args.extend([ | |
115 '--goma-stats-file', self._env['GOMA_DUMP_STATS_FILE'], | |
116 '--goma-crash-report-id-file', | |
117 self._env['GOMACTL_CRASH_REPORT_ID_FILE'], | |
118 '--build-data-dir', self._build_data_dir, | |
119 ]) | |
120 | |
121 self.m.python( | |
122 name='upload_log', | |
123 script='upload_goma_logs.py', | |
124 args=args | |
125 ) | |
OLD | NEW |