| 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 #ifndef TOOLS_GN_SOURCE_DIR_H_ | 5 #ifndef TOOLS_GN_SOURCE_DIR_H_ |
| 6 #define TOOLS_GN_SOURCE_DIR_H_ | 6 #define TOOLS_GN_SOURCE_DIR_H_ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
| 15 | 15 |
| 16 class Err; |
| 16 class SourceFile; | 17 class SourceFile; |
| 18 class Value; |
| 17 | 19 |
| 18 // Represents a directory within the source tree. Source dirs begin and end in | 20 // Represents a directory within the source tree. Source dirs begin and end in |
| 19 // slashes. | 21 // slashes. |
| 20 // | 22 // |
| 21 // If there is one slash at the beginning, it will mean a system-absolute file | 23 // If there is one slash at the beginning, it will mean a system-absolute file |
| 22 // path. On Windows, absolute system paths will be of the form "/C:/foo/bar". | 24 // path. On Windows, absolute system paths will be of the form "/C:/foo/bar". |
| 23 // | 25 // |
| 24 // Two slashes at the beginning indicate a path relative to the source root. | 26 // Two slashes at the beginning indicate a path relative to the source root. |
| 25 class SourceDir { | 27 class SourceDir { |
| 26 public: | 28 public: |
| 27 enum SwapIn { SWAP_IN }; | 29 enum SwapIn { SWAP_IN }; |
| 28 | 30 |
| 29 SourceDir(); | 31 SourceDir(); |
| 30 explicit SourceDir(const base::StringPiece& p); | 32 explicit SourceDir(const base::StringPiece& p); |
| 31 // Swaps the given string in without copies. The given string will be empty | 33 // Swaps the given string in without copies. The given string will be empty |
| 32 // after this call. | 34 // after this call. |
| 33 SourceDir(SwapIn, std::string* s); | 35 SourceDir(SwapIn, std::string* s); |
| 34 ~SourceDir(); | 36 ~SourceDir(); |
| 35 | 37 |
| 36 // Resolves a file or dir name relative to this source directory. Will return | 38 // Resolves a file or dir name relative to this source directory. Will return |
| 37 // an empty SourceDir/File on error. Empty input is always an error (it's | 39 // an empty SourceDir/File on error and set the give *err pointer (required). |
| 38 // possible we should say ResolveRelativeDir vs. an empty string should be | 40 // Empty input is always an error. |
| 39 // the source dir, but we require "." instead). | |
| 40 // | 41 // |
| 41 // If source_root is supplied, these functions will additionally handle the | 42 // If source_root is supplied, these functions will additionally handle the |
| 42 // case where the input is a system-absolute but still inside the source | 43 // case where the input is a system-absolute but still inside the source |
| 43 // tree. This is the case for some external tools. | 44 // tree. This is the case for some external tools. |
| 44 SourceFile ResolveRelativeFile( | 45 SourceFile ResolveRelativeFile( |
| 45 const base::StringPiece& p, | 46 const Value& p, |
| 47 Err* err, |
| 46 const base::StringPiece& source_root = base::StringPiece()) const; | 48 const base::StringPiece& source_root = base::StringPiece()) const; |
| 47 SourceDir ResolveRelativeDir( | 49 SourceDir ResolveRelativeDir( |
| 50 const Value& p, |
| 51 Err* err, |
| 52 const base::StringPiece& source_root = base::StringPiece()) const; |
| 53 |
| 54 // Like ResolveRelativeDir but takes a separate value (which gets blamed) |
| 55 // and string to use (in cases where a substring has been extracted from the |
| 56 // value, as with label resolution). |
| 57 SourceDir ResolveRelativeDir( |
| 58 const Value& blame_but_dont_use, |
| 48 const base::StringPiece& p, | 59 const base::StringPiece& p, |
| 60 Err* err, |
| 49 const base::StringPiece& source_root = base::StringPiece()) const; | 61 const base::StringPiece& source_root = base::StringPiece()) const; |
| 50 | 62 |
| 51 // Resolves this source file relative to some given source root. Returns | 63 // Resolves this source file relative to some given source root. Returns |
| 52 // an empty file path on error. | 64 // an empty file path on error. |
| 53 base::FilePath Resolve(const base::FilePath& source_root) const; | 65 base::FilePath Resolve(const base::FilePath& source_root) const; |
| 54 | 66 |
| 55 bool is_null() const { return value_.empty(); } | 67 bool is_null() const { return value_.empty(); } |
| 56 const std::string& value() const { return value_; } | 68 const std::string& value() const { return value_; } |
| 57 | 69 |
| 58 // Returns true if this path starts with a "//" which indicates a path | 70 // Returns true if this path starts with a "//" which indicates a path |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 123 } |
| 112 }; | 124 }; |
| 113 | 125 |
| 114 } // namespace BASE_HASH_NAMESPACE | 126 } // namespace BASE_HASH_NAMESPACE |
| 115 | 127 |
| 116 inline void swap(SourceDir& lhs, SourceDir& rhs) { | 128 inline void swap(SourceDir& lhs, SourceDir& rhs) { |
| 117 lhs.swap(rhs); | 129 lhs.swap(rhs); |
| 118 } | 130 } |
| 119 | 131 |
| 120 #endif // TOOLS_GN_SOURCE_DIR_H_ | 132 #endif // TOOLS_GN_SOURCE_DIR_H_ |
| OLD | NEW |