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/path_output.h" | 5 #include "tools/gn/path_output.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "tools/gn/filesystem_utils.h" | 8 #include "tools/gn/filesystem_utils.h" |
9 #include "tools/gn/output_file.h" | 9 #include "tools/gn/output_file.h" |
10 #include "tools/gn/string_utils.h" | 10 #include "tools/gn/string_utils.h" |
11 | 11 |
12 PathOutput::PathOutput(const SourceDir& current_dir, | 12 PathOutput::PathOutput(const SourceDir& current_dir, EscapingMode escaping) |
13 EscapingMode escaping, | |
14 bool convert_slashes) | |
15 : current_dir_(current_dir) { | 13 : current_dir_(current_dir) { |
16 CHECK(current_dir.is_source_absolute()) | 14 CHECK(current_dir.is_source_absolute()) |
17 << "Currently this only supports writing to output directories inside " | 15 << "Currently this only supports writing to output directories inside " |
18 "the source root. There needs to be some tweaks to PathOutput to make " | 16 "the source root. There needs to be some tweaks to PathOutput to make " |
19 "doing this work correctly."; | 17 "doing this work correctly."; |
20 inverse_current_dir_ = InvertDir(current_dir_); | 18 inverse_current_dir_ = InvertDir(current_dir_); |
21 | 19 |
22 options_.mode = escaping; | 20 options_.mode = escaping; |
23 options_.convert_slashes = convert_slashes; | |
24 options_.inhibit_quoting = false; | |
25 | |
26 if (convert_slashes) | |
27 ConvertPathToSystem(&inverse_current_dir_); | |
28 } | 21 } |
29 | 22 |
30 PathOutput::~PathOutput() { | 23 PathOutput::~PathOutput() { |
31 } | 24 } |
32 | 25 |
33 void PathOutput::WriteFile(std::ostream& out, const SourceFile& file) const { | 26 void PathOutput::WriteFile(std::ostream& out, const SourceFile& file) const { |
34 WritePathStr(out, file.value()); | 27 WritePathStr(out, file.value()); |
35 } | 28 } |
36 | 29 |
37 void PathOutput::WriteDir(std::ostream& out, | 30 void PathOutput::WriteDir(std::ostream& out, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 77 |
85 void PathOutput::WriteFile(std::ostream& out, | 78 void PathOutput::WriteFile(std::ostream& out, |
86 const base::FilePath& file) const { | 79 const base::FilePath& file) const { |
87 // Assume native file paths are always absolute. | 80 // Assume native file paths are always absolute. |
88 EscapeStringToStream(out, FilePathToUTF8(file), options_); | 81 EscapeStringToStream(out, FilePathToUTF8(file), options_); |
89 } | 82 } |
90 | 83 |
91 void PathOutput::WriteSourceRelativeString( | 84 void PathOutput::WriteSourceRelativeString( |
92 std::ostream& out, | 85 std::ostream& out, |
93 const base::StringPiece& str) const { | 86 const base::StringPiece& str) const { |
94 if (options_.mode == ESCAPE_SHELL) { | 87 if (options_.mode == ESCAPE_NINJA_COMMAND) { |
95 // Shell escaping needs an intermediate string since it may end up | 88 // Shell escaping needs an intermediate string since it may end up |
96 // quoting the whole thing. On Windows, the slashes may already be | 89 // quoting the whole thing. |
97 // converted to backslashes in inverse_current_dir_, but we assume that on | |
98 // Windows the escaper won't try to then escape the preconverted | |
99 // backslashes and will just pass them, so this is fine. | |
100 std::string intermediate; | 90 std::string intermediate; |
101 intermediate.reserve(inverse_current_dir_.size() + str.size()); | 91 intermediate.reserve(inverse_current_dir_.size() + str.size()); |
102 intermediate.assign(inverse_current_dir_.c_str(), | 92 intermediate.assign(inverse_current_dir_.c_str(), |
103 inverse_current_dir_.size()); | 93 inverse_current_dir_.size()); |
104 intermediate.append(str.data(), str.size()); | 94 intermediate.append(str.data(), str.size()); |
105 | 95 |
106 EscapeStringToStream(out, | 96 EscapeStringToStream(out, |
107 base::StringPiece(intermediate.c_str(), intermediate.size()), | 97 base::StringPiece(intermediate.c_str(), intermediate.size()), |
108 options_); | 98 options_); |
109 } else { | 99 } else { |
(...skipping 21 matching lines...) Expand all Loading... |
131 // it's system-absolute. | 121 // it's system-absolute. |
132 #if defined(OS_WIN) | 122 #if defined(OS_WIN) |
133 // On Windows, trim the leading slash, since the input for absolute | 123 // On Windows, trim the leading slash, since the input for absolute |
134 // paths will look like "/C:/foo/bar.txt". | 124 // paths will look like "/C:/foo/bar.txt". |
135 EscapeStringToStream(out, str.substr(1), options_); | 125 EscapeStringToStream(out, str.substr(1), options_); |
136 #else | 126 #else |
137 EscapeStringToStream(out, str, options_); | 127 EscapeStringToStream(out, str, options_); |
138 #endif | 128 #endif |
139 } | 129 } |
140 } | 130 } |
OLD | NEW |