]>
Commit | Line | Data |
---|---|---|
3ec65766 | 1 | // Copyright (C) 2020-2024 Joel Rosdahl and other contributors |
f3652404 TO |
2 | // |
3 | // See doc/AUTHORS.adoc for a complete list of contributors. | |
4 | // | |
5 | // This program is free software; you can redistribute it and/or modify it | |
6 | // under the terms of the GNU General Public License as published by the Free | |
7 | // Software Foundation; either version 3 of the License, or (at your option) | |
8 | // any later version. | |
9 | // | |
10 | // This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | // more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License along with | |
16 | // this program; if not, write to the Free Software Foundation, Inc., 51 | |
17 | // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | ||
19 | #pragma once | |
20 | ||
ad52c600 | 21 | #include "Args.hpp" |
f3652404 | 22 | #include "ArgsInfo.hpp" |
8b0f2eb6 | 23 | #include "Config.hpp" |
1a15286a | 24 | #include "MiniTrace.hpp" |
6e3b6b1c | 25 | |
ea9a264e | 26 | #include <util/FileStream.hpp> |
6e3b6b1c | 27 | #include <util/NonCopyable.hpp> |
35bcc8dc | 28 | |
2354adc2 JR |
29 | #ifdef INODE_CACHE_SUPPORTED |
30 | # include "InodeCache.hpp" | |
31 | #endif | |
32 | ||
0e4e4b63 | 33 | #include <Hash.hpp> |
d663cb51 | 34 | #include <core/Manifest.hpp> |
c7c0837a | 35 | #include <storage/Storage.hpp> |
653dde81 | 36 | #include <util/TimePoint.hpp> |
c7c0837a | 37 | |
ca9ec9cf | 38 | #include <ctime> |
eea89d4a | 39 | #include <optional> |
380beacf | 40 | #include <string> |
60005c83 | 41 | #include <string_view> |
35bcc8dc | 42 | #include <unordered_map> |
380beacf | 43 | #include <vector> |
f3652404 | 44 | |
91aa7075 JR |
45 | class SignalHandler; |
46 | ||
6e3b6b1c | 47 | class Context : util::NonCopyable |
f3652404 | 48 | { |
61bd2ef2 | 49 | public: |
20696244 | 50 | Context(); |
91aa7075 | 51 | ~Context(); |
272fb0ed | 52 | |
a2e6316e JR |
53 | // Read configuration, initialize logging, etc. Typically not called from unit |
54 | // tests. | |
e1a53fd0 JR |
55 | void initialize(Args&& compiler_and_args, |
56 | const std::vector<std::string>& cmdline_config_settings); | |
a2e6316e | 57 | |
272fb0ed | 58 | ArgsInfo args_info; |
8b0f2eb6 | 59 | Config config; |
0b5a24e7 | 60 | |
20696244 JR |
61 | // Current working directory as returned by getcwd(3). |
62 | std::string actual_cwd; | |
63 | ||
64 | // Current working directory according to $PWD (falling back to getcwd(3)). | |
65 | std::string apparent_cwd; | |
66 | ||
86d48e61 | 67 | // The original argument list. |
ad52c600 | 68 | Args orig_args; |
6a4e0f88 | 69 | |
35bcc8dc | 70 | // Files included by the preprocessor and their hashes. |
0e4e4b63 | 71 | std::unordered_map<std::string, Hash::Digest> included_files; |
6fffc647 | 72 | |
1c6ccf18 MW |
73 | // Have we tried and failed to get colored diagnostics? |
74 | bool diagnostics_color_failed = false; | |
75 | ||
7f398575 TO |
76 | // The name of the temporary preprocessed file. |
77 | std::string i_tmpfile; | |
ed11fcd7 | 78 | |
64fc42ca | 79 | // The preprocessor's stderr output. |
e9ddf680 | 80 | util::Bytes cpp_stderr_data; |
019d5032 | 81 | |
380beacf | 82 | // Headers (or directories with headers) to ignore in manifest mode. |
587b0244 | 83 | std::vector<std::filesystem::path> ignore_header_paths; |
8f720b28 | 84 | |
0cd6f70b | 85 | // Storage (fronting local and remote storage backends). |
c7c0837a JR |
86 | storage::Storage storage; |
87 | ||
d663cb51 JR |
88 | // Direct mode manifest. |
89 | core::Manifest manifest; | |
90 | ||
213d9883 OL |
91 | #ifdef INODE_CACHE_SUPPORTED |
92 | // InodeCache that caches source file hashes when enabled. | |
93 | mutable InodeCache inode_cache; | |
94 | #endif | |
95 | ||
3ec65766 JR |
96 | // Time of ccache invocation. |
97 | util::TimePoint time_of_invocation; | |
98 | ||
91aa7075 JR |
99 | // PID of currently executing compiler that we have started, if any. 0 means |
100 | // no ongoing compilation. | |
101 | pid_t compiler_pid = 0; | |
102 | ||
103 | // Files used by the hash debugging functionality. | |
ea9a264e | 104 | std::vector<util::FileStream> hash_debug_files; |
91aa7075 | 105 | |
231fef47 RE |
106 | // Options to ignore for the hash. |
107 | const std::vector<std::string>& ignore_options() const; | |
108 | void set_ignore_options(const std::vector<std::string>& options); | |
109 | ||
106a1d22 JR |
110 | // Original umask before applying the `umask`/`CCACHE_UMASK` configuration, or |
111 | // `nullopt` if there is no such configuration. | |
eea89d4a | 112 | std::optional<mode_t> original_umask; |
106a1d22 | 113 | |
1a15286a JR |
114 | #ifdef MTR_ENABLED |
115 | // Internal tracing. | |
116 | std::unique_ptr<MiniTrace> mini_trace; | |
117 | #endif | |
118 | ||
4ad17e89 JR |
119 | // Whether we have added "/showIncludes" ourselves since it's missing and |
120 | // depend mode is enabled. | |
bda468cf OS |
121 | bool auto_depend_mode = false; |
122 | ||
91aa7075 JR |
123 | // Register a temporary file to remove at program exit. |
124 | void register_pending_tmp_file(const std::string& path); | |
125 | ||
42280875 | 126 | private: |
231fef47 RE |
127 | // Options to ignore for the hash. |
128 | std::vector<std::string> m_ignore_options; | |
129 | ||
91aa7075 JR |
130 | // [Start of variables touched by the signal handler] |
131 | ||
132 | // Temporary files to remove at program exit. | |
133 | std::vector<std::string> m_pending_tmp_files; | |
134 | ||
135 | // [End of variables touched by the signal handler] | |
136 | ||
137 | friend SignalHandler; | |
138 | void unlink_pending_tmp_files(); | |
139 | void unlink_pending_tmp_files_signal_safe(); // called from signal handler | |
f3652404 | 140 | }; |
42280875 | 141 | |
231fef47 RE |
142 | inline const std::vector<std::string>& |
143 | Context::ignore_options() const | |
144 | { | |
145 | return m_ignore_options; | |
146 | } |