blob: 72ecbcad0c81e5c23183ad8dc75618b6b7ce9963 [file] [log] [blame]
[email protected]96ea63d2013-07-30 10:17:071// 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]96ea63d2013-07-30 10:17:079
tfarinaf51a763e2015-08-10 00:55:3810#include "base/macros.h"
[email protected]96ea63d2013-07-30 10:17:0711#include "tools/gn/path_output.h"
andybons987f4a52015-10-28 13:40:3012#include "tools/gn/substitution_type.h"
[email protected]96ea63d2013-07-30 10:17:0713
[email protected]b90c75a2013-09-18 22:02:5014class FileTemplate;
Brett Wilsona4e40582014-08-26 22:30:4615class OutputFile;
[email protected]9ce9b7f2013-08-16 12:28:5916class Settings;
[email protected]96ea63d2013-07-30 10:17:0717class Target;
tfarinaf51a763e2015-08-10 00:55:3818struct SubstitutionBits;
[email protected]96ea63d2013-07-30 10:17:0719
20// Generates one target's ".ninja" file. The toplevel "build.ninja" file is
[email protected]9ce9b7f2013-08-16 12:28:5921// generated by the NinjaBuildWriter.
[email protected]96ea63d2013-07-30 10:17:0722class NinjaTargetWriter {
23 public:
[email protected]0dfcae72014-08-19 22:52:1624 NinjaTargetWriter(const Target* target, std::ostream& out);
[email protected]c0822d7f2013-08-13 17:10:5625 virtual ~NinjaTargetWriter();
[email protected]96ea63d2013-07-30 10:17:0726
brettw8293c352016-07-26 20:38:3727 // 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]96ea63d2013-07-30 10:17:0735
[email protected]c0822d7f2013-08-13 17:10:5636 virtual void Run() = 0;
[email protected]96ea63d2013-07-30 10:17:0737
[email protected]c0822d7f2013-08-13 17:10:5638 protected:
[email protected]0dfcae72014-08-19 22:52:1639 // 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]ef348fe2014-05-01 18:31:3144 // Writes to the output stream a stamp rule for input dependencies, and
Brett Wilsona4e40582014-08-26 22:30:4645 // 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]3098afa2014-05-02 22:36:2950 const std::vector<const Target*>& extra_hard_deps) const;
[email protected]234be5202013-09-11 20:44:0251
[email protected]0dfcae72014-08-19 22:52:1652 // 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]96ea63d2013-07-30 10:17:0758 const Settings* settings_; // Non-owning.
59 const Target* target_; // Non-owning.
60 std::ostream& out_;
61 PathOutput path_output_;
62
[email protected]c0822d7f2013-08-13 17:10:5663 private:
64 void WriteCopyRules();
andybons987f4a52015-10-28 13:40:3065 void WriteEscapedSubstitution(SubstitutionType type);
[email protected]c0822d7f2013-08-13 17:10:5666
[email protected]96ea63d2013-07-30 10:17:0767 DISALLOW_COPY_AND_ASSIGN(NinjaTargetWriter);
68};
69
70#endif // TOOLS_GN_NINJA_TARGET_WRITER_H_