• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/compiler_specific.h"
9 #include "tools/gn/config_values.h"
10 #include "tools/gn/ninja_target_writer.h"
11 #include "tools/gn/toolchain.h"
12 #include "tools/gn/unique_vector.h"
13 
14 struct EscapeOptions;
15 
16 // Writes a .ninja file for a binary target type (an executable, a shared
17 // library, or a static library).
18 class NinjaBinaryTargetWriter : public NinjaTargetWriter {
19  public:
20   NinjaBinaryTargetWriter(const Target* target, std::ostream& out);
21   virtual ~NinjaBinaryTargetWriter();
22 
23   virtual void Run() OVERRIDE;
24 
25  private:
26   typedef std::set<OutputFile> OutputFileSet;
27 
28   void WriteCompilerVars();
29   void WriteSources(std::vector<OutputFile>* object_files);
30   void WriteLinkerStuff(const std::vector<OutputFile>& object_files);
31   void WriteLinkerFlags();
32   void WriteLibs();
33   void WriteOutputExtension();
34   void WriteSolibs(const std::vector<OutputFile>& solibs);
35 
36   // Writes the stamp line for a source set. These are not linked.
37   void WriteSourceSetStamp(const std::vector<OutputFile>& object_files);
38 
39   // Gets all target dependencies and classifies them, as well as accumulates
40   // object files from source sets we need to link.
41   void GetDeps(UniqueVector<OutputFile>* extra_object_files,
42                UniqueVector<const Target*>* linkable_deps,
43                UniqueVector<const Target*>* non_linkable_deps) const;
44 
45   // Classifies the dependency as linkable or nonlinkable with the current
46   // target, adding it to the appropriate vector. If the dependency is a source
47   // set we should link in, the source set's object files will be appended to
48   // |extra_object_files|.
49   void ClassifyDependency(const Target* dep,
50                           UniqueVector<OutputFile>* extra_object_files,
51                           UniqueVector<const Target*>* linkable_deps,
52                           UniqueVector<const Target*>* non_linkable_deps) const;
53 
54   // Writes the implicit dependencies for the link or stamp line. This is
55   // the "||" and everything following it on the ninja line.
56   //
57   // The order-only dependencies are the non-linkable deps passed in as an
58   // argument, plus the data file depdencies in the target.
59   void WriteOrderOnlyDependencies(
60       const UniqueVector<const Target*>& non_linkable_deps);
61 
62   // Computes the set of output files resulting from compiling the given source
63   // file. If the file can be compiled and the tool exists, fills the outputs in
64   // and writes the tool type to computed_tool_type. If the file is not
65   // compilable, returns false.
66   //
67   // The target that the source belongs to is passed as an argument. In the
68   // case of linking to source sets, this can be different than the target
69   // this class is currently writing.
70   //
71   // The function can succeed with a "NONE" tool type for object files which are
72   // just passed to the output. The output will always be overwritten, not
73   // appended to.
74   bool GetOutputFilesForSource(const Target* target,
75                                const SourceFile& source,
76                                Toolchain::ToolType* computed_tool_type,
77                                std::vector<OutputFile>* outputs) const;
78 
79   const Tool* tool_;
80 
81   DISALLOW_COPY_AND_ASSIGN(NinjaBinaryTargetWriter);
82 };
83 
84 #endif  // TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_
85 
86