siso: add .sisorc support

if build/config/siso/.sisorc exists, it will add global flags
or subcmd flags.

global flags is line starting with "-"
e.g.
--credential_helper=gcloud

subcmd flags are line starting with subcmd name.
e.g.
ninja --verbose_failures=false -k=0

Bug: b/269554009
Change-Id: I4691b9e17571721dd5b70f6ffb063e2d2f0ac4e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6910278
Reviewed-by: Scott Lee <ddoman@chromium.org>
Reviewed-by: Philipp Wollermann <philwo@google.com>
Commit-Queue: Fumitoshi Ukai <ukai@google.com>
Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
This commit is contained in:
Fumitoshi Ukai
2025-09-03 19:03:18 -07:00
committed by LUCI CQ
parent 7064499de3
commit 0f565fa858
3 changed files with 112 additions and 1 deletions

43
siso.py
View File

@@ -9,6 +9,7 @@ binary when run inside a gclient source tree, so users can just type
import os
import signal
import shlex
import shutil
import sys
@@ -41,6 +42,39 @@ def check_outdir(subcmd, out_dir):
sys.exit(1)
def load_sisorc(rcfile):
if not os.path.exists(rcfile):
return [], {}
global_flags = []
subcmd_flags = {}
with open(rcfile) as file:
for line in file:
line = line.strip()
if line.startswith("#"):
continue
args = shlex.split(line)
if len(args) == 0:
continue
if line.startswith("-"):
global_flags.extend(args)
continue
subcmd_flags[args[0]] = args[1:]
return global_flags, subcmd_flags
def apply_sisorc(global_flags, subcmd_flags, args, subcmd):
new_args = []
for arg in args:
if not new_args:
new_args.extend(global_flags)
if arg == subcmd:
new_args.append(arg)
new_args.extend(subcmd_flags.get(arg, []))
continue
new_args.append(arg)
return new_args
def _is_google_corp_machine():
"""This assumes that corp machine has gcert binary in known location."""
return shutil.which("gcert") is not None
@@ -145,6 +179,8 @@ def main(args):
'See build/config/siso/backend_config/README.md',
file=sys.stderr)
return 1
global_flags, subcmd_flags = load_sisorc(
os.path.join(base_path, 'build', 'config', 'siso', '.sisorc'))
siso_paths = [
siso_override_path,
os.path.join(base_path, 'third_party', 'siso', 'cipd',
@@ -155,7 +191,12 @@ def main(args):
for siso_path in siso_paths:
if siso_path and os.path.isfile(siso_path):
check_outdir(subcmd, out_dir)
return caffeinate.run([siso_path] + args[1:], env=env)
new_args = apply_sisorc(global_flags, subcmd_flags, args[1:],
subcmd)
if args[1:] != new_args:
print('depot_tools/siso.py: %s' % shlex.join(new_args),
file=sys.stderr)
return caffeinate.run([siso_path] + new_args, env=env)
print(
'depot_tools/siso.py: Could not find siso in third_party/siso '
'of the current project. Did you run gclient sync?',

View File

@@ -5,3 +5,5 @@ per-file gn_helper_test.py=file://BUILD_OWNERS
per-file ninjalog_uploader_test.py=tikuta@chromium.org
per-file reclient*=file://BUILD_OWNERS
per-file reclient*=file://RECLIENT_OWNERS
per-file siso*=file://BUILD_OWNERS

68
tests/siso_test.py Executable file
View File

@@ -0,0 +1,68 @@
#!/usr/bin/env python3
# Copyright (c) 2025 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import sys
import unittest
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, ROOT_DIR)
import siso
from testing_support import trial_dir
class SisoTest(trial_dir.TestCase):
def setUp(self):
super().setUp()
self.previous_dir = os.getcwd()
os.chdir(self.root_dir)
def tearDown(self):
os.chdir(self.previous_dir)
super().tearDown()
def test_load_sisorc_no_file(self):
global_flags, subcmd_flags = siso.load_sisorc(
os.path.join('build', 'config', 'siso', '.sisorc'))
self.assertEqual(global_flags, [])
self.assertEqual(subcmd_flags, {})
def test_load_sisorc(self):
sisorc = os.path.join('build', 'config', 'siso', '.sisorc')
os.makedirs(os.path.dirname(sisorc))
with open(sisorc, 'w') as f:
f.write("""
# comment
-credential_helper=gcloud
ninja --failure_verbose=false -k=0
""")
global_flags, subcmd_flags = siso.load_sisorc(sisorc)
self.assertEqual(global_flags, ['-credential_helper=gcloud'])
self.assertEqual(subcmd_flags,
{'ninja': ['--failure_verbose=false', '-k=0']})
def test_apply_sisorc_none(self):
new_args = siso.apply_sisorc([], {}, ['ninja', '-C', 'out/Default'],
'ninja')
self.assertEqual(new_args, ['ninja', '-C', 'out/Default'])
def test_apply_sisorc_nosubcmd(self):
new_args = siso.apply_sisorc([], {'ninja': ['-k=0']}, ['-version'], '')
self.assertEqual(new_args, ['-version'])
def test_apply_sisorc(self):
new_args = siso.apply_sisorc(
['-credential_helper=luci-auth'], {'ninja': ['-k=0']},
['-log_dir=/tmp', 'ninja', '-C', 'out/Default'], 'ninja')
self.assertEqual(new_args, [
'-credential_helper=luci-auth', '-log_dir=/tmp', 'ninja', '-k=0',
'-C', 'out/Default'
])
if __name__ == '__main__':
unittest.main()