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

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

Issue 630223002: gn: Support build directories outside the source tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch that compiles and passes unit tests on both Windows and Linux Created 6 years, 1 month 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/source_dir_unittest.cc ('k') | tools/gn/substitution_writer.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_file.h" 5 #include "tools/gn/source_file.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "tools/gn/filesystem_utils.h" 9 #include "tools/gn/filesystem_utils.h"
10 #include "tools/gn/source_dir.h" 10 #include "tools/gn/source_dir.h"
11 11
12 namespace {
13
14 void AssertValueSourceFileString(const std::string& s) {
15 #if defined(OS_WIN)
16 DCHECK(s[0] == '/' ||
17 (s.size() > 2 && s[0] != '/' && s[1] == ':' && IsSlash(s[2])));
18 #else
19 DCHECK(s[0] == '/');
20 #endif
21 DCHECK(!EndsWithSlash(s));
22 }
23
24 } // namespace
25
12 SourceFile::SourceFile() { 26 SourceFile::SourceFile() {
13 } 27 }
14 28
15 SourceFile::SourceFile(const base::StringPiece& p) 29 SourceFile::SourceFile(const base::StringPiece& p)
16 : value_(p.data(), p.size()) { 30 : value_(p.data(), p.size()) {
17 DCHECK(!value_.empty()); 31 DCHECK(!value_.empty());
18 DCHECK(value_[0] == '/'); 32 AssertValueSourceFileString(value_);
19 DCHECK(!EndsWithSlash(value_));
20 } 33 }
21 34
22 SourceFile::SourceFile(SwapIn, std::string* value) { 35 SourceFile::SourceFile(SwapIn, std::string* value) {
23 value_.swap(*value); 36 value_.swap(*value);
24 DCHECK(!value_.empty()); 37 DCHECK(!value_.empty());
25 DCHECK(value_[0] == '/'); 38 AssertValueSourceFileString(value_);
26 DCHECK(!EndsWithSlash(value_));
27 } 39 }
28 40
29 SourceFile::~SourceFile() { 41 SourceFile::~SourceFile() {
30 } 42 }
31 43
32 std::string SourceFile::GetName() const { 44 std::string SourceFile::GetName() const {
33 if (is_null()) 45 if (is_null())
34 return std::string(); 46 return std::string();
35 47
36 DCHECK(value_.find('/') != std::string::npos); 48 DCHECK(value_.find('/') != std::string::npos);
(...skipping 25 matching lines...) Expand all
62 } 74 }
63 return base::FilePath(UTF8ToFilePath(converted)); 75 return base::FilePath(UTF8ToFilePath(converted));
64 } 76 }
65 77
66 converted.assign(&value_[2], value_.size() - 2); 78 converted.assign(&value_[2], value_.size() - 2);
67 if (source_root.empty()) 79 if (source_root.empty())
68 return UTF8ToFilePath(converted).NormalizePathSeparatorsTo('/'); 80 return UTF8ToFilePath(converted).NormalizePathSeparatorsTo('/');
69 return source_root.Append(UTF8ToFilePath(converted)) 81 return source_root.Append(UTF8ToFilePath(converted))
70 .NormalizePathSeparatorsTo('/'); 82 .NormalizePathSeparatorsTo('/');
71 } 83 }
OLDNEW
« no previous file with comments | « tools/gn/source_dir_unittest.cc ('k') | tools/gn/substitution_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698