blob: 51e3ba160463f8d75ee0cf3567eb8722eee22fd5 [file] [log] [blame]
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <iosfwd>
#include "base/basictypes.h"
#include "tools/gn/ninja_helper.h"
#include "tools/gn/path_output.h"
class FileTemplate;
class Settings;
class Target;
// Generates one target's ".ninja" file. The toplevel "" file is
// generated by the NinjaBuildWriter.
class NinjaTargetWriter {
NinjaTargetWriter(const Target* target,
const Toolchain* toolchain,
std::ostream& out);
virtual ~NinjaTargetWriter();
static void RunAndWriteFile(const Target* target, const Toolchain* toolchain);
virtual void Run() = 0;
// Writes to the output stream a stamp rule for input dependencies, and
// returns the string to be appended to source rules that encodes the
// order-only dependencies for the current target. This will include the "|"
// character so can just be appended to the source rules. If there are no
// implicit dependencies and no extra target dependencies passed in, returns
// the empty string.
std::string WriteInputDepsStampAndGetDep(
const std::vector<const Target*>& extra_hard_deps) const;
// Returns the FileTemplate constructed from the outputs variable. This is
// like FileTemplate::GetForTargetOutputs except this additionally trims the
// build directory from the front so we can just write the names without
// further processing.
FileTemplate GetOutputTemplate() const;
const Settings* settings_; // Non-owning.
const Target* target_; // Non-owning.
const Toolchain* toolchain_; // Non-owning.
std::ostream& out_;
PathOutput path_output_;
NinjaHelper helper_;
void WriteCopyRules();