Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: tools/gn/source_dir.cc

Issue 857163002: Absolute path fixes for gn. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improve error message Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/label_unittest.cc ('k') | tools/gn/substitution_writer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 NormalizePath(&ret.value_); 75 NormalizePath(&ret.value_);
76 return ret; 76 return ret;
77 } 77 }
78 78
79 if (!source_root.empty()) { 79 if (!source_root.empty()) {
80 std::string absolute = 80 std::string absolute =
81 FilePathToUTF8(Resolve(UTF8ToFilePath(source_root)).AppendASCII( 81 FilePathToUTF8(Resolve(UTF8ToFilePath(source_root)).AppendASCII(
82 p.as_string()).value()); 82 p.as_string()).value());
83 NormalizePath(&absolute); 83 NormalizePath(&absolute);
84 if (!MakeAbsolutePathRelativeIfPossible(source_root, absolute, 84 if (!MakeAbsolutePathRelativeIfPossible(source_root, absolute,
85 &ret.value_)) 85 &ret.value_)) {
86 ret.value_ = absolute; 86 #if defined(OS_WIN)
87 // On Windows we'll accept "C:\foo" as an absolute path, which we want
88 // to convert to "/C:..." here.
89 if (absolute[0] != '/')
90 ret.value_ = "/";
91 #endif
92 ret.value_.append(absolute.data(), absolute.size());
93 }
87 return ret; 94 return ret;
88 } 95 }
89 96
90 // With no source_root_, there's nothing we can do about 97 // With no source_root_, there's nothing we can do about
91 // e.g. p=../../../path/to/file and value_=//source and we'll 98 // e.g. p=../../../path/to/file and value_=//source and we'll
92 // errornously return //file. 99 // errornously return //file.
93 ret.value_.reserve(value_.size() + p.size()); 100 ret.value_.reserve(value_.size() + p.size());
94 ret.value_.assign(value_); 101 ret.value_.assign(value_);
95 ret.value_.append(p.data(), p.size()); 102 ret.value_.append(p.data(), p.size());
96 103
(...skipping 30 matching lines...) Expand all
127 if (!EndsWithSlash(ret.value_)) 134 if (!EndsWithSlash(ret.value_))
128 ret.value_.push_back('/'); 135 ret.value_.push_back('/');
129 return ret; 136 return ret;
130 } 137 }
131 138
132 if (!source_root.empty()) { 139 if (!source_root.empty()) {
133 std::string absolute = 140 std::string absolute =
134 FilePathToUTF8(Resolve(UTF8ToFilePath(source_root)).AppendASCII( 141 FilePathToUTF8(Resolve(UTF8ToFilePath(source_root)).AppendASCII(
135 p.as_string()).value()); 142 p.as_string()).value());
136 NormalizePath(&absolute); 143 NormalizePath(&absolute);
137 if (!MakeAbsolutePathRelativeIfPossible(source_root, absolute, &ret.value_)) 144 if (!MakeAbsolutePathRelativeIfPossible(source_root, absolute,
138 ret.value_ = absolute; 145 &ret.value_)) {
146 #if defined(OS_WIN)
147 if (absolute[0] != '/') // See the file case for why we do this check.
148 ret.value_ = "/";
149 #endif
150 ret.value_.append(absolute.data(), absolute.size());
151 }
139 if (!EndsWithSlash(ret.value_)) 152 if (!EndsWithSlash(ret.value_))
140 ret.value_.push_back('/'); 153 ret.value_.push_back('/');
141 return ret; 154 return ret;
142 } 155 }
143 156
144 ret.value_.reserve(value_.size() + p.size()); 157 ret.value_.reserve(value_.size() + p.size());
145 ret.value_.assign(value_); 158 ret.value_.assign(value_);
146 ret.value_.append(p.data(), p.size()); 159 ret.value_.append(p.data(), p.size());
147 160
148 NormalizePath(&ret.value_); 161 NormalizePath(&ret.value_);
(...skipping 22 matching lines...) Expand all
171 // String the double-leading slash for source-relative paths. 184 // String the double-leading slash for source-relative paths.
172 converted.assign(&value_[2], value_.size() - 2); 185 converted.assign(&value_[2], value_.size() - 2);
173 return source_root.Append(UTF8ToFilePath(converted)) 186 return source_root.Append(UTF8ToFilePath(converted))
174 .NormalizePathSeparatorsTo('/'); 187 .NormalizePathSeparatorsTo('/');
175 } 188 }
176 189
177 void SourceDir::SwapValue(std::string* v) { 190 void SourceDir::SwapValue(std::string* v) {
178 value_.swap(*v); 191 value_.swap(*v);
179 AssertValueSourceDirString(value_); 192 AssertValueSourceDirString(value_);
180 } 193 }
OLDNEW
« no previous file with comments | « tools/gn/label_unittest.cc ('k') | tools/gn/substitution_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698