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 "gn/err.h" 9 #include "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 30 static std::string RenderJSON(const BuildSettings* build_settings, 31 std::vector<const Target*>& all_targets); 32 33 static std::vector<const Target*> FilterTargets( 34 const std::vector<const Target*>& all_targets, 35 const std::set<std::string>& target_filters_set); 36 37 private: 38 // This function visits the deps graph of a target in a DFS fashion. 39 static void VisitDeps(const Target* target, TargetSet* visited); 40 }; 41 42 #endif // TOOLS_GN_COMPILE_COMMANDS_WRITER_H_ 43