xref: /aosp_15_r20/external/cronet/build/toolchain/get_goma_dir.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2020 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# This script gets default goma_dir for depot_tools goma.
6
7import os
8import sys
9
10
11def main():
12  gomacc = 'gomacc'
13  candidates = []
14  if sys.platform in ['win32', 'cygwin']:
15    gomacc = 'gomacc.exe'
16
17  for path in os.environ.get('PATH', '').split(os.pathsep):
18    # normpath() required to strip trailing slash when present.
19    if os.path.basename(os.path.normpath(path)) == 'depot_tools':
20      candidates.append(os.path.join(path, '.cipd_bin'))
21
22  for d in candidates:
23    if os.path.isfile(os.path.join(d, gomacc)):
24      sys.stdout.write(d)
25      return 0
26  # mb analyze step set use_goma=true, but goma_dir="",
27  # and bot doesn't have goma in default locataion above.
28  # to mitigate this, just use initial depot_tools path
29  # or default path as before (if depot_tools doesn't exist
30  # in PATH).
31  # TODO(ukai): crbug.com/1073276: fix mb analyze step and make it hard error?
32  if sys.platform in ['win32', 'cygwin']:
33    sys.stdout.write('C:\\src\\goma\\goma-win64')
34  elif 'GOMA_DIR' in os.environ:
35    sys.stdout.write(os.environ.get('GOMA_DIR'))
36  else:
37    sys.stdout.write(os.path.join(os.environ.get('HOME', ''), 'goma'))
38  return 0
39
40
41if __name__ == '__main__':
42  sys.exit(main())
43