From abf3905c8b3bcf2820bccb54180eeed968e3ed2e Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 13 Sep 2019 07:38:48 -0700 Subject: [PATCH] Handle -iquote in copt We need to parse copt for -iquote paths and pass them to the include scanner. This mirrors what we already do for -I paths. Note currently objc_library documentation (see [] recommends use of -iquote while cc_library documentaiton recommends ([] While we're at it, sanity check the include path, and add/fix a couple tests. RELNOTES: None PiperOrigin-RevId: 268902183 --- .../build/lib/rules/cpp/CppCompileAction.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java index 4c16242c20b626..e4103626cc43b7 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java @@ -639,7 +639,23 @@ public CcCompilationContext getCcCompilationContext() { @Override public List getQuoteIncludeDirs() { - return ccCompilationContext.getQuoteIncludeDirs(); + ImmutableList.Builder result = ImmutableList.builder(); + result.addAll(ccCompilationContext.getQuoteIncludeDirs()); + ImmutableList copts = compileCommandLine.getCopts(); + for (int i = 0; i < copts.size(); i++) { + String opt = copts.get(i); + if (opt.startsWith("-iquote")) { + if (opt.length() > 7) { + result.add(PathFragment.create(opt.substring(7).trim())); + } else if (i + 1 < copts.size()) { + i++; + result.add(PathFragment.create(copts.get(i))); + } else { + System.err.println("WARNING: dangling -iquote flag in options for " + prettyPrint()); + } + } + } + return result.build(); } @Override @@ -920,13 +936,11 @@ void verifyActionIncludePaths(List systemIncludeDirs) throws ActionExecutionException { ImmutableSet ignoredDirs = ImmutableSet.copyOf(getValidationIgnoredDirs()); // We currently do not check the output of: - // - getQuoteIncludeDirs(): those only come from includes attributes, and are checked in - // CcCommon.getIncludeDirsFromIncludesAttribute(). // - getBuiltinIncludeDirs(): while in practice this doesn't happen, bazel can be configured // to use an absolute system root, in which case the builtin include dirs might be absolute. Iterable includePathsToVerify = - Iterables.concat(getIncludeDirs(), systemIncludeDirs); + Iterables.concat(getIncludeDirs(), getQuoteIncludeDirs(), systemIncludeDirs); for (PathFragment includePath : includePathsToVerify) { // includePathsToVerify contains all paths that are added as -isystem directive on the command // line, most of which are added for include directives in the CcCompilationContext and are