xref: /aosp_15_r20/external/angle/build/toolchain/use_reclient_value.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1#!/usr/bin/env python3
2# Copyright 2024 The Chromium Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""Script to decide use_reclient value.
6
7It is called by rbe.gni via exec_script,
8or used in depot_tools' autoninja or siso wrapper.
9"""
10
11import os
12import sys
13
14sys.path.insert(0, os.path.join(os.path.dirname(__file__)))
15import use_siso_default
16
17# instead of finding depot_tools in PATH,
18# just use pinned third_party/depot_tools.
19sys.path.insert(
20    0,
21    os.path.join(os.path.dirname(__file__), "..", "..", "third_party",
22                 "depot_tools"))
23import gn_helper
24
25
26def _gn_bool(value):
27  if value == "true":
28    return True
29  if value == "false":
30    return False
31  raise Exception("invalid bool value %s" % value)
32
33
34def use_reclient_value(output_dir):
35  """Returns use_reclient value."""
36  use_remoteexec = None
37  use_reclient = None
38  use_siso = use_siso_default.use_siso_default(output_dir)
39  for k, v in gn_helper.args(output_dir):
40    if k == "use_remoteexec":
41      use_remoteexec = _gn_bool(v)
42    if k == "use_reclient":
43      use_reclient = _gn_bool(v)
44    if k == "use_siso":
45      use_siso = _gn_bool(v)
46  # If args.gn has use_reclient, use it.
47  if use_reclient is not None:
48    return use_reclient
49
50  # If .reproxy_tmp dir exists, keep to use reclient.
51  if os.path.exists(os.path.join(output_dir, ".reproxy_tmp")):
52    return True
53
54  if not use_remoteexec:
55    return False
56  # TODO(crbug.com/341167943): Use reclient if use_remoteexec=true and
57  # use_siso=false.
58  return True
59
60
61if __name__ == "__main__":
62  # exec_script runs in output directory.
63  print(str(use_reclient_value(".")).lower())
64