[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 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_TARGET_WRITER_H_ | ||||
6 | #define TOOLS_GN_NINJA_TARGET_WRITER_H_ | ||||
7 | |||||
8 | #include <iosfwd> | ||||
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 9 | |
tfarina | f51a763e | 2015-08-10 00:55:38 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 11 | #include "tools/gn/path_output.h" |
andybons | 987f4a5 | 2015-10-28 13:40:30 | [diff] [blame] | 12 | #include "tools/gn/substitution_type.h" |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 13 | |
[email protected] | b90c75a | 2013-09-18 22:02:50 | [diff] [blame] | 14 | class FileTemplate; |
Brett Wilson | a4e4058 | 2014-08-26 22:30:46 | [diff] [blame] | 15 | class OutputFile; |
[email protected] | 9ce9b7f | 2013-08-16 12:28:59 | [diff] [blame] | 16 | class Settings; |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 17 | class Target; |
tfarina | f51a763e | 2015-08-10 00:55:38 | [diff] [blame] | 18 | struct SubstitutionBits; |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 19 | |
20 | // Generates one target's ".ninja" file. The toplevel "build.ninja" file is | ||||
[email protected] | 9ce9b7f | 2013-08-16 12:28:59 | [diff] [blame] | 21 | // generated by the NinjaBuildWriter. |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 22 | class NinjaTargetWriter { |
23 | public: | ||||
[email protected] | 0dfcae7 | 2014-08-19 22:52:16 | [diff] [blame] | 24 | NinjaTargetWriter(const Target* target, std::ostream& out); |
[email protected] | c0822d7f | 2013-08-13 17:10:56 | [diff] [blame] | 25 | virtual ~NinjaTargetWriter(); |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 26 | |
brettw | 8293c35 | 2016-07-26 20:38:37 | [diff] [blame] | 27 | // Returns the build line to be written to the toolchain build file. |
28 | // | ||||
29 | // Some targets have their rules written to separate files, and some can have | ||||
30 | // their rules coalesced in the main build file. For the coalesced case, this | ||||
31 | // function will return the rules as a string. For the separate file case, | ||||
32 | // the separate ninja file will be written and the return string will be the | ||||
33 | // subninja command to load that file. | ||||
34 | static std::string RunAndWriteFile(const Target* target); | ||||
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 35 | |
[email protected] | c0822d7f | 2013-08-13 17:10:56 | [diff] [blame] | 36 | virtual void Run() = 0; |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 37 | |
[email protected] | c0822d7f | 2013-08-13 17:10:56 | [diff] [blame] | 38 | protected: |
[email protected] | 0dfcae7 | 2014-08-19 22:52:16 | [diff] [blame] | 39 | // Writes out the substitution values that are shared between the different |
40 | // types of tools (target gen dir, target label, etc.). Only the substitutions | ||||
41 | // identified by the given bits will be written. | ||||
42 | void WriteSharedVars(const SubstitutionBits& bits); | ||||
43 | |||||
[email protected] | ef348fe | 2014-05-01 18:31:31 | [diff] [blame] | 44 | // Writes to the output stream a stamp rule for input dependencies, and |
Brett Wilson | a4e4058 | 2014-08-26 22:30:46 | [diff] [blame] | 45 | // returns the file to be appended to source rules that encodes the |
46 | // order-only dependencies for the current target. The returned OutputFile | ||||
47 | // will be empty if there are no implicit dependencies and no extra target | ||||
48 | // dependencies passed in. | ||||
49 | OutputFile WriteInputDepsStampAndGetDep( | ||||
[email protected] | 3098afa | 2014-05-02 22:36:29 | [diff] [blame] | 50 | const std::vector<const Target*>& extra_hard_deps) const; |
[email protected] | 234be520 | 2013-09-11 20:44:02 | [diff] [blame] | 51 | |
[email protected] | 0dfcae7 | 2014-08-19 22:52:16 | [diff] [blame] | 52 | // Writes to the output file a final stamp rule for the target that stamps |
53 | // the given list of files. This function assumes the stamp is for the target | ||||
54 | // as a whole so the stamp file is set as the target's dependency output. | ||||
55 | void WriteStampForTarget(const std::vector<OutputFile>& deps, | ||||
56 | const std::vector<OutputFile>& order_only_deps); | ||||
57 | |||||
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 58 | const Settings* settings_; // Non-owning. |
59 | const Target* target_; // Non-owning. | ||||
60 | std::ostream& out_; | ||||
61 | PathOutput path_output_; | ||||
62 | |||||
[email protected] | c0822d7f | 2013-08-13 17:10:56 | [diff] [blame] | 63 | private: |
64 | void WriteCopyRules(); | ||||
andybons | 987f4a5 | 2015-10-28 13:40:30 | [diff] [blame] | 65 | void WriteEscapedSubstitution(SubstitutionType type); |
[email protected] | c0822d7f | 2013-08-13 17:10:56 | [diff] [blame] | 66 | |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 67 | DISALLOW_COPY_AND_ASSIGN(NinjaTargetWriter); |
68 | }; | ||||
69 | |||||
70 | #endif // TOOLS_GN_NINJA_TARGET_WRITER_H_ |