OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/ninja_build_writer.h" | 5 #include "tools/gn/ninja_build_writer.h" |
6 | 6 |
7 #include <fstream> | 7 #include <fstream> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/process/process_handle.h" | 11 #include "base/process/process_handle.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "tools/gn/build_settings.h" | 14 #include "tools/gn/build_settings.h" |
| 15 #include "tools/gn/escape.h" |
15 #include "tools/gn/filesystem_utils.h" | 16 #include "tools/gn/filesystem_utils.h" |
16 #include "tools/gn/input_file_manager.h" | 17 #include "tools/gn/input_file_manager.h" |
17 #include "tools/gn/scheduler.h" | 18 #include "tools/gn/scheduler.h" |
18 #include "tools/gn/target.h" | 19 #include "tools/gn/target.h" |
19 | 20 |
20 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
21 #include <windows.h> | 22 #include <windows.h> |
22 #endif | 23 #endif |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 std::string GetSelfInvocationCommand(const BuildSettings* build_settings) { | 27 std::string GetSelfInvocationCommand(const BuildSettings* build_settings) { |
27 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
28 wchar_t module[MAX_PATH]; | 29 wchar_t module[MAX_PATH]; |
29 GetModuleFileName(NULL, module, MAX_PATH); | 30 GetModuleFileName(NULL, module, MAX_PATH); |
30 //result = "\"" + WideToUTF8(module) + "\""; | 31 //result = "\"" + WideToUTF8(module) + "\""; |
31 base::FilePath executable(module); | 32 base::FilePath executable(module); |
32 #elif defined(OS_MACOSX) | 33 #elif defined(OS_MACOSX) |
33 // FIXME(brettw) write this on Mac! | 34 // FIXME(brettw) write this on Mac! |
34 base::FilePath executable("gn"); | 35 base::FilePath executable("../Debug/gn"); |
35 #else | 36 #else |
36 base::FilePath executable = | 37 base::FilePath executable = |
37 base::GetProcessExecutablePath(base::GetCurrentProcessHandle()); | 38 base::GetProcessExecutablePath(base::GetCurrentProcessHandle()); |
38 #endif | 39 #endif |
39 | 40 |
40 /* | 41 /* |
41 // Append the root path. | 42 // Append the root path. |
42 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 43 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
43 result += " --root=\"" + FilePathToUTF8(settings->root_path()) + "\""; | 44 result += " --root=\"" + FilePathToUTF8(settings->root_path()) + "\""; |
44 */ | 45 */ |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 102 } |
102 | 103 |
103 void NinjaBuildWriter::WriteNinjaRules() { | 104 void NinjaBuildWriter::WriteNinjaRules() { |
104 out_ << "rule gn\n"; | 105 out_ << "rule gn\n"; |
105 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n"; | 106 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n"; |
106 out_ << " description = GN the world\n\n"; | 107 out_ << " description = GN the world\n\n"; |
107 | 108 |
108 out_ << "build build.ninja: gn"; | 109 out_ << "build build.ninja: gn"; |
109 | 110 |
110 // Input build files. | 111 // Input build files. |
111 std::vector<SourceFile> input_files; | 112 std::vector<base::FilePath> input_files; |
112 g_scheduler->input_file_manager()->GetAllInputFileNames(&input_files); | 113 g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files); |
113 for (size_t i = 0; i < input_files.size(); i++) { | 114 EscapeOptions ninja_options; |
114 out_ << " "; | 115 ninja_options.mode = ESCAPE_NINJA; |
115 path_output_.WriteFile(out_, input_files[i]); | 116 for (size_t i = 0; i < input_files.size(); i++) |
116 } | 117 out_ << " " << EscapeString(FilePathToUTF8(input_files[i]), ninja_options); |
117 | 118 |
118 // Other files read by the build. | 119 // Other files read by the build. |
119 std::vector<SourceFile> other_files = g_scheduler->GetGenDependencies(); | 120 std::vector<SourceFile> other_files = g_scheduler->GetGenDependencies(); |
120 for (size_t i = 0; i < other_files.size(); i++) { | 121 for (size_t i = 0; i < other_files.size(); i++) { |
121 out_ << " "; | 122 out_ << " "; |
122 path_output_.WriteFile(out_, other_files[i]); | 123 path_output_.WriteFile(out_, other_files[i]); |
123 } | 124 } |
124 | 125 |
125 out_ << std::endl << std::endl; | 126 out_ << std::endl << std::endl; |
126 } | 127 } |
(...skipping 29 matching lines...) Expand all Loading... |
156 all_rules.append(" $\n "); | 157 all_rules.append(" $\n "); |
157 all_rules.append(target_file.value()); | 158 all_rules.append(target_file.value()); |
158 } | 159 } |
159 | 160 |
160 if (!all_rules.empty()) { | 161 if (!all_rules.empty()) { |
161 out_ << "\nbuild all: phony " << all_rules << std::endl; | 162 out_ << "\nbuild all: phony " << all_rules << std::endl; |
162 out_ << "default all" << std::endl; | 163 out_ << "default all" << std::endl; |
163 } | 164 } |
164 } | 165 } |
165 | 166 |
OLD | NEW |