blob: 5e6827d550950e990c31fa859537d7b0265edfa1 [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 <string>
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "tools/gn/filesystem_utils.h"
#include "tools/gn/ninja_helper.h"
#include "tools/gn/path_output.h"
#include "tools/gn/settings.h"
class Target;
// Generates one target's ".ninja" file. The toplevel "" file is
// generated by the NinjaBuildGenerator.
class NinjaTargetWriter {
NinjaTargetWriter(const Target* target, std::ostream& out);
void Run();
static void RunAndWriteFile(const Target* target);
void WriteCopyRules();
void WriteCustomRules();
void WriteCustomArg(const std::string& arg);
// Writs the rules for compiling each source, writing all output files
// to the given vector.
// common_deps is a precomputed string of all ninja files that are common
// to each build step. This is added to each one.
void WriteCustomSourceRules(const std::string& custom_rule_name,
const std::string& common_deps,
const SourceDir& script_cd,
const std::string& script_cd_to_root,
std::vector<OutputFile>* output_files);
void WriteCompilerVars();
void WriteSources(std::vector<OutputFile>* object_files);
void WriteLinkerStuff(const std::vector<OutputFile>& object_files);
// Returns NULL if the source type should not be compiled on this target.
const char* GetCommandForSourceType(SourceFileType type) const;
const char* GetCommandForTargetType() const;
const Settings* settings_; // Non-owning.
const Target* target_; // Non-owning.
std::ostream& out_;
PathOutput path_output_;
NinjaHelper helper_;