Skip to content

Commit

Permalink
Merge pull request #177 from rime/develop
Browse files Browse the repository at this point in the history
fix issues with the refactored config and dict_compiler
  • Loading branch information
lotem authored Feb 20, 2018
2 parents 463dc09 + 8a3e25c commit 202b01f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
6 changes: 5 additions & 1 deletion src/rime/config/build_info_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ bool BuildInfoPlugin::ReviewLinkOutput(
auto timestamps = build_info["timestamps"];
compiler->EnumerateResources([&](an<ConfigResource> resource) {
if (!resource->loaded) {
LOG(WARNING) << "resource '" << resource->resource_id << "' not loaded.";
LOG(INFO) << "resource '" << resource->resource_id << "' not loaded.";
timestamps[resource->resource_id] = 0;
return;
}
auto file_name = resource->data->file_name();
if (file_name.empty()) {
LOG(WARNING) << "resource '" << resource->resource_id
<< "' is not persisted.";
timestamps[resource->resource_id] = 0;
return;
}
// TODO: store as 64-bit number to avoid the year 2038 problem
Expand Down
10 changes: 7 additions & 3 deletions src/rime/dict/dict_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static string LocateFile(const string& file_name) {
}

bool DictCompiler::Compile(const string &schema_file) {
LOG(INFO) << "compiling:";
LOG(INFO) << "compiling dictionary for " << schema_file;
bool build_table_from_source = true;
DictSettings settings;
string dict_file = LocateFile(dict_name_ + ".dict.yaml");
Expand Down Expand Up @@ -215,9 +215,13 @@ bool DictCompiler::BuildPrism(const string &schema_file,
// apply spelling algebra
Script script;
if (!schema_file.empty()) {
Config config;
if (!config.LoadFromFile(schema_file)) {
LOG(ERROR) << "error loading prism definition from " << schema_file;
return false;
}
Projection p;
the<Config> config(Config::Require("config")->Create(schema_file));
auto algebra = config->GetList("speller/algebra");
auto algebra = config.GetList("speller/algebra");
if (algebra && p.Load(algebra)) {
for (const auto& x : syllabary) {
script.AddSyllable(x);
Expand Down
2 changes: 1 addition & 1 deletion src/rime/lever/custom_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool CustomSettings::Load() {
fs::path shared_data_path(deployer_->shared_data_dir);
fs::path config_path(user_data_path / "build" / (config_id_ + ".yaml"));
if (!config_.LoadFromFile(config_path.string())) {
config_path = shared_data_path / (config_id_ + ".yaml");
config_path = shared_data_path / "build" / (config_id_ + ".yaml");
if (!config_.LoadFromFile(config_path.string())) {
LOG(WARNING) << "cannot find '" << config_id_ << ".yaml'.";
return false;
Expand Down
23 changes: 12 additions & 11 deletions src/rime/lever/deployment_tasks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ bool WorkspaceUpdate::Run(Deployer* deployer) {
the<DeploymentTask> t;
t.reset(new ConfigFileUpdate("default.yaml", "config_version"));
t->Run(deployer);
t.reset(new ConfigFileUpdate("symbols.yaml", "config_version"));
t->Run(deployer);
// Deprecated: symbols.yaml is only used as source file
//t.reset(new ConfigFileUpdate("symbols.yaml", "config_version"));
//t->Run(deployer);
t.reset(new SymlinkingPrebuiltDictionaries);
t->Run(deployer);
}
Expand Down Expand Up @@ -257,8 +258,11 @@ static bool TrashCustomizedCopy(const fs::path& shared_copy,
const fs::path& user_copy,
const string& version_key,
const fs::path& trash) {
if (fs::equivalent(shared_copy, user_copy))
if (!fs::exists(shared_copy) ||
!fs::exists(user_copy) ||
fs::equivalent(shared_copy, user_copy)) {
return false;
}
if (IsCustomizedCopy(user_copy.string())) {
string shared_copy_version;
string user_copy_version;
Expand Down Expand Up @@ -384,14 +388,14 @@ static bool ConfigNeedsUpdate(Config* config) {
for (auto entry : *timestamps.AsMap()) {
fs::path source_file_path = resolver->ResolvePath(entry.first);
if (!fs::exists(source_file_path)) {
LOG(INFO) << "source file not exists: " << source_file_path.string();
LOG(INFO) << "source file no longer exists: " << source_file_path.string();
return true;
}
auto value = As<ConfigValue>(entry.second);
int recorded_time = 0;
if (!value || !value->GetInt(&recorded_time) ||
recorded_time != (int) fs::last_write_time(source_file_path)) {
LOG(INFO) << "timestamp mismatch: " << source_file_path.string();
LOG(INFO) << "source file changed: " << source_file_path.string();
return true;
}
}
Expand All @@ -401,19 +405,16 @@ static bool ConfigNeedsUpdate(Config* config) {
bool ConfigFileUpdate::Run(Deployer* deployer) {
fs::path shared_data_path(deployer->shared_data_dir);
fs::path user_data_path(deployer->user_data_dir);
// trash depecated user copy created by an older version of Rime
fs::path source_config_path(shared_data_path / file_name_);
fs::path dest_config_path(user_data_path / file_name_);
fs::path trash = user_data_path / "trash";
if (!fs::exists(source_config_path)) {
LOG(WARNING) << "'" << file_name_
<< "' is missing from shared data directory.";
return false;
}
if (TrashCustomizedCopy(source_config_path,
dest_config_path,
version_key_,
trash)) {
LOG(INFO) << "patched copy of '" << file_name_ << "' is moved to trash.";
LOG(INFO) << "deprecated user copy of '" << file_name_
<< "' is moved to " << trash;
}
// build the config file if needs update
the<Config> config(Config::Require("config")->Create(file_name_));
Expand Down

0 comments on commit 202b01f

Please sign in to comment.