| OLD | NEW |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import("//build/config/android/config.gni") | 5 import("//build/config/android/config.gni") |
| 6 import("//build/config/clang/clang.gni") | 6 import("//build/config/clang/clang.gni") |
| 7 import("//build/config/nacl/config.gni") | 7 import("//build/config/nacl/config.gni") |
| 8 import("//build/config/sanitizers/sanitizers.gni") | 8 import("//build/config/sanitizers/sanitizers.gni") |
| 9 import("//build/config/v8_target_cpu.gni") | 9 import("//build/config/v8_target_cpu.gni") |
| 10 import("//build/toolchain/cc_wrapper.gni") | 10 import("//build/toolchain/cc_wrapper.gni") |
| 11 import("//build/toolchain/clang_static_analyzer.gni") | 11 import("//build/toolchain/clang_static_analyzer.gni") |
| 12 import("//build/toolchain/goma.gni") | 12 import("//build/toolchain/goma.gni") |
| 13 import("//build/toolchain/toolchain.gni") | 13 import("//build/toolchain/toolchain.gni") |
| 14 | 14 |
| 15 # Path to the Clang static analysis wrapper script. |
| 16 analyzer_wrapper = |
| 17 rebase_path("//build/toolchain/clang_static_analyzer_wrapper.py", |
| 18 root_build_dir) |
| 19 |
| 15 # This template defines a toolchain for something that works like gcc | 20 # This template defines a toolchain for something that works like gcc |
| 16 # (including clang). | 21 # (including clang). |
| 17 # | 22 # |
| 18 # It requires the following variables specifying the executables to run: | 23 # It requires the following variables specifying the executables to run: |
| 19 # - ar | 24 # - ar |
| 20 # - cc | 25 # - cc |
| 21 # - cxx | 26 # - cxx |
| 22 # - ld | 27 # - ld |
| 23 # | 28 # |
| 24 # Optional parameters that control the tools: | 29 # Optional parameters that control the tools: |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 if (defined(toolchain_args.use_goma)) { | 124 if (defined(toolchain_args.use_goma)) { |
| 120 toolchain_uses_goma = toolchain_args.use_goma | 125 toolchain_uses_goma = toolchain_args.use_goma |
| 121 } else { | 126 } else { |
| 122 toolchain_uses_goma = use_goma | 127 toolchain_uses_goma = use_goma |
| 123 } | 128 } |
| 124 if (defined(toolchain_args.cc_wrapper)) { | 129 if (defined(toolchain_args.cc_wrapper)) { |
| 125 toolchain_cc_wrapper = toolchain_args.cc_wrapper | 130 toolchain_cc_wrapper = toolchain_args.cc_wrapper |
| 126 } else { | 131 } else { |
| 127 toolchain_cc_wrapper = cc_wrapper | 132 toolchain_cc_wrapper = cc_wrapper |
| 128 } | 133 } |
| 134 assert(!(toolchain_cc_wrapper != "" && toolchain_uses_goma), |
| 135 "Goma and cc_wrapper can't be used together.") |
| 129 | 136 |
| 130 # Compute the compiler prefix. | 137 # When the invoker has explicitly overridden use_goma or cc_wrapper in the |
| 138 # toolchain args, use those values, otherwise default to the global one. |
| 139 # This works because the only reasonable override that toolchains might |
| 140 # supply for these values are to force-disable them. |
| 131 if (toolchain_uses_goma) { | 141 if (toolchain_uses_goma) { |
| 132 assert(toolchain_cc_wrapper == "", | 142 goma_path = "$goma_dir/gomacc" |
| 133 "Goma and cc_wrapper can't be used together.") | 143 |
| 134 compiler_prefix = "$goma_dir/gomacc " | 144 # Use the static analysis script if static analysis is turned on |
| 135 } else if (toolchain_cc_wrapper != "") { | 145 # AND the tool has not opted out by setting |
| 136 compiler_prefix = toolchain_cc_wrapper + " " | 146 # 'is_clang_static_analysis_supported' to false. |
| 147 if (is_clang && use_clang_static_analyzer && |
| 148 (!defined(invoker.is_clang_analysis_supported) || |
| 149 invoker.is_clang_analysis_supported)) { |
| 150 compiler_prefix = "${analyzer_wrapper} ${goma_path} " |
| 151 |
| 152 # Create a distinct variable for "asm", since analysis runs pass |
| 153 # a bunch of flags to clang/clang++ that are nonsensical on assembler |
| 154 # runs. |
| 155 asm = "${goma_path} ${invoker.cc}" |
| 156 } else { |
| 157 compiler_prefix = "${goma_path} " |
| 158 } |
| 137 } else { | 159 } else { |
| 138 compiler_prefix = "" | 160 if (is_clang && use_clang_static_analyzer && |
| 161 (!defined(invoker.is_clang_analysis_supported) || |
| 162 invoker.is_clang_analysis_supported)) { |
| 163 compiler_prefix = "${analyzer_wrapper} " |
| 164 asm = invoker.cc |
| 165 } else { |
| 166 compiler_prefix = "${toolchain_cc_wrapper} " |
| 167 } |
| 139 } | 168 } |
| 140 | 169 |
| 141 cc = compiler_prefix + invoker.cc | 170 cc = compiler_prefix + invoker.cc |
| 142 cxx = compiler_prefix + invoker.cxx | 171 cxx = compiler_prefix + invoker.cxx |
| 143 ar = invoker.ar | 172 ar = invoker.ar |
| 144 ld = invoker.ld | 173 ld = invoker.ld |
| 174 if (!defined(asm)) { |
| 175 asm = cc |
| 176 } |
| 145 if (defined(invoker.readelf)) { | 177 if (defined(invoker.readelf)) { |
| 146 readelf = invoker.readelf | 178 readelf = invoker.readelf |
| 147 } else { | 179 } else { |
| 148 readelf = "readelf" | 180 readelf = "readelf" |
| 149 } | 181 } |
| 150 if (defined(invoker.nm)) { | 182 if (defined(invoker.nm)) { |
| 151 nm = invoker.nm | 183 nm = invoker.nm |
| 152 } else { | 184 } else { |
| 153 nm = "nm" | 185 nm = "nm" |
| 154 } | 186 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 compile_wrapper = | 288 compile_wrapper = |
| 257 rebase_path("//build/toolchain/gcc_compile_wrapper.py", | 289 rebase_path("//build/toolchain/gcc_compile_wrapper.py", |
| 258 root_build_dir) | 290 root_build_dir) |
| 259 command = "$python_path \"$compile_wrapper\" --resource-whitelist=\"{{ou
tput}}.whitelist\" $command" | 291 command = "$python_path \"$compile_wrapper\" --resource-whitelist=\"{{ou
tput}}.whitelist\" $command" |
| 260 } | 292 } |
| 261 } | 293 } |
| 262 | 294 |
| 263 tool("asm") { | 295 tool("asm") { |
| 264 # For GCC we can just use the C compiler to compile assembly. | 296 # For GCC we can just use the C compiler to compile assembly. |
| 265 depfile = "{{output}}.d" | 297 depfile = "{{output}}.d" |
| 266 command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_di
rs}} {{asmflags}} -c {{source}} -o {{output}}" | 298 command = "$asm -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_d
irs}} {{asmflags}} -c {{source}} -o {{output}}" |
| 267 depsformat = "gcc" | 299 depsformat = "gcc" |
| 268 description = "ASM {{output}}" | 300 description = "ASM {{output}}" |
| 269 outputs = [ | 301 outputs = [ |
| 270 "$object_subdir/{{source_name_part}}.o", | 302 "$object_subdir/{{source_name_part}}.o", |
| 271 ] | 303 ] |
| 272 } | 304 } |
| 273 | 305 |
| 274 tool("alink") { | 306 tool("alink") { |
| 275 rspfile = "{{output}}.rsp" | 307 rspfile = "{{output}}.rsp" |
| 276 whitelist_flag = " " | 308 whitelist_flag = " " |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 toolprefix = invoker.toolprefix | 543 toolprefix = invoker.toolprefix |
| 512 } else { | 544 } else { |
| 513 toolprefix = "" | 545 toolprefix = "" |
| 514 } | 546 } |
| 515 | 547 |
| 516 gcc_toolchain(target_name) { | 548 gcc_toolchain(target_name) { |
| 517 prefix = rebase_path("$clang_base_path/bin", root_build_dir) | 549 prefix = rebase_path("$clang_base_path/bin", root_build_dir) |
| 518 cc = "$prefix/clang" | 550 cc = "$prefix/clang" |
| 519 cxx = "$prefix/clang++" | 551 cxx = "$prefix/clang++" |
| 520 ld = cxx | 552 ld = cxx |
| 521 | |
| 522 if (use_clang_static_analyzer) { | |
| 523 # Static analysis isn't supported under GOMA. See crbug.com/687245 | |
| 524 # for progress on this issue. | |
| 525 assert(!use_goma, "'use_clang_static_analyzer' cannot be used with GOMA.") | |
| 526 | |
| 527 # Call "ccc-analyzer" or "c++-analyzer" instead of directly calling Clang. | |
| 528 # |wrapper_tool| sets the environment variables which are read by the | |
| 529 # analyzer tools. | |
| 530 analyzer_wrapper = | |
| 531 rebase_path("//build/toolchain/clang_static_analyzer_wrapper.py", | |
| 532 root_build_dir) | |
| 533 cc = analyzer_wrapper + " --clang-cc-path=${cc} --analyzer=" + | |
| 534 rebase_path("//third_party/scan-build/src/libexec/ccc-analyzer", | |
| 535 root_build_dir) | |
| 536 cxx = analyzer_wrapper + " --clang-cxx-path=${cxx} --analyzer=" + | |
| 537 rebase_path("//third_party/scan-build/src/libexec/c++-analyzer", | |
| 538 root_build_dir) | |
| 539 } | |
| 540 | |
| 541 readelf = "${toolprefix}readelf" | 553 readelf = "${toolprefix}readelf" |
| 542 ar = "${toolprefix}ar" | 554 ar = "${toolprefix}ar" |
| 543 nm = "${toolprefix}nm" | 555 nm = "${toolprefix}nm" |
| 544 | 556 |
| 545 forward_variables_from(invoker, | 557 forward_variables_from(invoker, |
| 546 [ | 558 [ |
| 559 "strip", |
| 560 "is_clang_analysis_supported", |
| 547 "enable_linker_map", | 561 "enable_linker_map", |
| 548 "strip", | |
| 549 ]) | 562 ]) |
| 550 | 563 |
| 551 toolchain_args = { | 564 toolchain_args = { |
| 552 if (defined(invoker.toolchain_args)) { | 565 if (defined(invoker.toolchain_args)) { |
| 553 forward_variables_from(invoker.toolchain_args, "*") | 566 forward_variables_from(invoker.toolchain_args, "*") |
| 554 } | 567 } |
| 555 is_clang = true | 568 is_clang = true |
| 556 } | 569 } |
| 557 } | 570 } |
| 558 } | 571 } |
| OLD | NEW |