1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef TOOLS_GN_COMPILE_COMMANDS_WRITER_H_
6 #define TOOLS_GN_COMPILE_COMMANDS_WRITER_H_
7 
8 #include "tools/gn/err.h"
9 #include "tools/gn/target.h"
10 
11 class Builder;
12 class BuildSettings;
13 
14 class CompileCommandsWriter {
15  public:
16   // Write compile commands into a json file located by parameter file_name.
17   //
18   // Parameter target_filters should be in "target_name1,target_name2..."
19   // format. If it is not empty, only targets that are reachable from targets
20   // in target_filters are used to generate compile commands.
21   //
22   // Parameter quiet is not used.
23   static bool RunAndWriteFiles(const BuildSettings* build_setting,
24                                const Builder& builder,
25                                const std::string& file_name,
26                                const std::string& target_filters,
27                                bool quiet,
28                                Err* err);
29   static void RenderJSON(const BuildSettings* build_settings,
30                          std::vector<const Target*>& all_targets,
31                          std::string* compile_commands);
32   static std::vector<const Target*> FilterTargets(
33       const std::vector<const Target*>& all_targets,
34       const std::set<std::string>& target_filters_set);
35 
36  private:
37   // This fuction visits the deps graph of a target in a DFS fashion.
38   static void VisitDeps(const Target* target, std::set<const Target*>* visited);
39 };
40 
41 #endif  // TOOLS_GN_COMPILE_COMMANDS_WRITER_H_
42