1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63

build / toolchain / use_reclient_value.py [blame]

#!/usr/bin/env python3
# Copyright 2024 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Script to decide use_reclient value.

It is called by rbe.gni via exec_script,
or used in depot_tools' autoninja or siso wrapper.
"""

import os
import sys

sys.path.insert(0, os.path.join(os.path.dirname(__file__)))
import use_siso_default

# instead of finding depot_tools in PATH,
# just use pinned third_party/depot_tools.
sys.path.insert(
    0,
    os.path.join(os.path.dirname(__file__), "..", "..", "third_party",
                 "depot_tools"))
import gn_helper


def _gn_bool(value):
  if value == "true":
    return True
  if value == "false":
    return False
  raise Exception("invalid bool value %s" % value)


def use_reclient_value(output_dir):
  """Returns use_reclient value."""
  use_remoteexec = None
  use_reclient = None
  use_siso = use_siso_default.use_siso_default(output_dir)
  for k, v in gn_helper.args(output_dir):
    if k == "use_remoteexec":
      use_remoteexec = _gn_bool(v)
    if k == "use_reclient":
      use_reclient = _gn_bool(v)
    if k == "use_siso":
      use_siso = _gn_bool(v)
  # If args.gn has use_reclient, use it.
  if use_reclient is not None:
    return use_reclient

  # If .reproxy_tmp dir exists, keep to use reclient.
  if os.path.exists(os.path.join(output_dir, ".reproxy_tmp")):
    return True

  if not use_remoteexec:
    return False
  # TODO(crbug.com/341167943): Use reclient if use_remoteexec=true and
  # use_siso=false.
  return True


if __name__ == "__main__":
  # exec_script runs in output directory.
  print(str(use_reclient_value(".")).lower())