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 import os |
| 6 |
5 from recipe_engine import recipe_api | 7 from recipe_engine import recipe_api |
6 | 8 |
7 class GomaApi(recipe_api.RecipeApi): | 9 class GomaApi(recipe_api.RecipeApi): |
8 """GomaApi contains helper functions for using goma.""" | 10 """GomaApi contains helper functions for using goma.""" |
9 | 11 |
10 def __init__(self, **kwargs): | 12 def __init__(self, **kwargs): |
11 super(GomaApi, self).__init__(**kwargs) | 13 super(GomaApi, self).__init__(**kwargs) |
12 self._goma_dir = None | 14 self._goma_dir = None |
13 self._goma_started = False | 15 self._goma_started = False |
14 | 16 |
| 17 self._goma_ctl_env_init() |
| 18 |
| 19 def _goma_ctl_env_init(self): |
15 self._goma_ctl_env = {} | 20 self._goma_ctl_env = {} |
16 | 21 |
| 22 # Inherit some env vars used in goma_utils.SendGomaTsMon. |
| 23 for key in ['BUILDBOT_BUILDERNAME', |
| 24 'BUILDBOT_MASTERNAME', |
| 25 'BUILDBOT_SLAVENAME', |
| 26 'BUILDBOT_CLOBBER', |
| 27 'TEST_TMPDIR', |
| 28 'TMPDIR', |
| 29 'TMP', |
| 30 ]: |
| 31 if key in os.environ: # pragma: no cover |
| 32 self._goma_ctl_env[key] = os.environ[key] |
| 33 |
17 @property | 34 @property |
18 def service_account_json_path(self): | 35 def service_account_json_path(self): |
19 if self.m.platform.is_win: | 36 if self.m.platform.is_win: |
20 return 'C:\\creds\\service_accounts\\service-account-goma-client.json' | 37 return 'C:\\creds\\service_accounts\\service-account-goma-client.json' |
21 return '/creds/service_accounts/service-account-goma-client.json' | 38 return '/creds/service_accounts/service-account-goma-client.json' |
22 | 39 |
23 def ensure_goma(self, canary=False): | 40 def ensure_goma(self, canary=False): |
24 with self.m.step.nest('ensure_goma'): | 41 with self.m.step.nest('ensure_goma'): |
25 with self.m.step.context({'infra_step': True}): | 42 with self.m.step.context({'infra_step': True}): |
26 try: | 43 try: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 79 |
63 if self.build_data_dir: | 80 if self.build_data_dir: |
64 self._goma_ctl_env['GOMA_DUMP_STATS_FILE'] = ( | 81 self._goma_ctl_env['GOMA_DUMP_STATS_FILE'] = ( |
65 self.m.path.join(self.build_data_dir, 'goma_stats_proto')) | 82 self.m.path.join(self.build_data_dir, 'goma_stats_proto')) |
66 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'] = ( | 83 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'] = ( |
67 self.m.path.join(self.build_data_dir, 'crash_report_id_file')) | 84 self.m.path.join(self.build_data_dir, 'crash_report_id_file')) |
68 | 85 |
69 self._goma_ctl_env['GOMA_SERVICE_ACCOUNT_JSON_FILE'] = ( | 86 self._goma_ctl_env['GOMA_SERVICE_ACCOUNT_JSON_FILE'] = ( |
70 self.service_account_json_path) | 87 self.service_account_json_path) |
71 | 88 |
| 89 # GLOG_log_dir should not be set. |
| 90 assert env is None or 'GLOG_log_dir' not in env |
| 91 |
72 goma_ctl_start_env = self._goma_ctl_env.copy() | 92 goma_ctl_start_env = self._goma_ctl_env.copy() |
73 | 93 |
74 if env is not None: | 94 if env is not None: |
75 goma_ctl_start_env.update(env) | 95 goma_ctl_start_env.update(env) |
76 | 96 |
77 try: | 97 try: |
78 self.m.python( | 98 self.m.python( |
79 name='start_goma', | 99 name='start_goma', |
80 script=self.goma_ctl, | 100 script=self.goma_ctl, |
81 args=['restart'], env=goma_ctl_start_env, infra_step=True, **kwargs) | 101 args=['restart'], env=goma_ctl_start_env, infra_step=True, **kwargs) |
(...skipping 23 matching lines...) Expand all Loading... |
105 assert self._goma_started | 125 assert self._goma_started |
106 self.m.python( | 126 self.m.python( |
107 name='stop_goma', | 127 name='stop_goma', |
108 script=self.goma_ctl, | 128 script=self.goma_ctl, |
109 args=['stop'], env=self._goma_ctl_env, **kwargs) | 129 args=['stop'], env=self._goma_ctl_env, **kwargs) |
110 | 130 |
111 self.upload_logs(ninja_log_outdir, ninja_log_compiler, ninja_log_command, | 131 self.upload_logs(ninja_log_outdir, ninja_log_compiler, ninja_log_command, |
112 ninja_log_exit_status) | 132 ninja_log_exit_status) |
113 | 133 |
114 self._goma_started = False | 134 self._goma_started = False |
115 self._goma_ctl_env = {} | 135 self._goma_ctl_env_init() |
| 136 |
116 | 137 |
117 def upload_logs(self, ninja_log_outdir=None, ninja_log_compiler=None, | 138 def upload_logs(self, ninja_log_outdir=None, ninja_log_compiler=None, |
118 ninja_log_command=None, ninja_log_exit_status=None, | 139 ninja_log_command=None, ninja_log_exit_status=None, |
119 name=None): | 140 name=None): |
120 args = [ | 141 args = [ |
121 '--upload-compiler-proxy-info' | 142 '--upload-compiler-proxy-info' |
122 ] | 143 ] |
123 | 144 |
124 if ninja_log_outdir: | 145 if ninja_log_outdir: |
125 assert ninja_log_compiler is not None | 146 assert ninja_log_compiler is not None |
(...skipping 12 matching lines...) Expand all Loading... |
138 '--goma-stats-file', self._goma_ctl_env['GOMA_DUMP_STATS_FILE'], | 159 '--goma-stats-file', self._goma_ctl_env['GOMA_DUMP_STATS_FILE'], |
139 '--goma-crash-report-id-file', | 160 '--goma-crash-report-id-file', |
140 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'], | 161 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'], |
141 '--build-data-dir', self.build_data_dir, | 162 '--build-data-dir', self.build_data_dir, |
142 ]) | 163 ]) |
143 | 164 |
144 self.m.python( | 165 self.m.python( |
145 name=name or 'upload_log', | 166 name=name or 'upload_log', |
146 script=self.package_repo_resource( | 167 script=self.package_repo_resource( |
147 'scripts', 'slave', 'upload_goma_logs.py'), | 168 'scripts', 'slave', 'upload_goma_logs.py'), |
148 args=args | 169 args=args, |
| 170 env=self._goma_ctl_env |
149 ) | 171 ) |
OLD | NEW |