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 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
29 #include <windows.h> | 29 #include <windows.h> |
30 #endif | 30 #endif |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 std::string GetSelfInvocationCommand(const BuildSettings* build_settings) { | 34 std::string GetSelfInvocationCommand(const BuildSettings* build_settings) { |
35 base::FilePath executable; | 35 base::FilePath executable; |
36 PathService::Get(base::FILE_EXE, &executable); | 36 PathService::Get(base::FILE_EXE, &executable); |
37 | 37 |
38 CommandLine cmdline(executable.NormalizePathSeparatorsTo('/')); | 38 base::CommandLine cmdline(executable.NormalizePathSeparatorsTo('/')); |
39 cmdline.AppendArg("gen"); | 39 cmdline.AppendArg("gen"); |
40 cmdline.AppendArg(build_settings->build_dir().value()); | 40 cmdline.AppendArg(build_settings->build_dir().value()); |
41 cmdline.AppendSwitchPath(std::string("--") + switches::kRoot, | 41 cmdline.AppendSwitchPath(std::string("--") + switches::kRoot, |
42 build_settings->root_path()); | 42 build_settings->root_path()); |
43 // Successful automatic invocations shouldn't print output. | 43 // Successful automatic invocations shouldn't print output. |
44 cmdline.AppendSwitch(std::string("-") + switches::kQuiet); | 44 cmdline.AppendSwitch(std::string("-") + switches::kQuiet); |
45 | 45 |
46 EscapeOptions escape_shell; | 46 EscapeOptions escape_shell; |
47 escape_shell.mode = ESCAPE_NINJA_COMMAND; | 47 escape_shell.mode = ESCAPE_NINJA_COMMAND; |
48 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
49 // The command line code quoting varies by platform. We have one string, | 49 // The command line code quoting varies by platform. We have one string, |
50 // possibly with spaces, that we want to quote. The Windows command line | 50 // possibly with spaces, that we want to quote. The Windows command line |
51 // quotes again, so we don't want quoting. The Posix one doesn't. | 51 // quotes again, so we don't want quoting. The Posix one doesn't. |
52 escape_shell.inhibit_quoting = true; | 52 escape_shell.inhibit_quoting = true; |
53 #endif | 53 #endif |
54 | 54 |
55 const CommandLine& our_cmdline = *CommandLine::ForCurrentProcess(); | 55 const base::CommandLine& our_cmdline = |
56 const CommandLine::SwitchMap& switches = our_cmdline.GetSwitches(); | 56 *base::CommandLine::ForCurrentProcess(); |
57 for (CommandLine::SwitchMap::const_iterator i = switches.begin(); | 57 const base::CommandLine::SwitchMap& switches = our_cmdline.GetSwitches(); |
| 58 for (base::CommandLine::SwitchMap::const_iterator i = switches.begin(); |
58 i != switches.end(); ++i) { | 59 i != switches.end(); ++i) { |
59 // Only write arguments we haven't already written. Always skip "args" | 60 // Only write arguments we haven't already written. Always skip "args" |
60 // since those will have been written to the file and will be used | 61 // since those will have been written to the file and will be used |
61 // implicitly in the future. Keeping --args would mean changes to the file | 62 // implicitly in the future. Keeping --args would mean changes to the file |
62 // would be ignored. | 63 // would be ignored. |
63 if (i->first != switches::kQuiet && | 64 if (i->first != switches::kQuiet && |
64 i->first != switches::kRoot && | 65 i->first != switches::kRoot && |
65 i->first != switches::kArgs) { | 66 i->first != switches::kArgs) { |
66 std::string escaped_value = | 67 std::string escaped_value = |
67 EscapeString(FilePathToUTF8(i->second), escape_shell, NULL); | 68 EscapeString(FilePathToUTF8(i->second), escape_shell, NULL); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 EscapeOptions ninja_escape; | 289 EscapeOptions ninja_escape; |
289 ninja_escape.mode = ESCAPE_NINJA; | 290 ninja_escape.mode = ESCAPE_NINJA; |
290 | 291 |
291 // Escape for special chars Ninja will handle. | 292 // Escape for special chars Ninja will handle. |
292 std::string escaped = EscapeString(phony_name, ninja_escape, NULL); | 293 std::string escaped = EscapeString(phony_name, ninja_escape, NULL); |
293 | 294 |
294 out_ << "build " << escaped << ": phony "; | 295 out_ << "build " << escaped << ": phony "; |
295 path_output_.WriteFile(out_, target_file); | 296 path_output_.WriteFile(out_, target_file); |
296 out_ << std::endl; | 297 out_ << std::endl; |
297 } | 298 } |
OLD | NEW |