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 clang/mac.""" 6 7load("@builtin//lib/gn.star", "gn") 8load("@builtin//path.star", "path") 9load("@builtin//struct.star", "module") 10load("./clang_all.star", "clang_all") 11load("./clang_code_coverage_wrapper.star", "clang_code_coverage_wrapper") 12load("./config.star", "config") 13load("./gn_logs.star", "gn_logs") 14load("./rewrapper_cfg.star", "rewrapper_cfg") 15 16def __filegroups(ctx): 17 sdk_includes = [ 18 "*.framework", 19 "*.h", 20 "*.json", 21 "*.modulemap", 22 "Current", 23 "Frameworks", 24 "Headers", 25 "Modules", 26 "crt*.o", 27 "usr/include/c++/v1/*", 28 "usr/include/c++/v1/*/*", 29 ] 30 fg = { 31 "build/mac_files/xcode_binaries/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk:headers": { 32 "type": "glob", 33 "includes": sdk_includes, 34 }, 35 } 36 37 # precompute subtree for sysroot/frameworks for siso scandeps, 38 # which is not complex enough to handle C preprocessor tricks 39 # and need system include dirs when using deps log of -MMD. 40 # need to add new entries when new version is used. 41 # TODO: b/323091468 - get sysroot, ios_sdk_path from gn 42 fg[ctx.fs.canonpath("./sdk/xcode_links/MacOSX14.2.sdk") + ":headers"] = { 43 "type": "glob", 44 "includes": sdk_includes, 45 } 46 fg[ctx.fs.canonpath("./sdk/xcode_links/iPhoneSimulator17.2.sdk") + ":headers"] = { 47 "type": "glob", 48 "includes": sdk_includes, 49 } 50 51 # https://b.corp.google.com/issues/332652041#comment2 52 fg[ctx.fs.canonpath("./sdk/xcode_links/MacOSX14.4.sdk") + ":headers"] = { 53 "type": "glob", 54 "includes": sdk_includes, 55 } 56 fg[ctx.fs.canonpath("./sdk/xcode_links/iPhoneSimulator17.4.sdk") + ":headers"] = { 57 "type": "glob", 58 "includes": sdk_includes, 59 } 60 61 # https://chromium-review.googlesource.com/c/chromium/src/+/5568662 62 fg[ctx.fs.canonpath("./sdk/xcode_links/MacOSX14.5.sdk") + ":headers"] = { 63 "type": "glob", 64 "includes": sdk_includes, 65 } 66 fg[ctx.fs.canonpath("./sdk/xcode_links/iPhoneSimulator17.5.sdk") + ":headers"] = { 67 "type": "glob", 68 "includes": sdk_includes, 69 } 70 71 fg[ctx.fs.canonpath("./sdk/xcode_links/iPhoneSimulator.platform/Developer/Library/Frameworks") + ":headers"] = { 72 "type": "glob", 73 "includes": sdk_includes, 74 } 75 fg.update(clang_all.filegroups(ctx)) 76 return fg 77 78def __clang_compile_coverage(ctx, cmd): 79 clang_command = clang_code_coverage_wrapper.run(ctx, list(cmd.args)) 80 ctx.actions.fix(args = clang_command) 81 82__handlers = { 83 "clang_compile_coverage": __clang_compile_coverage, 84} 85 86def __step_config(ctx, step_config): 87 cfg = "buildtools/reclient_cfgs/chromium-browser-clang/rewrapper_mac.cfg" 88 if ctx.fs.exists(cfg): 89 reproxy_config = rewrapper_cfg.parse(ctx, cfg) 90 largePlatform = {} 91 for k, v in reproxy_config["platform"].items(): 92 if k.startswith("label:action"): 93 continue 94 largePlatform[k] = v 95 largePlatform["label:action_large"] = "1" 96 step_config["platforms"].update({ 97 "clang": reproxy_config["platform"], 98 "clang_large": largePlatform, 99 }) 100 step_config["input_deps"].update(clang_all.input_deps) 101 102 gn_logs_data = gn_logs.read(ctx) 103 input_root_absolute_path = gn_logs_data.get("clang_need_input_root_absolute_path") == "true" 104 input_root_absolute_path_for_objc = gn_logs_data.get("clang_need_input_root_absolute_path_for_objc") == "true" 105 106 # TODO(b/346425467): enable canonicalize_dir when not input_root_absolute_path 107 canonicalize_dir = False 108 canonicalize_dir_for_objc = False 109 110 step_config["rules"].extend([ 111 { 112 "name": "clang/cxx", 113 "action": "(.*_)?cxx", 114 "command_prefix": "../../third_party/llvm-build/Release+Asserts/bin/clang++", 115 "inputs": [ 116 "third_party/llvm-build/Release+Asserts/bin/clang++", 117 ], 118 "exclude_input_patterns": ["*.stamp"], 119 "platform_ref": "clang", 120 "remote": True, 121 "input_root_absolute_path": input_root_absolute_path, 122 "canonicalize_dir": canonicalize_dir, 123 "remote_wrapper": reproxy_config["remote_wrapper"], 124 "timeout": "2m", 125 }, 126 { 127 "name": "clang/cc", 128 "action": "(.*_)?cc", 129 "command_prefix": "../../third_party/llvm-build/Release+Asserts/bin/clang", 130 "inputs": [ 131 "third_party/llvm-build/Release+Asserts/bin/clang", 132 ], 133 "exclude_input_patterns": ["*.stamp"], 134 "platform_ref": "clang", 135 "remote": True, 136 "input_root_absolute_path": input_root_absolute_path, 137 "canonicalize_dir": canonicalize_dir, 138 "remote_wrapper": reproxy_config["remote_wrapper"], 139 "timeout": "2m", 140 }, 141 { 142 "name": "clang/objcxx", 143 "action": "(.*_)?objcxx", 144 "command_prefix": "../../third_party/llvm-build/Release+Asserts/bin/clang++", 145 "inputs": [ 146 "third_party/llvm-build/Release+Asserts/bin/clang++", 147 ], 148 "exclude_input_patterns": ["*.stamp"], 149 "platform_ref": "clang", 150 "remote": True, 151 "remote_wrapper": reproxy_config["remote_wrapper"], 152 "timeout": "2m", 153 "input_root_absolute_path": input_root_absolute_path_for_objc, 154 "canonicalize_dir": canonicalize_dir_for_objc, 155 }, 156 { 157 "name": "clang/objc", 158 "action": "(.*_)?objc", 159 "command_prefix": "../../third_party/llvm-build/Release+Asserts/bin/clang", 160 "inputs": [ 161 "third_party/llvm-build/Release+Asserts/bin/clang", 162 ], 163 "exclude_input_patterns": ["*.stamp"], 164 "platform_ref": "clang", 165 "remote": True, 166 "remote_wrapper": reproxy_config["remote_wrapper"], 167 "timeout": "2m", 168 "input_root_absolute_path": input_root_absolute_path_for_objc, 169 "canonicalize_dir": canonicalize_dir_for_objc, 170 }, 171 { 172 "name": "clang-coverage/cxx", 173 "action": "(.*_)?cxx", 174 "command_prefix": "python3 ../../build/toolchain/clang_code_coverage_wrapper.py", 175 "inputs": [ 176 "third_party/llvm-build/Release+Asserts/bin/clang++", 177 ], 178 "exclude_input_patterns": ["*.stamp"], 179 "handler": "clang_compile_coverage", 180 "platform_ref": "clang", 181 "remote": True, 182 "input_root_absolute_path": input_root_absolute_path, 183 "canonicalize_dir": canonicalize_dir, 184 "remote_wrapper": reproxy_config["remote_wrapper"], 185 "timeout": "2m", 186 }, 187 { 188 "name": "clang-coverage/cc", 189 "action": "(.*_)?cc", 190 "command_prefix": "python3 ../../build/toolchain/clang_code_coverage_wrapper.py", 191 "inputs": [ 192 "third_party/llvm-build/Release+Asserts/bin/clang", 193 ], 194 "exclude_input_patterns": ["*.stamp"], 195 "handler": "clang_compile_coverage", 196 "platform_ref": "clang", 197 "remote": True, 198 "input_root_absolute_path": input_root_absolute_path, 199 "canonicalize_dir": canonicalize_dir, 200 "remote_wrapper": reproxy_config["remote_wrapper"], 201 "timeout": "2m", 202 }, 203 { 204 "name": "clang-coverage/objcxx", 205 "action": "(.*_)?objcxx", 206 "command_prefix": "python3 ../../build/toolchain/clang_code_coverage_wrapper.py", 207 "inputs": [ 208 "third_party/llvm-build/Release+Asserts/bin/clang++", 209 ], 210 "exclude_input_patterns": ["*.stamp"], 211 "handler": "clang_compile_coverage", 212 "platform_ref": "clang", 213 "remote": True, 214 "remote_wrapper": reproxy_config["remote_wrapper"], 215 "timeout": "2m", 216 "input_root_absolute_path": input_root_absolute_path_for_objc, 217 "canonicalize_dir": canonicalize_dir_for_objc, 218 }, 219 { 220 "name": "clang-coverage/objc", 221 "action": "(.*_)?objc", 222 "command_prefix": "python3 ../../build/toolchain/clang_code_coverage_wrapper.py", 223 "inputs": [ 224 "third_party/llvm-build/Release+Asserts/bin/clang", 225 ], 226 "exclude_input_patterns": ["*.stamp"], 227 "handler": "clang_compile_coverage", 228 "platform_ref": "clang", 229 "remote": True, 230 "remote_wrapper": reproxy_config["remote_wrapper"], 231 "timeout": "2m", 232 "input_root_absolute_path": input_root_absolute_path_for_objc, 233 "canonicalize_dir": canonicalize_dir_for_objc, 234 }, 235 ]) 236 return step_config 237 238clang = module( 239 "clang", 240 step_config = __step_config, 241 filegroups = __filegroups, 242 handlers = __handlers, 243) 244