aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoj Gupta <manojgupta@chromium.org>2022-11-01 17:48:50 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-01 17:59:02 +0000
commit537f2ecfe7bc9eb996cd4abedae26bf699ab54dd (patch)
tree71f30bb8e3eaabbe890f830f17ae1ee82f32447d
parent6b285afc5e9caadeb6741efe872981ffdbb3bfe1 (diff)
downloadtoolchain-utils-537f2ecfe7bc9eb996cd4abedae26bf699ab54dd.tar.gz
Revert "compiler-wrapper: adds an IWYU component"
This reverts commit 6b285afc5e9caadeb6741efe872981ffdbb3bfe1. Reason for revert: Likely erroneous change. Original change's description: > compiler-wrapper: adds an IWYU component > > This first patch makes it possible to run IWYU as a part of the build > process. It's not currently possible for us to make changes to packages: > this functionality will appear in a later CL. > > BUG=b:237320348 > TEST=Tested locally > > Change-Id: I00610284143cf478b242b2c0ca1c05e2c8d43de4 > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3820351 > Reviewed-by: Ryan Beltran <ryanbeltran@chromium.org> > Auto-Submit: Christopher Di Bella <cjdb@google.com> > Commit-Queue: Ryan Beltran <ryanbeltran@chromium.org> > Tested-by: Christopher Di Bella <cjdb@google.com> Bug: b:237320348 Change-Id: Ia563382c3302b2a4c69942db95d315088763f97c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3995401 Auto-Submit: Manoj Gupta <manojgupta@chromium.org> Commit-Queue: Ryan Beltran <ryanbeltran@chromium.org> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Ryan Beltran <ryanbeltran@chromium.org>
-rw-r--r--compiler_wrapper/compiler_wrapper.go15
-rw-r--r--compiler_wrapper/iwyu_flag.go155
-rw-r--r--compiler_wrapper/testdata/cros_clang_host_golden/clangtidy.json8
-rw-r--r--compiler_wrapper/testdata/cros_hardened_golden/clangtidy.json8
-rw-r--r--compiler_wrapper/testdata/cros_hardened_llvmnext_golden/clangtidy.json8
-rw-r--r--compiler_wrapper/testdata/cros_hardened_noccache_golden/clangtidy.json8
-rw-r--r--compiler_wrapper/testdata/cros_nonhardened_golden/clangtidy.json8
7 files changed, 20 insertions, 190 deletions
diff --git a/compiler_wrapper/compiler_wrapper.go b/compiler_wrapper/compiler_wrapper.go
index dcaada99..1386374e 100644
--- a/compiler_wrapper/compiler_wrapper.go
+++ b/compiler_wrapper/compiler_wrapper.go
@@ -151,7 +151,6 @@ func callCompilerInternal(env env, cfg *config, inputCmd *command) (exitCode int
}
} else {
cSrcFile, tidyFlags, tidyMode := processClangTidyFlags(mainBuilder)
- cSrcFile, iwyuFlags, iwyuMode := processIWYUFlags(mainBuilder)
if mainBuilder.target.compilerType == clangType {
err := prepareClangCommand(mainBuilder)
if err != nil {
@@ -177,20 +176,6 @@ func callCompilerInternal(env env, cfg *config, inputCmd *command) (exitCode int
return 0, err
}
}
-
- if iwyuMode != iwyuModeNone {
- if iwyuMode == iwyuModeError {
- panic(fmt.Sprintf("Unknown IWYU mode"))
- }
-
- allowCCache = false
- clangCmdWithoutRemoteBuildAndCCache := mainBuilder.build()
- err := runIWYU(env, clangCmdWithoutRemoteBuildAndCCache, cSrcFile, iwyuFlags)
- if err != nil {
- return 0, err
- }
- }
-
if remoteBuildUsed, err = processRemoteBuildAndCCacheFlags(allowCCache, mainBuilder); err != nil {
return 0, err
}
diff --git a/compiler_wrapper/iwyu_flag.go b/compiler_wrapper/iwyu_flag.go
deleted file mode 100644
index c1e6af65..00000000
--- a/compiler_wrapper/iwyu_flag.go
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright 2022 The ChromiumOS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package main
-
-import (
- "bufio"
- "bytes"
- "fmt"
- "path/filepath"
- "strings"
-)
-
-type useIWYUMode int
-
-const iwyuCrashSubstring = "PLEASE submit a bug report"
-
-const (
- iwyuModeNone useIWYUMode = iota
- iwyuModeAll
- iwyuModeError
-)
-
-var srcFileSuffixes = []string{
- ".c",
- ".cc",
- ".cpp",
- ".C",
- ".cxx",
- ".c++",
-}
-
-func findWithIWYUFlag(args []builderArg) (string, []builderArg) {
- for i := range args {
- if args[i].value == "--with-iwyu" {
- args = append(args[:i], args[i+1:]...)
- return "1", args
- }
- }
- return "", args
-}
-
-func processIWYUFlags(builder *commandBuilder) (cSrcFile string, iwyuFlags []string, mode useIWYUMode) {
- builder.transformArgs(func(arg builderArg) string {
- const prefix = "-iwyu-flag="
- if !strings.HasPrefix(arg.value, prefix) {
- return arg.value
- }
-
- iwyuFlags = append(iwyuFlags, arg.value[len(prefix):])
- return ""
- })
-
- withIWYU, _ := builder.env.getenv("WITH_IWYU")
- if withIWYU == "" {
- withIWYU, builder.args = findWithIWYUFlag(builder.args)
- if withIWYU == "" {
- return "", iwyuFlags, iwyuModeNone
- }
- }
-
- cSrcFile = ""
- lastArg := ""
- for _, arg := range builder.args {
- if lastArg != "-o" {
- for _, suffix := range srcFileSuffixes {
- if strings.HasSuffix(arg.value, suffix) {
- cSrcFile = arg.value
- break
- }
- }
- }
- lastArg = arg.value
- }
-
- if cSrcFile == "" {
- return "", iwyuFlags, iwyuModeNone
- }
-
- if withIWYU != "1" {
- return "", iwyuFlags, iwyuModeError
- }
-
- return cSrcFile, iwyuFlags, iwyuModeAll
-}
-
-func calcIWYUInvocation(env env, clangCmd *command, cSrcFile string, iwyuFlags ...string) (*command, error) {
- resourceDir, err := getClangResourceDir(env, clangCmd.Path)
- if err != nil {
- return nil, err
- }
-
- iwyuPath := filepath.Join(filepath.Dir(clangCmd.Path), "include-what-you-use")
- args := append([]string{}, iwyuFlags...)
- args = append(args, "-resource-dir="+resourceDir)
- args = append(args, clangCmd.Args...)
-
- for i := 0; i < len(args); i++ {
- for j := 0; j < len(srcFileSuffixes); j++ {
- if strings.HasSuffix(args[i], srcFileSuffixes[j]) {
- args = append(args[:i], args[i+1:]...)
- break
- }
- }
- }
- args = append(args, cSrcFile)
-
- return &command{
- Path: iwyuPath,
- Args: args,
- EnvUpdates: clangCmd.EnvUpdates,
- }, nil
-}
-
-func runIWYU(env env, clangCmd *command, cSrcFile string, extraIWYUFlags []string) error {
- extraIWYUFlags = append(extraIWYUFlags, "-Xiwyu", "--mapping_file=/usr/share/include-what-you-use/libcxx.imp", "-Xiwyu", "--no_fwd_decls")
- iwyuCmd, err := calcIWYUInvocation(env, clangCmd, cSrcFile, extraIWYUFlags...)
- if err != nil {
- return fmt.Errorf("calculating include-what-you-use invocation: %v", err)
- }
-
- // Note: We pass nil as stdin as we checked before that the compiler
- // was invoked with a source file argument.
- var stderr bytes.Buffer
- stderr_writer := bufio.NewWriter(&stderr)
- exitCode, err := wrapSubprocessErrorWithSourceLoc(iwyuCmd,
- env.run(iwyuCmd, nil, nil, stderr_writer))
- stderr_ := stderr.String()
- fmt.Fprintln(env.stderr(), stderr_)
-
- if err == nil && exitCode != 0 {
- // Note: We continue on purpose when include-what-you-use fails
- // to maintain compatibility with the previous wrapper.
- fmt.Fprintln(env.stderr(), "include-what-you-use failed")
- }
-
- var path strings.Builder
- path.WriteString(strings.TrimSuffix(iwyuCmd.Path, "include-what-you-use"))
- path.WriteString("fix_includes.py")
- fixIncludesCmd := &command{
- Path: path.String(),
- Args: []string{"--nocomment"},
- EnvUpdates: clangCmd.EnvUpdates,
- }
-
- exitCode, err = wrapSubprocessErrorWithSourceLoc(fixIncludesCmd,
- env.run(fixIncludesCmd, strings.NewReader(stderr_), env.stdout(), env.stderr()))
- if err == nil && exitCode != 0 {
- // Note: We continue on purpose when include-what-you-use fails
- // to maintain compatibility with the previous wrapper.
- fmt.Fprint(env.stderr(), "include-what-you-use failed")
- }
- return nil
-}
diff --git a/compiler_wrapper/testdata/cros_clang_host_golden/clangtidy.json b/compiler_wrapper/testdata/cros_clang_host_golden/clangtidy.json
index d0a604ba..c1cf0507 100644
--- a/compiler_wrapper/testdata/cros_clang_host_golden/clangtidy.json
+++ b/compiler_wrapper/testdata/cros_clang_host_golden/clangtidy.json
@@ -27,7 +27,7 @@
"path": "/tmp/stable/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"-Qunused-arguments",
@@ -117,7 +117,7 @@
"path": "/tmp/stable/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"-Qunused-arguments",
@@ -209,7 +209,7 @@
"path": "/tmp/stable/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"-Qunused-arguments",
@@ -305,7 +305,7 @@
"path": "/tmp/stable/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"-Qunused-arguments",
diff --git a/compiler_wrapper/testdata/cros_hardened_golden/clangtidy.json b/compiler_wrapper/testdata/cros_hardened_golden/clangtidy.json
index bfef2799..f7438940 100644
--- a/compiler_wrapper/testdata/cros_hardened_golden/clangtidy.json
+++ b/compiler_wrapper/testdata/cros_hardened_golden/clangtidy.json
@@ -27,7 +27,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
@@ -141,7 +141,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
@@ -258,7 +258,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
@@ -379,7 +379,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
diff --git a/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/clangtidy.json b/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/clangtidy.json
index bfef2799..f7438940 100644
--- a/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/clangtidy.json
+++ b/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/clangtidy.json
@@ -27,7 +27,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
@@ -141,7 +141,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
@@ -258,7 +258,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
@@ -379,7 +379,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
diff --git a/compiler_wrapper/testdata/cros_hardened_noccache_golden/clangtidy.json b/compiler_wrapper/testdata/cros_hardened_noccache_golden/clangtidy.json
index bfef2799..f7438940 100644
--- a/compiler_wrapper/testdata/cros_hardened_noccache_golden/clangtidy.json
+++ b/compiler_wrapper/testdata/cros_hardened_noccache_golden/clangtidy.json
@@ -27,7 +27,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
@@ -141,7 +141,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
@@ -258,7 +258,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
@@ -379,7 +379,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
diff --git a/compiler_wrapper/testdata/cros_nonhardened_golden/clangtidy.json b/compiler_wrapper/testdata/cros_nonhardened_golden/clangtidy.json
index 3d5078df..830abee6 100644
--- a/compiler_wrapper/testdata/cros_nonhardened_golden/clangtidy.json
+++ b/compiler_wrapper/testdata/cros_nonhardened_golden/clangtidy.json
@@ -27,7 +27,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
@@ -127,7 +127,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
@@ -230,7 +230,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",
@@ -337,7 +337,7 @@
"path": "../../usr/bin/clang-tidy",
"args": [
"-checks=*,-bugprone-narrowing-conversions,-cppcoreguidelines-*,-fuchsia-*,-google-readability*,-google-runtime-references,-hicpp-*,-llvm-*,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-*,-readability-*",
- "",
+ "main.cc",
"--",
"-resource-dir=someResourceDir",
"--sysroot=/usr/x86_64-cros-linux-gnu",