Correct blacklist entry message
[chromium-blink-merge.git] / tools / gn / source_file.cc
blobe5d67753e7f4a958bf09542fd3ead162ae94bcf8
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
3 // found in the LICENSE file.
5 #include "tools/gn/source_file.h"
7 #include "base/logging.h"
8 #include "build/build_config.h"
9 #include "tools/gn/filesystem_utils.h"
10 #include "tools/gn/source_dir.h"
12 SourceFile::SourceFile() {
15 SourceFile::SourceFile(const base::StringPiece& p)
16 : value_(p.data(), p.size()) {
17 DCHECK(!value_.empty());
18 DCHECK(value_[0] == '/');
19 DCHECK(!EndsWithSlash(value_));
22 SourceFile::~SourceFile() {
25 std::string SourceFile::GetName() const {
26 if (is_null())
27 return std::string();
29 DCHECK(value_.find('/') != std::string::npos);
30 size_t last_slash = value_.rfind('/');
31 return std::string(&value_[last_slash + 1],
32 value_.size() - last_slash - 1);
35 SourceDir SourceFile::GetDir() const {
36 if (is_null())
37 return SourceDir();
39 DCHECK(value_.find('/') != std::string::npos);
40 size_t last_slash = value_.rfind('/');
41 return SourceDir(base::StringPiece(&value_[0], last_slash + 1));
44 base::FilePath SourceFile::Resolve(const base::FilePath& source_root) const {
45 if (is_null())
46 return base::FilePath();
48 std::string converted;
49 if (is_system_absolute()) {
50 if (value_.size() > 2 && value_[2] == ':') {
51 // Windows path, strip the leading slash.
52 converted.assign(&value_[1], value_.size() - 1);
53 } else {
54 converted.assign(value_);
56 ConvertPathToSystem(&converted);
57 return base::FilePath(UTF8ToFilePath(converted));
60 converted.assign(&value_[2], value_.size() - 2);
61 ConvertPathToSystem(&converted);
62 return source_root.Append(UTF8ToFilePath(converted));