• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- bazel-starlark -*-
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"""Config module for checking siso -config flags."""
6
7load("@builtin//struct.star", "module")
8
9__KNOWN_CONFIG_OPTIONS = [
10    # Indicates that the build runs on a builder.
11    "builder",
12
13    # Indicate that it runs on Cog (automatically set on Cog).
14    "cog",
15
16    # Force disable additional remote on cog.
17    # TODO: b/333033551 - check performance with/without remote on cog.
18    "disable-remote-on-cog",
19
20    # TODO: b/308405411 - Enable this config for all builders.
21    "remote-devtools-frontend-typescript",
22
23    # TODO: b/316267242 - Enable remote links after confirming performance.
24    "remote-library-link",
25    "remote-exec-link",
26]
27
28def __check(ctx):
29    if "config" in ctx.flags:
30        for cfg in ctx.flags["config"].split(","):
31            if cfg not in __KNOWN_CONFIG_OPTIONS:
32                print("unknown config: %s" % cfg)
33
34def __get(ctx, key):
35    onCog = ctx.fs.exists("../.citc")
36    disableRemoteOnCog = False
37    if "config" in ctx.flags:
38        for cfg in ctx.flags["config"].split(","):
39            if cfg == key:
40                return True
41            if cfg == "disable-remote-on-cog":
42                disableRemoteOnCog = True
43            if cfg == "cog":
44                onCog = True
45    if onCog:
46        if disableRemoteOnCog:
47            return False
48
49        # on cog, .citc directory exist in parent directory of exec root.
50        # disable race strategy as "builder".
51        # enable "remote-*" on cog
52        # TODO: b/308405411 - enable "remote-devtools-frontend-typescript"
53        if key in ("builder", "cog", "remote-library-link", "remote-exec-link"):
54            return True
55    return False
56
57config = module(
58    "config",
59    check = __check,
60    get = __get,
61)
62