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"""Siso configuration for parsing rewrapper cfg file.""" 6 7load("@builtin//struct.star", "module") 8load("./config.star", "config") 9 10def __parse(ctx, cfg_file): 11 if not cfg_file: 12 fail("cfg file expected but none found") 13 if not ctx.fs.exists(cfg_file): 14 fail("looked for rewrapper cfg %s but not found, is download_remoteexec_cfg set in gclient custom_vars?" % cfg_file) 15 16 reproxy_config = {} 17 for line in str(ctx.fs.read(cfg_file)).splitlines(): 18 if line.startswith("canonicalize_working_dir="): 19 reproxy_config["canonicalize_working_dir"] = line.removeprefix("canonicalize_working_dir=").lower() == "true" 20 21 reproxy_config["download_outputs"] = True 22 if line.startswith("download_outputs="): 23 reproxy_config["download_outputs"] = line.removeprefix("download_outputs=").lower() == "true" 24 25 if line.startswith("exec_strategy="): 26 exec_strategy = line.removeprefix("exec_strategy=") 27 28 # Disable racing on builders since bots don't have many CPU cores. 29 if exec_strategy == "racing" and config.get(ctx, "builder"): 30 exec_strategy = "remote_local_fallback" 31 reproxy_config["exec_strategy"] = exec_strategy 32 33 if line.startswith("exec_timeout="): 34 reproxy_config["exec_timeout"] = line.removeprefix("exec_timeout=") 35 36 if line.startswith("reclient_timeout="): 37 reproxy_config["reclient_timeout"] = line.removeprefix("reclient_timeout=") 38 39 if line.startswith("inputs="): 40 reproxy_config["inputs"] = line.removeprefix("inputs=").split(",") 41 42 if line.startswith("labels="): 43 if "labels" not in reproxy_config: 44 reproxy_config["labels"] = dict() 45 for label in line.removeprefix("labels=").split(","): 46 label_parts = label.split("=") 47 if len(label_parts) != 2: 48 fail("not k,v %s" % label) 49 reproxy_config["labels"][label_parts[0]] = label_parts[1] 50 51 if line.startswith("platform="): 52 if "platform" not in reproxy_config: 53 reproxy_config["platform"] = dict() 54 for label in line.removeprefix("platform=").split(","): 55 label_parts = label.split("=") 56 if len(label_parts) != 2: 57 fail("not k,v %s" % label) 58 reproxy_config["platform"][label_parts[0]] = label_parts[1] 59 60 if line.startswith("remote_wrapper="): 61 reproxy_config["remote_wrapper"] = line.removeprefix("remote_wrapper=") 62 63 if line.startswith("server_address="): 64 reproxy_config["server_address"] = line.removeprefix("server_address=") 65 return reproxy_config 66 67rewrapper_cfg = module( 68 "rewrapper_cfg", 69 parse = __parse, 70) 71