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/source_dir.h" | 5 #include "tools/gn/source_dir.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "tools/gn/filesystem_utils.h" | 8 #include "tools/gn/filesystem_utils.h" |
9 #include "tools/gn/source_file.h" | 9 #include "tools/gn/source_file.h" |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 *err = Err(p, "File path ends in a slash.", | 64 *err = Err(p, "File path ends in a slash.", |
65 "You specified the path\n " + str + "\n" | 65 "You specified the path\n " + str + "\n" |
66 "and it ends in a slash, indicating you think it's a directory." | 66 "and it ends in a slash, indicating you think it's a directory." |
67 "\nBut here you're supposed to be listing a file."); | 67 "\nBut here you're supposed to be listing a file."); |
68 return ret; | 68 return ret; |
69 } | 69 } |
70 | 70 |
71 if (str.size() >= 2 && str[0] == '/' && str[1] == '/') { | 71 if (str.size() >= 2 && str[0] == '/' && str[1] == '/') { |
72 // Source-relative. | 72 // Source-relative. |
73 ret.value_.assign(str.data(), str.size()); | 73 ret.value_.assign(str.data(), str.size()); |
74 NormalizePath(&ret.value_); | 74 NormalizePath(&ret.value_, source_root); |
75 return ret; | 75 return ret; |
76 } else if (IsPathAbsolute(str)) { | 76 } else if (IsPathAbsolute(str)) { |
77 if (source_root.empty() || | 77 if (source_root.empty() || |
78 !MakeAbsolutePathRelativeIfPossible(source_root, str, &ret.value_)) { | 78 !MakeAbsolutePathRelativeIfPossible(source_root, str, &ret.value_)) { |
79 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
80 // On Windows we'll accept "C:\foo" as an absolute path, which we want | 80 // On Windows we'll accept "C:\foo" as an absolute path, which we want |
81 // to convert to "/C:..." here. | 81 // to convert to "/C:..." here. |
82 if (str[0] != '/') | 82 if (str[0] != '/') |
83 ret.value_ = "/"; | 83 ret.value_ = "/"; |
84 #endif | 84 #endif |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 "You can't use empty strings as directories. " | 138 "You can't use empty strings as directories. " |
139 "That's just wrong."); | 139 "That's just wrong."); |
140 return ret; | 140 return ret; |
141 } | 141 } |
142 | 142 |
143 if (str.size() >= 2 && str[0] == '/' && str[1] == '/') { | 143 if (str.size() >= 2 && str[0] == '/' && str[1] == '/') { |
144 // Source-relative. | 144 // Source-relative. |
145 ret.value_.assign(str.data(), str.size()); | 145 ret.value_.assign(str.data(), str.size()); |
146 if (!EndsWithSlash(ret.value_)) | 146 if (!EndsWithSlash(ret.value_)) |
147 ret.value_.push_back('/'); | 147 ret.value_.push_back('/'); |
148 NormalizePath(&ret.value_); | 148 NormalizePath(&ret.value_, source_root); |
149 return ret; | 149 return ret; |
150 } else if (IsPathAbsolute(str)) { | 150 } else if (IsPathAbsolute(str)) { |
151 if (source_root.empty() || | 151 if (source_root.empty() || |
152 !MakeAbsolutePathRelativeIfPossible(source_root, str, &ret.value_)) { | 152 !MakeAbsolutePathRelativeIfPossible(source_root, str, &ret.value_)) { |
153 #if defined(OS_WIN) | 153 #if defined(OS_WIN) |
154 if (str[0] != '/') // See the file case for why we do this check. | 154 if (str[0] != '/') // See the file case for why we do this check. |
155 ret.value_ = "/"; | 155 ret.value_ = "/"; |
156 #endif | 156 #endif |
157 ret.value_.append(str.data(), str.size()); | 157 ret.value_.append(str.data(), str.size()); |
158 } | 158 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // String the double-leading slash for source-relative paths. | 210 // String the double-leading slash for source-relative paths. |
211 converted.assign(&value_[2], value_.size() - 2); | 211 converted.assign(&value_[2], value_.size() - 2); |
212 return source_root.Append(UTF8ToFilePath(converted)) | 212 return source_root.Append(UTF8ToFilePath(converted)) |
213 .NormalizePathSeparatorsTo('/'); | 213 .NormalizePathSeparatorsTo('/'); |
214 } | 214 } |
215 | 215 |
216 void SourceDir::SwapValue(std::string* v) { | 216 void SourceDir::SwapValue(std::string* v) { |
217 value_.swap(*v); | 217 value_.swap(*v); |
218 AssertValueSourceDirString(value_); | 218 AssertValueSourceDirString(value_); |
219 } | 219 } |
OLD | NEW |