File tree 5 files changed +55
-0
lines changed
5 files changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ //
2
+ // Copyright RIME Developers
3
+ // Distributed under the BSD License
4
+ //
5
+ #include < boost/filesystem.hpp>
6
+ #include < rime/service.h>
7
+ #include < rime/config/config_compiler.h>
8
+ #include < rime/config/config_types.h>
9
+ #include < rime/config/plugins.h>
10
+
11
+ namespace rime {
12
+
13
+ bool BuildInfoPlugin::ReviewCompileOutput (
14
+ ConfigCompiler* compiler, an<ConfigResource> resource) {
15
+ return true ;
16
+ }
17
+
18
+ bool BuildInfoPlugin::ReviewLinkOutput (
19
+ ConfigCompiler* compiler, an<ConfigResource> resource) {
20
+ auto build_info = (*resource)[" __build_info" ];
21
+ build_info[" rime_version" ] = RIME_VERSION;
22
+ auto timestamps = build_info[" timestamps" ];
23
+ compiler->EnumerateResources ([&](an<ConfigResource> resource) {
24
+ if (!resource->loaded ) {
25
+ LOG (WARNING) << " resource '" << resource->resource_id << " ' not loaded." ;
26
+ return ;
27
+ }
28
+ auto file_name = resource->data ->file_name ();
29
+ if (file_name.empty ()) {
30
+ return ;
31
+ }
32
+ // TODO: store as 64-bit number to avoid the year 2038 problem
33
+ timestamps[resource->resource_id ] =
34
+ (int ) boost::filesystem::last_write_time (file_name);
35
+ });
36
+ return true ;
37
+ }
38
+
39
+ } // namespace rime
Original file line number Diff line number Diff line change @@ -295,6 +295,13 @@ void ConfigCompiler::Pop() {
295
295
graph_->Pop ();
296
296
}
297
297
298
+ void ConfigCompiler::EnumerateResources (
299
+ function<void (an<ConfigResource> resource)> process_resource) {
300
+ for (const auto & r : graph_->resources ) {
301
+ process_resource (r.second );
302
+ }
303
+ }
304
+
298
305
an<ConfigResource> ConfigCompiler::GetCompiledResource (
299
306
const string& resource_id) const {
300
307
return graph_->resources [resource_id];
Original file line number Diff line number Diff line change @@ -64,6 +64,8 @@ class ConfigCompiler {
64
64
bool Parse (const string& key, const an<ConfigItem>& item);
65
65
void Pop ();
66
66
67
+ void EnumerateResources (
68
+ function<void (an<ConfigResource> resource)> process_resource);
67
69
an<ConfigResource> GetCompiledResource (const string& resource_id) const ;
68
70
an<ConfigResource> Compile (const string& file_name);
69
71
bool Link (an<ConfigResource> target);
Original file line number Diff line number Diff line change @@ -45,6 +45,12 @@ class LegacyDictionaryConfigPlugin : public ConfigCompilerPlugin {
45
45
Review ReviewLinkOutput;
46
46
};
47
47
48
+ class BuildInfoPlugin : public ConfigCompilerPlugin {
49
+ public:
50
+ Review ReviewCompileOutput;
51
+ Review ReviewLinkOutput;
52
+ };
53
+
48
54
} // namespace rime
49
55
50
56
#endif // RIME_CONFIG_PLUGINS_H_
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ static void rime_core_initialize() {
25
25
config->InstallPlugin (new DefaultConfigPlugin);
26
26
config->InstallPlugin (new LegacyPresetConfigPlugin);
27
27
config->InstallPlugin (new LegacyDictionaryConfigPlugin);
28
+ config->InstallPlugin (new BuildInfoPlugin);
28
29
r.Register (" config" , config);
29
30
r.Register (" schema" , new SchemaComponent (config));
30
31
}
You can’t perform that action at this time.
0 commit comments