xref: /aosp_15_r20/external/angle/build/config/siso/clang_exception.star (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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"""workaround for exceptional clang actions. e.g. exit=137 (OOM?),
6 or DeadlineExceeded.
7"""
8
9load("@builtin//runtime.star", "runtime")
10load("@builtin//struct.star", "module")
11
12def __step_config(ctx, step_config):
13    exceptions = [
14        {
15            # TODO: crbug.com/380755128 - Make each compile unit smaller.
16            "name": "fuzzer_large_compile",
17            "action_outs": [
18                "./obj/chrome/test/fuzzing/htmlfuzzer_proto_gen/htmlfuzzer_sub.pb.o",
19                "./obj/chrome/test/fuzzing/jsfuzzer/jsfuzzer.o",
20                "./obj/chrome/test/fuzzing/jsfuzzer_proto_gen/jsfuzzer.pb.o",
21                "./obj/chrome/test/fuzzing/jsfuzzer_proto_gen/jsfuzzer_sub.pb.o",
22                "./obj/chrome/test/fuzzing/webidl_fuzzing/webidl_fuzzer_grammar/webidl_fuzzer_grammar.o",
23                "./obj/chrome/test/fuzzing/webidl_fuzzing/webidl_fuzzer_grammar_proto_gen/webidl_fuzzer_grammar.pb.o",
24                "./obj/chrome/test/fuzzing/webidl_fuzzing/webidlfuzzer/webidlfuzzer.o",
25                "./obj/chrome/test/fuzzing/webidl_fuzzing/webidlfuzzer_proto_gen/webidlfuzzer.pb.o",
26                "./obj/chrome/test/fuzzing/webidl_fuzzing/webidlfuzzer_proto_gen/webidlfuzzer_sub.pb.o",
27            ],
28            "timeout": "15m",
29            # need 9G for debug build
30            "use_large": True,
31        },
32    ]
33    new_rules = []
34    for rule in step_config["rules"]:
35        if not rule["name"].endswith("/cxx"):
36            new_rules.append(rule)
37            continue
38        if "action_outs" in rule:
39            fail("unexpeced \"action_outs\" in cxx rule %s" % rule["name"])
40        for ex in exceptions:
41            r = {}
42            r.update(rule)
43            r["name"] += "/exception/" + ex["name"]
44            outs = ex["action_outs"]
45            if runtime.os == "windows":
46                outs = [obj.removesuffix(".o") + ".obj" for obj in outs if obj.startswith("./obj/")]
47            r["action_outs"] = outs
48            if "timeout" in ex:
49                r["timeout"] = ex["timeout"]
50            if "use_large" in ex and ex["use_large"]:
51                # use `_large` variant of platform if it doesn't use default platform,
52                # i.e. mac/win case.
53                if "platform_ref" in r:
54                    r["platform_ref"] = r["platform_ref"] + "_large"
55                else:
56                    r["platform_ref"] = "large"
57            if r.get("handler") == "rewrite_rewrapper":
58                r["handler"] = "rewrite_rewrapper_large"
59            new_rules.append(r)
60        new_rules.append(rule)
61    step_config["rules"] = new_rules
62    return step_config
63
64clang_exception = module(
65    "clang_exception",
66    step_config = __step_config,
67)
68