xref: /aosp_15_r20/external/cronet/testing/scripts/checkbins.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1#!/usr/bin/env python3
2# Copyright 2015 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
6"""Launches //tools/checkbins/checkbins.py for trybots.
7
8To run locally on `out/release`, create /tmp/config.json
9
10{
11  "checkout": "."
12}
13
14python3 testing/scripts/checkbins.py \
15  --paths /tmp/config.json \
16  --build-config-fs release run \
17  --output -
18"""
19
20import json
21import os
22import sys
23
24# Add src/testing/ into sys.path for importing common without pylint errors.
25sys.path.append(
26    os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
27from scripts import common
28
29WIN_PY3_TARGETS = ['python3.exe', 'python3.bat']
30
31
32def with_python3():
33  if sys.version_info.major >= 3:
34    return sys.executable
35  # `env` should have worked on other platforms.
36  if sys.platform == 'win32':
37    # non-exhaustive, we expect depot_tools somewhere.
38    for d in os.environ['PATH'].split(';'):
39      for maybe_py3 in WIN_PY3_TARGETS:
40        if os.path.exists(os.path.join(d, maybe_py3)):
41          return os.path.join(d, maybe_py3)
42  raise Exception("Cannot find python3 to launch checkbins.py")
43
44def main_run(args):
45  print(sys.executable)
46  with common.temporary_file() as tempfile_path:
47    rc = common.run_command([
48        with_python3(),
49        os.path.join(common.SRC_DIR, 'tools', 'checkbins', 'checkbins.py'),
50        '--verbose',
51        '--json', tempfile_path,
52        os.path.join(args.paths['checkout'], 'out', args.build_config_fs),
53    ])
54
55    with open(tempfile_path) as f:
56      checkbins_results = json.load(f)
57
58  common.record_local_script_results(
59      'checkbins', args.output, checkbins_results, True)
60
61  return rc
62
63
64def main_compile_targets(args):
65  json.dump([], args.output)
66
67
68if __name__ == '__main__':
69  funcs = {
70    'run': main_run,
71    'compile_targets': main_compile_targets,
72  }
73  sys.exit(common.run_script(sys.argv[1:], funcs))
74