• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 shutil
10import sys
11
12THIS_DIR = os.path.abspath(os.path.dirname(__file__))
13
14SISO_PROJECT_CFG = "SISO_PROJECT"
15SISO_ENV = os.path.join(THIS_DIR, ".sisoenv")
16
17_BACKEND_STAR = os.path.join(THIS_DIR, "backend_config", "backend.star")
18
19_GOOGLE_STAR = os.path.join(THIS_DIR, "backend_config", "google.star")
20_KNOWN_GOOGLE_PROJECTS = (
21    'goma-foundry-experiments',
22    'rbe-chrome-official',
23    'rbe-chrome-trusted',
24    'rbe-chrome-untrusted',
25    'rbe-chromium-trusted',
26    'rbe-chromium-trusted-test',
27    'rbe-chromium-untrusted',
28    'rbe-chromium-untrusted-test',
29    'rbe-webrtc-developer'
30    'rbe-webrtc-trusted',
31    'rbe-webrtc-untrusted',
32)
33
34def ReadConfig():
35  entries = {}
36  if not os.path.isfile(SISO_ENV):
37    print('The .sisoenv file has not been generated yet')
38    return entries
39  with open(SISO_ENV, 'r') as f:
40    for line in f:
41      parts = line.strip().split('=')
42      if len(parts) > 1:
43        entries[parts[0].strip()] = parts[1].strip()
44    return entries
45
46
47def main():
48  parser = argparse.ArgumentParser(description="configure siso")
49  parser.add_argument("--rbe_instance", help="RBE instance to use for Siso")
50  parser.add_argument("--get-siso-project",
51                      help="Print the currently configured siso project to "
52                      "stdout",
53                      action="store_true")
54  args = parser.parse_args()
55
56  if args.get_siso_project:
57    config = ReadConfig()
58    if not SISO_PROJECT_CFG in config:
59      return 1
60    print(config[SISO_PROJECT_CFG])
61    return 0
62
63  project = None
64  rbe_instance = args.rbe_instance
65  if rbe_instance:
66    elems = rbe_instance.split("/")
67    if len(elems) == 4 and elems[0] == "projects":
68      project = elems[1]
69      rbe_instance = elems[-1]
70
71  with open(SISO_ENV, "w") as f:
72    if project:
73      f.write("%s=%s\n" % (SISO_PROJECT_CFG, project))
74    if rbe_instance:
75      f.write("SISO_REAPI_INSTANCE=%s\n" % rbe_instance)
76  if project in _KNOWN_GOOGLE_PROJECTS:
77    if os.path.exists(_BACKEND_STAR):
78      os.remove(_BACKEND_STAR)
79    shutil.copy2(_GOOGLE_STAR, _BACKEND_STAR)
80  if not os.path.exists(_BACKEND_STAR):
81    print('Need to provide {} for your backend {}'.format(
82        _BACKEND_STAR, args.rbe_instance),
83          file=sys.stderr)
84    return 1
85  return 0
86
87
88if __name__ == "__main__":
89  sys.exit(main())
90