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_INPUT_FILE_H_ | 5 #ifndef TOOLS_GN_INPUT_FILE_H_ |
6 #define TOOLS_GN_INPUT_FILE_H_ | 6 #define TOOLS_GN_INPUT_FILE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "tools/gn/source_dir.h" | 13 #include "tools/gn/source_dir.h" |
14 #include "tools/gn/source_file.h" | 14 #include "tools/gn/source_file.h" |
15 | 15 |
16 class InputFile { | 16 class InputFile { |
17 public: | 17 public: |
18 InputFile(const SourceFile& name); | 18 InputFile(const SourceFile& name); |
19 | 19 |
20 // Constructor for testing. Uses an empty file path and a given contents. | |
21 //InputFile(const char* contents); | |
22 ~InputFile(); | 20 ~InputFile(); |
23 | 21 |
| 22 // The virtual name passed into the constructor. This does not take into |
| 23 // account whether the file was loaded from the secondary source tree (see |
| 24 // BuildSettings secondary_source_path). |
24 const SourceFile& name() const { return name_; } | 25 const SourceFile& name() const { return name_; } |
25 | 26 |
26 // The directory is just a cached version of name_->GetDir() but we get this | 27 // The directory is just a cached version of name()->GetDir() but we get this |
27 // a lot so computing it once up front saves a bunch of work. | 28 // a lot so computing it once up front saves a bunch of work. |
28 const SourceDir& dir() const { return dir_; } | 29 const SourceDir& dir() const { return dir_; } |
29 | 30 |
| 31 // The physical name tells the actual name on disk, if there is one. |
| 32 const base::FilePath& physical_name() const { return physical_name_; } |
| 33 |
30 const std::string& contents() const { | 34 const std::string& contents() const { |
31 DCHECK(contents_loaded_); | 35 DCHECK(contents_loaded_); |
32 return contents_; | 36 return contents_; |
33 } | 37 } |
34 | 38 |
35 // For testing and in cases where this input doesn't actually refer to | 39 // For testing and in cases where this input doesn't actually refer to |
36 // "a file". | 40 // "a file". |
37 void SetContents(const std::string& c); | 41 void SetContents(const std::string& c); |
38 | 42 |
39 // Loads the given file synchronously, returning true on success. This | 43 // Loads the given file synchronously, returning true on success. This |
40 bool Load(const base::FilePath& system_path); | 44 bool Load(const base::FilePath& system_path); |
41 | 45 |
42 private: | 46 private: |
43 SourceFile name_; | 47 SourceFile name_; |
44 SourceDir dir_; | 48 SourceDir dir_; |
45 | 49 |
| 50 base::FilePath physical_name_; |
| 51 |
46 bool contents_loaded_; | 52 bool contents_loaded_; |
47 std::string contents_; | 53 std::string contents_; |
48 | 54 |
49 DISALLOW_COPY_AND_ASSIGN(InputFile); | 55 DISALLOW_COPY_AND_ASSIGN(InputFile); |
50 }; | 56 }; |
51 | 57 |
52 #endif // TOOLS_GN_INPUT_FILE_H_ | 58 #endif // TOOLS_GN_INPUT_FILE_H_ |
OLD | NEW |