@@ -199,9 +199,35 @@ def get_target_cpu(args):
199199 return 'x64'
200200
201201
202+ def buildtools_dir():
203+ host_os = get_host_os()
204+ host_cpu = get_host_cpu()
205+ if host_os == 'win':
206+ host_os = 'windows'
207+ if host_os == 'mac' and host_cpu == 'arm64':
208+ host_cpu = 'x64'
209+ return '%s-%s' % (host_os, host_cpu)
210+
211+
212+ def goma_ensure_start(goma_dir):
213+ goma_ctl_path = os.path.join(goma_dir, 'goma_ctl.py')
214+ command = ['python3', goma_ctl_path, 'ensure_start']
215+ try:
216+ output = subprocess.check_output(command, stderr=subprocess.STDOUT)
217+ print(output)
218+ except subprocess.CalledProcessError:
219+ print(
220+ 'Failed to start goma:\n%s\nEnsure it is started by manually running:\n'
221+ '$ %s\n' % (output.decode('utf-8'), ' '.join(command))
222+ )
223+
224+
202225def setup_goma(args):
203226 goma_gn_args = {}
204227
228+ # Prefer the goma fetched by gclient.
229+ cipd_goma_dir = os.path.join(SRC_ROOT, 'buildtools', buildtools_dir(), 'goma')
230+
205231 goma_dir = os.environ.get('GOMA_DIR')
206232 goma_home_dir = os.path.join(os.getenv('HOME', ''), 'goma')
207233
@@ -214,6 +240,9 @@ def setup_goma(args):
214240 goma_gn_args['use_goma'] = False
215241 goma_gn_args['goma_dir'] = None
216242 print('Disabling GOMA for wasm builds, it is not supported yet.')
243+ elif args.goma and os.path.exists(cipd_goma_dir):
244+ goma_gn_args['use_goma'] = True
245+ goma_gn_args['goma_dir'] = cipd_goma_dir
217246 elif args.goma and goma_dir and os.path.exists(goma_dir):
218247 goma_gn_args['use_goma'] = True
219248 goma_gn_args['goma_dir'] = goma_dir
@@ -237,6 +266,9 @@ def setup_goma(args):
237266 os.getenv('FLUTTER_GOMA_CREATE_XCODE_SYMLINKS', '0') == '1'):
238267 goma_gn_args['create_xcode_symlinks'] = True
239268
269+ if goma_gn_args['use_goma'] and args.goma_ensure_start:
270+ goma_ensure_start(goma_gn_args['goma_dir'])
271+
240272 return goma_gn_args
241273
242274
@@ -1070,6 +1102,19 @@ def parse_args(args):
10701102 help='Do not run GN. Instead configure the Impeller cmake example build.',
10711103 )
10721104
1105+ parser.add_argument(
1106+ '--goma-ensure-start',
1107+ default=True,
1108+ action='store_true',
1109+ help='Ensure that the goma compiler proxy is running.',
1110+ )
1111+ parser.add_argument(
1112+ '--no-goma-ensure-start',
1113+ dest='goma_ensure_start',
1114+ action='store_false',
1115+ help='Do not ensure that the goma compiler proxy is running.',
1116+ )
1117+
10731118 # Sanitizers.
10741119 parser.add_argument('--asan', default=False, action='store_true')
10751120 parser.add_argument('--lsan', default=False, action='store_true')
0 commit comments