1695b41eeSopenharmony_ci// Copyright 2015 Google Inc. All Rights Reserved.
2695b41eeSopenharmony_ci//
3695b41eeSopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
4695b41eeSopenharmony_ci// you may not use this file except in compliance with the License.
5695b41eeSopenharmony_ci// You may obtain a copy of the License at
6695b41eeSopenharmony_ci//
7695b41eeSopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
8695b41eeSopenharmony_ci//
9695b41eeSopenharmony_ci// Unless required by applicable law or agreed to in writing, software
10695b41eeSopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
11695b41eeSopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12695b41eeSopenharmony_ci// See the License for the specific language governing permissions and
13695b41eeSopenharmony_ci// limitations under the License.
14695b41eeSopenharmony_ci
15695b41eeSopenharmony_ci#ifndef NINJA_CLPARSER_H_
16695b41eeSopenharmony_ci#define NINJA_CLPARSER_H_
17695b41eeSopenharmony_ci
18695b41eeSopenharmony_ci#include <set>
19695b41eeSopenharmony_ci#include <string>
20695b41eeSopenharmony_ci
21695b41eeSopenharmony_ci/// Visual Studio's cl.exe requires some massaging to work with Ninja;
22695b41eeSopenharmony_ci/// for example, it emits include information on stderr in a funny
23695b41eeSopenharmony_ci/// format when building with /showIncludes.  This class parses this
24695b41eeSopenharmony_ci/// output.
25695b41eeSopenharmony_cistruct CLParser {
26695b41eeSopenharmony_ci  /// Parse a line of cl.exe output and extract /showIncludes info.
27695b41eeSopenharmony_ci  /// If a dependency is extracted, returns a nonempty string.
28695b41eeSopenharmony_ci  /// Exposed for testing.
29695b41eeSopenharmony_ci  static std::string FilterShowIncludes(const std::string& line,
30695b41eeSopenharmony_ci                                        const std::string& deps_prefix);
31695b41eeSopenharmony_ci
32695b41eeSopenharmony_ci  /// Return true if a mentioned include file is a system path.
33695b41eeSopenharmony_ci  /// Filtering these out reduces dependency information considerably.
34695b41eeSopenharmony_ci  static bool IsSystemInclude(std::string path);
35695b41eeSopenharmony_ci
36695b41eeSopenharmony_ci  /// Parse a line of cl.exe output and return true if it looks like
37695b41eeSopenharmony_ci  /// it's printing an input filename.  This is a heuristic but it appears
38695b41eeSopenharmony_ci  /// to be the best we can do.
39695b41eeSopenharmony_ci  /// Exposed for testing.
40695b41eeSopenharmony_ci  static bool FilterInputFilename(std::string line);
41695b41eeSopenharmony_ci
42695b41eeSopenharmony_ci  /// Parse the full output of cl, filling filtered_output with the text that
43695b41eeSopenharmony_ci  /// should be printed (if any). Returns true on success, or false with err
44695b41eeSopenharmony_ci  /// filled. output must not be the same object as filtered_object.
45695b41eeSopenharmony_ci  bool Parse(const std::string& output, const std::string& deps_prefix,
46695b41eeSopenharmony_ci             std::string* filtered_output, std::string* err);
47695b41eeSopenharmony_ci
48695b41eeSopenharmony_ci  std::set<std::string> includes_;
49695b41eeSopenharmony_ci};
50695b41eeSopenharmony_ci
51695b41eeSopenharmony_ci#endif  // NINJA_CLPARSER_H_
52