| 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_FILESYSTEM_UTILS_H_ | 5 #ifndef TOOLS_GN_FILESYSTEM_UTILS_H_ |
| 6 #define TOOLS_GN_FILESYSTEM_UTILS_H_ | 6 #define TOOLS_GN_FILESYSTEM_UTILS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 12 #include "tools/gn/settings.h" | 12 #include "tools/gn/settings.h" |
| 13 #include "tools/gn/target.h" | 13 #include "tools/gn/target.h" |
| 14 | 14 |
| 15 class Err; | 15 class Err; |
| 16 class Location; | 16 class Location; |
| 17 class Value; | 17 class Value; |
| 18 | 18 |
| 19 enum SourceFileType { | |
| 20 SOURCE_UNKNOWN, | |
| 21 SOURCE_ASM, | |
| 22 SOURCE_C, | |
| 23 SOURCE_CC, | |
| 24 SOURCE_H, | |
| 25 SOURCE_M, | |
| 26 SOURCE_MM, | |
| 27 SOURCE_S, | |
| 28 SOURCE_RC, | |
| 29 SOURCE_O, // Object files can be inputs, too. Also counts .obj. | |
| 30 }; | |
| 31 | |
| 32 SourceFileType GetSourceFileType(const SourceFile& file); | |
| 33 | |
| 34 // Returns the extension, not including the dot, for the given file type on the | 19 // Returns the extension, not including the dot, for the given file type on the |
| 35 // given system. | 20 // given system. |
| 36 // | 21 // |
| 37 // Some targets make multiple files (like a .dll and an import library). This | 22 // Some targets make multiple files (like a .dll and an import library). This |
| 38 // function returns the name of the file other targets should depend on and | 23 // function returns the name of the file other targets should depend on and |
| 39 // link to (so in this example, the import library). | 24 // link to (so in this example, the import library). |
| 40 const char* GetExtensionForOutputType(Target::OutputType type, | 25 const char* GetExtensionForOutputType(Target::OutputType type, |
| 41 Settings::TargetOS os); | 26 Settings::TargetOS os); |
| 42 | 27 |
| 43 std::string FilePathToUTF8(const base::FilePath::StringType& str); | 28 std::string FilePathToUTF8(const base::FilePath::StringType& str); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 80 |
| 96 // Returns the substring identifying the last component of the dir, or the | 81 // Returns the substring identifying the last component of the dir, or the |
| 97 // empty substring if none. For example "//foo/bar/" -> "bar". | 82 // empty substring if none. For example "//foo/bar/" -> "bar". |
| 98 base::StringPiece FindLastDirComponent(const SourceDir& dir); | 83 base::StringPiece FindLastDirComponent(const SourceDir& dir); |
| 99 | 84 |
| 100 // Verifies that the given string references a file inside of the given | 85 // Verifies that the given string references a file inside of the given |
| 101 // directory. This is pretty stupid and doesn't handle "." and "..", etc., | 86 // directory. This is pretty stupid and doesn't handle "." and "..", etc., |
| 102 // it is designed for a sanity check to keep people from writing output files | 87 // it is designed for a sanity check to keep people from writing output files |
| 103 // to the source directory accidentally. | 88 // to the source directory accidentally. |
| 104 // | 89 // |
| 105 // The originating value will be blamed in the error. | 90 // The origin will be blamed in the error. |
| 106 // | 91 // |
| 107 // If the file isn't in the dir, returns false and sets the error. Otherwise | 92 // If the file isn't in the dir, returns false and sets the error. Otherwise |
| 108 // returns true and leaves the error untouched. | 93 // returns true and leaves the error untouched. |
| 109 bool EnsureStringIsInOutputDir(const SourceDir& dir, | 94 bool EnsureStringIsInOutputDir(const SourceDir& dir, |
| 110 const std::string& str, | 95 const std::string& str, |
| 111 const Value& originating, | 96 const ParseNode* origin, |
| 112 Err* err); | 97 Err* err); |
| 113 | 98 |
| 114 // ---------------------------------------------------------------------------- | 99 // ---------------------------------------------------------------------------- |
| 115 | 100 |
| 116 // Returns true if the input string is absolute. Double-slashes at the | 101 // Returns true if the input string is absolute. Double-slashes at the |
| 117 // beginning are treated as source-relative paths. On Windows, this handles | 102 // beginning are treated as source-relative paths. On Windows, this handles |
| 118 // paths of both the native format: "C:/foo" and ours "/C:/foo" | 103 // paths of both the native format: "C:/foo" and ours "/C:/foo" |
| 119 bool IsPathAbsolute(const base::StringPiece& path); | 104 bool IsPathAbsolute(const base::StringPiece& path); |
| 120 | 105 |
| 121 // Given an absolute path, checks to see if is it is inside the source root. | 106 // Given an absolute path, checks to see if is it is inside the source root. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // output. This will be the empty string to indicate that the toolchain outputs | 156 // output. This will be the empty string to indicate that the toolchain outputs |
| 172 // go in the root build directory. Otherwise, the result will end in a slash. | 157 // go in the root build directory. Otherwise, the result will end in a slash. |
| 173 std::string GetOutputSubdirName(const Label& toolchain_label, bool is_default); | 158 std::string GetOutputSubdirName(const Label& toolchain_label, bool is_default); |
| 174 | 159 |
| 175 // ----------------------------------------------------------------------------- | 160 // ----------------------------------------------------------------------------- |
| 176 | 161 |
| 177 // These functions return the various flavors of output and gen directories. | 162 // These functions return the various flavors of output and gen directories. |
| 178 SourceDir GetToolchainOutputDir(const Settings* settings); | 163 SourceDir GetToolchainOutputDir(const Settings* settings); |
| 179 SourceDir GetToolchainOutputDir(const BuildSettings* build_settings, | 164 SourceDir GetToolchainOutputDir(const BuildSettings* build_settings, |
| 180 const Label& label, bool is_default); | 165 const Label& label, bool is_default); |
| 166 |
| 181 SourceDir GetToolchainGenDir(const Settings* settings); | 167 SourceDir GetToolchainGenDir(const Settings* settings); |
| 168 OutputFile GetToolchainGenDirAsOutputFile(const Settings* settings); |
| 182 SourceDir GetToolchainGenDir(const BuildSettings* build_settings, | 169 SourceDir GetToolchainGenDir(const BuildSettings* build_settings, |
| 183 const Label& toolchain_label, bool is_default); | 170 const Label& toolchain_label, |
| 171 bool is_default); |
| 172 |
| 184 SourceDir GetOutputDirForSourceDir(const Settings* settings, | 173 SourceDir GetOutputDirForSourceDir(const Settings* settings, |
| 185 const SourceDir& source_dir); | 174 const SourceDir& source_dir); |
| 175 OutputFile GetOutputDirForSourceDirAsOutputFile(const Settings* settings, |
| 176 const SourceDir& source_dir); |
| 177 |
| 186 SourceDir GetGenDirForSourceDir(const Settings* settings, | 178 SourceDir GetGenDirForSourceDir(const Settings* settings, |
| 187 const SourceDir& source_dir); | 179 const SourceDir& source_dir); |
| 180 OutputFile GetGenDirForSourceDirAsOutputFile(const Settings* settings, |
| 181 const SourceDir& source_dir); |
| 182 |
| 188 SourceDir GetTargetOutputDir(const Target* target); | 183 SourceDir GetTargetOutputDir(const Target* target); |
| 184 OutputFile GetTargetOutputDirAsOutputFile(const Target* target); |
| 189 SourceDir GetTargetGenDir(const Target* target); | 185 SourceDir GetTargetGenDir(const Target* target); |
| 186 OutputFile GetTargetGenDirAsOutputFile(const Target* target); |
| 187 |
| 190 SourceDir GetCurrentOutputDir(const Scope* scope); | 188 SourceDir GetCurrentOutputDir(const Scope* scope); |
| 191 SourceDir GetCurrentGenDir(const Scope* scope); | 189 SourceDir GetCurrentGenDir(const Scope* scope); |
| 192 | 190 |
| 193 #endif // TOOLS_GN_FILESYSTEM_UTILS_H_ | 191 #endif // TOOLS_GN_FILESYSTEM_UTILS_H_ |
| OLD | NEW |