• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- bazel-starlark -*-
2# Copyright 2023 The Chromium Authors. All rights reserved.
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 clang/linux."""
6
7load("@builtin//path.star", "path")
8load("@builtin//struct.star", "module")
9
10__filegroups = {}
11
12def __clang_compile_coverage(ctx, cmd):
13    # TODO(b/278225415): add better support for coverage build.
14    # The instrument file contains the list of files affected by a patch.
15    # Including this file to remote action input prevents cache hits.
16    inputs = []
17    deps_args = []
18    for i, arg in enumerate(cmd.args):
19        if i == 0:
20            continue
21        if arg == "../../build/toolchain/clang_code_coverage_wrapper.py":
22            continue
23        if arg.startswith("--files-to-instrument="):
24            inputs.append(ctx.fs.canonpath(arg.removeprefix("--files-to-instrument=")))
25            continue
26        if len(deps_args) == 0 and path.base(arg).find("clang") >= 0:
27            deps_args.append(arg)
28            continue
29        if deps_args:
30            if arg in ["-MD", "-MMD", "-c"]:
31                continue
32            if arg.startswith("-MF") or arg.startswith("-o"):
33                continue
34            if i > 1 and cmd.args[i - 1] in ["-MF", "-o"]:
35                continue
36            deps_args.append(arg)
37    if deps_args:
38        deps_args.append("-M")
39    ctx.actions.fix(
40        tool_inputs = cmd.tool_inputs + inputs,
41        deps_args = deps_args,
42    )
43
44__handlers = {
45    "clang_compile_coverage": __clang_compile_coverage,
46}
47
48def __step_config(ctx, step_config):
49    step_config["input_deps"].update({
50        # clang++ is a symlink to clang
51        # but siso doesn't add symlink target automatically.
52        "third_party/llvm-build/Release+Asserts/bin/clang++": [
53            "third_party/llvm-build/Release+Asserts/bin/clang",
54        ],
55    })
56    step_config["rules"].extend([
57        {
58            "name": "clang/cxx",
59            "action": "(.*_)?cxx",
60            "command_prefix": "../../third_party/llvm-build/Release+Asserts/bin/clang++ ",
61            "inputs": [
62                "third_party/llvm-build/Release+Asserts/bin/clang++",
63            ],
64            "remote": True,
65            "canonicalize_dir": True,
66        },
67        {
68            "name": "clang/cc",
69            "action": "(.*_)?cc",
70            "command_prefix": "../../third_party/llvm-build/Release+Asserts/bin/clang ",
71            "inputs": [
72                "third_party/llvm-build/Release+Asserts/bin/clang",
73            ],
74            "remote": True,
75            "canonicalize_dir": True,
76        },
77        {
78            "name": "clang-coverage/cxx",
79            "action": "(.*_)?cxx",
80            "command_prefix": "\"python3\" ../../build/toolchain/clang_code_coverage_wrapper.py",
81            "inputs": [
82                "build/toolchain/clang_code_coverage_wrapper.py",
83                "third_party/llvm-build/Release+Asserts/bin/clang++",
84            ],
85            "handler": "clang_compile_coverage",
86            "remote": True,
87            "canonicalize_dir": True,
88        },
89        {
90            "name": "clang-coverage/cc",
91            "action": "(.*_)?cc",
92            "command_prefix": "\"python3\" ../../build/toolchain/clang_code_coverage_wrapper.py",
93            "inputs": [
94                "build/toolchain/clang_code_coverage_wrapper.py",
95                "third_party/llvm-build/Release+Asserts/bin/clang",
96            ],
97            "handler": "clang_compile_coverage",
98            "remote": True,
99            "canonicalize_dir": True,
100        },
101    ])
102    return step_config
103
104clang = module(
105    "clang",
106    step_config = __step_config,
107    filegroups = __filegroups,
108    handlers = __handlers,
109)
110