1 // Copyright (c) 2013 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_NINJA_BINARY_TARGET_WRITER_H_ 6 #define TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_ 7 8 #include "base/macros.h" 9 #include "gn/c_tool.h" 10 #include "gn/config_values.h" 11 #include "gn/ninja_target_writer.h" 12 #include "gn/toolchain.h" 13 #include "gn/unique_vector.h" 14 15 struct EscapeOptions; 16 17 // Writes a .ninja file for a binary target type (an executable, a shared 18 // library, or a static library). 19 class NinjaBinaryTargetWriter : public NinjaTargetWriter { 20 public: 21 NinjaBinaryTargetWriter(const Target* target, std::ostream& out); 22 ~NinjaBinaryTargetWriter() override; 23 24 void Run() override; 25 26 protected: 27 // Writes to the output stream a stamp rule for inputs, and 28 // returns the file to be appended to source rules that encodes the 29 // implicit dependencies for the current target. The returned OutputFile 30 // will be empty if there are no inputs. 31 OutputFile WriteInputsStampAndGetDep() const; 32 33 // Writes the stamp line for a source set. These are not linked. 34 void WriteSourceSetStamp(const std::vector<OutputFile>& object_files); 35 36 // Gets all target dependencies and classifies them, as well as accumulates 37 // object files from source sets we need to link. 38 void GetDeps(UniqueVector<OutputFile>* extra_object_files, 39 UniqueVector<const Target*>* linkable_deps, 40 UniqueVector<const Target*>* non_linkable_deps, 41 UniqueVector<const Target*>* framework_deps) const; 42 43 // Classifies the dependency as linkable or nonlinkable with the current 44 // target, adding it to the appropriate vector. If the dependency is a source 45 // set we should link in, the source set's object files will be appended to 46 // |extra_object_files|. 47 void ClassifyDependency(const Target* dep, 48 UniqueVector<OutputFile>* extra_object_files, 49 UniqueVector<const Target*>* linkable_deps, 50 UniqueVector<const Target*>* non_linkable_deps, 51 UniqueVector<const Target*>* framework_deps) const; 52 53 OutputFile WriteStampAndGetDep(const UniqueVector<const SourceFile*>& files, 54 const std::string& stamp_ext) const; 55 56 void WriteCompilerBuildLine(const SourceFile& source, 57 const std::vector<OutputFile>& extra_deps, 58 const std::vector<OutputFile>& order_only_deps, 59 const char* tool_name, 60 const std::vector<OutputFile>& outputs); 61 62 void WriteLinkerFlags(std::ostream& out, 63 const Tool* tool, 64 const SourceFile* optional_def_file); 65 void WriteLibs(std::ostream& out, const Tool* tool); 66 void WriteFrameworks(std::ostream& out, const Tool* tool); 67 68 virtual void AddSourceSetFiles(const Target* source_set, 69 UniqueVector<OutputFile>* obj_files) const; 70 71 // Cached version of the prefix used for rule types for this toolchain. 72 std::string rule_prefix_; 73 74 private: 75 DISALLOW_COPY_AND_ASSIGN(NinjaBinaryTargetWriter); 76 }; 77 78 #endif // TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_ 79