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.
5 #ifndef TOOLS_GN_NINJA_TARGET_WRITER_H_
6 #define TOOLS_GN_NINJA_TARGET_WRITER_H_
10 #include "base/basictypes.h"
11 #include "tools/gn/ninja_helper.h"
12 #include "tools/gn/path_output.h"
18 // Generates one target's ".ninja" file. The toplevel "build.ninja" file is
19 // generated by the NinjaBuildWriter.
20 class NinjaTargetWriter
{
22 NinjaTargetWriter(const Target
* target
,
23 const Toolchain
* toolchain
,
25 virtual ~NinjaTargetWriter();
27 static void RunAndWriteFile(const Target
* target
, const Toolchain
* toolchain
);
29 virtual void Run() = 0;
32 // Writes to the output stream a stamp rule for input dependencies, and
33 // returns the string to be appended to source rules that encodes the
34 // order-only dependencies for the current target. This will include the "|"
35 // character so can just be appended to the source rules. If there are no
36 // implicit dependencies and no extra target dependencies passed in, returns
38 std::string
WriteInputDepsStampAndGetDep(
39 const std::vector
<const Target
*>& extra_hard_deps
) const;
41 // Returns the FileTemplate constructed from the outputs variable. This is
42 // like FileTemplate::GetForTargetOutputs except this additionally trims the
43 // build directory from the front so we can just write the names without
44 // further processing.
45 FileTemplate
GetOutputTemplate() const;
47 const Settings
* settings_
; // Non-owning.
48 const Target
* target_
; // Non-owning.
49 const Toolchain
* toolchain_
; // Non-owning.
51 PathOutput path_output_
;
56 void WriteCopyRules();
58 DISALLOW_COPY_AND_ASSIGN(NinjaTargetWriter
);
61 #endif // TOOLS_GN_NINJA_TARGET_WRITER_H_