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_BUILD_WRITER_H_
6#define TOOLS_GN_NINJA_BUILD_WRITER_H_
7
8#include <iosfwd>
9#include <vector>
10
11#include "tools/gn/ninja_helper.h"
12#include "tools/gn/path_output.h"
13
14class BuildSettings;
15class Settings;
16class Target;
17
18// Generates the toplevel "build.ninja" file. This references the individual
19// toolchain files and lists all input .gn files as dependencies of the
20// build itself.
21class NinjaBuildWriter {
22 public:
23  static bool RunAndWriteFile(
24      const BuildSettings* settings,
25      const std::vector<const Settings*>& all_settings,
26      const std::vector<const Target*>& default_toolchain_targets);
27
28 private:
29  NinjaBuildWriter(const BuildSettings* settings,
30                   const std::vector<const Settings*>& all_settings,
31                   const std::vector<const Target*>& default_toolchain_targets,
32                   std::ostream& out);
33  ~NinjaBuildWriter();
34
35  void Run();
36
37  void WriteNinjaRules();
38  void WriteSubninjas();
39  void WritePhonyAndAllRules();
40
41  const BuildSettings* build_settings_;
42  std::vector<const Settings*> all_settings_;
43  std::vector<const Target*> default_toolchain_targets_;
44  std::ostream& out_;
45  PathOutput path_output_;
46
47  NinjaHelper helper_;
48
49  DISALLOW_COPY_AND_ASSIGN(NinjaBuildWriter);
50};
51
52#endif  // TOOLS_GN_NINJA_BUILD_GENERATOR_H_
53
54