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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // Writes given stream contents to the given file if it differs from existing | 170 // Writes given stream contents to the given file if it differs from existing |
171 // file contents. Returns true if new contents was successfully written or | 171 // file contents. Returns true if new contents was successfully written or |
172 // existing file contents doesn't need updating, false on write error. |err| is | 172 // existing file contents doesn't need updating, false on write error. |err| is |
173 // set on write error if not nullptr. | 173 // set on write error if not nullptr. |
174 bool WriteFileIfChanged(const base::FilePath& file_path, | 174 bool WriteFileIfChanged(const base::FilePath& file_path, |
175 const std::string& data, | 175 const std::string& data, |
176 Err* err); | 176 Err* err); |
177 | 177 |
178 // ----------------------------------------------------------------------------- | 178 // ----------------------------------------------------------------------------- |
179 | 179 |
180 // These functions return the various flavors of output and gen directories. | 180 enum class BuildDirType { |
181 SourceDir GetToolchainOutputDir(const Settings* settings); | 181 // Returns the root toolchain dir rather than the generated or output |
182 SourceDir GetToolchainOutputDir(const BuildSettings* build_settings, | 182 // subdirectories. This is valid only for the toolchain directory getters. |
183 const Label& label, bool is_default); | 183 // Asking for this for a target or source dir makes no sense. |
| 184 TOOLCHAIN_ROOT, |
184 | 185 |
185 SourceDir GetToolchainGenDir(const Settings* settings); | 186 // Generated file directory. |
186 OutputFile GetToolchainGenDirAsOutputFile(const Settings* settings); | 187 GEN, |
187 SourceDir GetToolchainGenDir(const BuildSettings* build_settings, | |
188 const Label& toolchain_label, | |
189 bool is_default); | |
190 | 188 |
191 SourceDir GetOutputDirForSourceDir(const Settings* settings, | 189 // Output file directory. |
192 const SourceDir& source_dir); | 190 OBJ, |
193 SourceDir GetOutputDirForSourceDir(const BuildSettings* build_settings, | 191 }; |
194 const SourceDir& source_dir, | |
195 const Label& toolchain_label, | |
196 bool is_default_toolchain); | |
197 OutputFile GetOutputDirForSourceDirAsOutputFile( | |
198 const BuildSettings* build_settings, | |
199 const SourceDir& source_dir, | |
200 const Label& toolchain_label, | |
201 bool is_default_toolchain); | |
202 OutputFile GetOutputDirForSourceDirAsOutputFile(const Settings* settings, | |
203 const SourceDir& source_dir); | |
204 | 192 |
205 SourceDir GetGenDirForSourceDir(const Settings* settings, | 193 // In different contexts, different information is known about the toolchain in |
206 const SourceDir& source_dir); | 194 // question. If you have a Target or settings object, everything can be |
207 OutputFile GetGenDirForSourceDirAsOutputFile(const Settings* settings, | 195 // extracted from there. But when querying label information on something in |
208 const SourceDir& source_dir); | 196 // another toolchain, for example, the only thing known (it may not even exist) |
| 197 // is the toolchain label string and whether it matches the default toolchain. |
| 198 // |
| 199 // This object extracts the relevant information from a variety of input |
| 200 // types for the convenience of the caller. |
| 201 class BuildDirContext { |
| 202 public: |
| 203 // Extracts toolchain information associated with the given target. |
| 204 explicit BuildDirContext(const Target* target); |
209 | 205 |
210 SourceDir GetTargetOutputDir(const Target* target); | 206 // Extracts toolchain information associated with the given settings object. |
211 OutputFile GetTargetOutputDirAsOutputFile(const Target* target); | 207 explicit BuildDirContext(const Settings* settings); |
212 SourceDir GetTargetGenDir(const Target* target); | |
213 OutputFile GetTargetGenDirAsOutputFile(const Target* target); | |
214 | 208 |
215 SourceDir GetCurrentOutputDir(const Scope* scope); | 209 // Extrats toolchain information from the current toolchain of the scope. |
216 SourceDir GetCurrentGenDir(const Scope* scope); | 210 explicit BuildDirContext(const Scope* execution_scope); |
| 211 |
| 212 // Extracts the default toolchain information from the given execution |
| 213 // scope. The toolchain you want to query must be passed in. This doesn't |
| 214 // use the settings object from the Scope so one can query other toolchains. |
| 215 // If you want to use the scope's current toolchain, use the version above. |
| 216 BuildDirContext(const Scope* execution_scope, const Label& toolchain_label); |
| 217 |
| 218 // Specify all information manually. |
| 219 BuildDirContext(const BuildSettings* build_settings, |
| 220 const Label& toolchain_label, |
| 221 bool is_default_toolchain); |
| 222 |
| 223 const BuildSettings* build_settings; |
| 224 const Label& toolchain_label; |
| 225 bool is_default_toolchain; |
| 226 }; |
| 227 |
| 228 // Returns the root, object, or generated file directory for the toolchain. |
| 229 // |
| 230 // The toolchain object file root is never exposed in GN (there is no |
| 231 // root_obj_dir variable) so BuildDirType::OBJ would normally never be passed |
| 232 // to this function except when it's called by one of the variants below that |
| 233 // append paths to it. |
| 234 SourceDir GetBuildDirAsSourceDir(const BuildDirContext& context, |
| 235 BuildDirType type); |
| 236 OutputFile GetBuildDirAsOutputFile(const BuildDirContext& context, |
| 237 BuildDirType type); |
| 238 |
| 239 // Returns the output or generated file directory corresponding to the given |
| 240 // source directory. |
| 241 SourceDir GetSubBuildDirAsSourceDir(const BuildDirContext& context, |
| 242 const SourceDir& source_dir, |
| 243 BuildDirType type); |
| 244 OutputFile GetSubBuildDirAsOutputFile(const BuildDirContext& context, |
| 245 const SourceDir& source_dir, |
| 246 BuildDirType type); |
| 247 |
| 248 // Returns the output or generated file directory corresponding to the given |
| 249 // target. |
| 250 SourceDir GetBuildDirForTargetAsSourceDir(const Target* target, |
| 251 BuildDirType type); |
| 252 OutputFile GetBuildDirForTargetAsOutputFile(const Target* target, |
| 253 BuildDirType type); |
| 254 |
| 255 // Returns the scope's current directory. |
| 256 SourceDir GetScopeCurrentBuildDirAsSourceDir(const Scope* scope, |
| 257 BuildDirType type); |
| 258 // Lack of OutputDir version is due only to it not currently being needed, |
| 259 // please add one if you need it. |
217 | 260 |
218 #endif // TOOLS_GN_FILESYSTEM_UTILS_H_ | 261 #endif // TOOLS_GN_FILESYSTEM_UTILS_H_ |
OLD | NEW |