code: def build(build_python, build_java, build_cpp):
      if tuple(sys.version_info[:2]) not in SUPPORTED_PYTHONS:
          msg = (
              "Detected Python version {}, which is not supported. "
              "Only Python {} are supported."
          ).format(
              ".".join(map(str, sys.version_info[:2])),
              ", ".join(
                  ".".join(map(str, v)) for v in SUPPORTED_PYTHONS
              ),
          )
          raise RuntimeError(msg)
  
      if is_invalid_windows_platform():
          msg = (
              "Please use official native CPython on Windows,"
              " not Cygwin/MSYS/MSYS2/MinGW/etc.\n"
              + "Detected: {}\n  at: {!r}".format(
                  sys.version, sys.executable
              )
          )
          raise OSError(msg)
  
      bazel_env = dict(os.environ, PYTHON3_BIN_PATH=sys.executable)
  
      if is_native_windows_or_msys():
          SHELL = bazel_env.get("SHELL")
          if SHELL:
              bazel_env.setdefault("BAZEL_SH", os.path.normpath(SHELL))
          BAZEL_SH = bazel_env.get("BAZEL_SH", "")
          SYSTEMROOT = os.getenv("SystemRoot")
          wsl_bash = os.path.join(SYSTEMROOT, "System32", "bash.exe")
          if (not BAZEL_SH) and SYSTEMROOT and os.path.isfile(wsl_bash):
              msg = (
                  "You appear to have Bash from WSL,"
                  " which Bazel may invoke unexpectedly. "
                  "To avoid potential problems,"
                  " please explicitly set the {name!r}"
                  " environment variable for Bazel."
              ).format(name="BAZEL_SH")
              raise RuntimeError(msg)
  
      # Note: We are passing in sys.executable so that we use the same
      # version of Python to build packages inside the build.sh script. Note
      # that certain flags will not be passed along such as --user or sudo.
      # TODO(rkn): Fix this.
      if not os.getenv("SKIP_THIRDPARTY_INSTALL"):
          pip_packages = ["psutil", "setproctitle==1.2.2", "colorama"]
          subprocess.check_call(
              [
                  sys.executable,
                  "-m",
                  "pip",
                  "install",
                  "-q",
                  "--target="
                  + os.path.join(ROOT_DIR, THIRDPARTY_SUBDIR),
              ]
              + pip_packages,
              env=dict(os.environ, CC="gcc"),
          )
  
      # runtime env agent dependenceis
      runtime_env_agent_pip_packages = ["aiohttp"]
      subprocess.check_call(
          [
              sys.executable,
              "-m",
              "pip",
              "install",
              "-q",
              "--target="
              + os.path.join(
                  ROOT_DIR, RUNTIME_ENV_AGENT_THIRDPARTY_SUBDIR
              ),
          ]
          + runtime_env_agent_pip_packages
      )
  
      bazel_flags = ["--verbose_failures"]
      if BAZEL_ARGS:
          bazel_flags.extend(shlex.split(BAZEL_ARGS))
  
      if BAZEL_LIMIT_CPUS:
          n = int(BAZEL_LIMIT_CPUS)  # the value must be an int
          bazel_flags.append(f"--local_cpu_resources={n}")
          warnings.warn(
              "Setting BAZEL_LIMIT_CPUS is deprecated and will be removed in a future"
              " version. Please use BAZEL_ARGS instead.",
              FutureWarning,
          )
  
      if not is_automated_build:
          bazel_precmd_flags = []
      if is_automated_build:
          root_dir = os.path.join(
              os.path.abspath(os.environ["SRC_DIR"]), "..", "bazel-root"
          )
          out_dir = os.path.join(
              os.path.abspath(os.environ["SRC_DIR"]), "..", "b-o"
          )
  
          for d in (root_dir, out_dir):
              if not os.path.exists(d):
                  os.makedirs(d)
  
          bazel_precmd_flags = [
              "--output_user_root=" + root_dir,
              "--output_base=" + out_dir,
          ]
  
          if is_native_windows_or_msys():
              bazel_flags.append("--enable_runfiles=false")
  
      bazel_targets = []
      bazel_targets += ["//:ray_pkg"] if build_python else []
      bazel_targets += ["//cpp:ray_cpp_pkg"] if build_cpp else []
      bazel_targets += ["//java:ray_java_pkg"] if build_java else []
  
      if setup_spec.build_type == BuildType.DEBUG:
          bazel_flags.extend(["--config", "debug"])
      if setup_spec.build_type == BuildType.ASAN:
          bazel_flags.extend(["--config=asan-build"])
      if setup_spec.build_type == BuildType.TSAN:
          bazel_flags.extend(["--config=tsan"])
  
      return bazel_invoke(
          subprocess.check_call,
          bazel_precmd_flags
          + ["build"]
          + bazel_flags
          + ["--"]
          + bazel_targets,
          env=bazel_env,
      )
  
imports: import argparse
  import errno
  import io
  import logging
  import os
  import pathlib
  import re
  import shlex
  import shutil
  import subprocess
  import sys
  import urllib.error
  import urllib.parse
  import urllib.request
  import warnings
  from enum import Enum
  from itertools import chain
label_desc: Use image node_id 8 for calling a global function with example usage: build(build_python, build_java, build_cpp) and returns: bazel_invoke