// Copyright 2014 The Bazel Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.devtools.build.lib.rules.cpp; import com.google.common.annotations.VisibleForTesting; import com.google.devtools.build.lib.util.io.FileOutErr; import com.google.devtools.build.lib.vfs.Path; import java.io.ByteArrayOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; /** * A Class for filtering the output of /showIncludes from MSVC compiler. * *
A discovered header file will be printed with prefix "Note: including file:", the path is * collected, and the line is suppressed from the actual output users can see. * *
Also suppress the basename of source file, which is printed unconditionally by MSVC compiler,
* there is no way to turn it off.
*/
public class ShowIncludesFilter implements FileOutErr.OutputFilter {
private FilterShowIncludesOutputStream filterShowIncludesOutputStream;
private final String sourceFileName;
public ShowIncludesFilter(String sourceFileName) {
this.sourceFileName = sourceFileName;
}
/**
* Use this class to filter and collect the headers discovered by MSVC compiler, also filter out
* the source file name printed unconditionally by the compiler.
*/
public static class FilterShowIncludesOutputStream extends FilterOutputStream {
private final ByteArrayOutputStream buffer = new ByteArrayOutputStream(4096);
private final Collection