xref: /aosp_15_r20/external/angle/build/config/siso/configure_siso.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1#!/usr/bin/env python3
2# Copyright 2023 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"""This script is used to configure siso."""
6
7import argparse
8import os
9import sys
10
11THIS_DIR = os.path.abspath(os.path.dirname(__file__))
12
13SISO_PROJECT_CFG = "SISO_PROJECT"
14SISO_ENV = os.path.join(THIS_DIR, ".sisoenv")
15
16
17def ReadConfig():
18  entries = {}
19  if not os.path.isfile(SISO_ENV):
20      print('The .sisoenv file has not been generated yet')
21      return entries
22  with open(SISO_ENV, 'r') as f:
23    for line in f:
24      parts = line.strip().split('=')
25      if len(parts) > 1:
26        entries[parts[0].strip()] = parts[1].strip()
27    return entries
28
29
30def main():
31  parser = argparse.ArgumentParser(description="configure siso")
32  parser.add_argument("--rbe_instance", help="RBE instance to use for Siso")
33  parser.add_argument("--get-siso-project",
34                      help="Print the currently configured siso project to "
35                      "stdout",
36                      action="store_true")
37  args = parser.parse_args()
38
39  if args.get_siso_project:
40    config = ReadConfig()
41    if not SISO_PROJECT_CFG in config:
42      return 1
43    print(config[SISO_PROJECT_CFG])
44    return 0
45
46  project = None
47  rbe_instance = args.rbe_instance
48  if rbe_instance:
49    elems = rbe_instance.split("/")
50    if len(elems) == 4 and elems[0] == "projects":
51      project = elems[1]
52      rbe_instance = elems[-1]
53
54  with open(SISO_ENV, "w") as f:
55    if project:
56      f.write("%s=%s\n" % (SISO_PROJECT_CFG, project))
57    if rbe_instance:
58      f.write("SISO_REAPI_INSTANCE=%s\n" % rbe_instance)
59  return 0
60
61
62if __name__ == "__main__":
63  sys.exit(main())
64