diff --git a/src/rime/dict/dict_compiler.cc b/src/rime/dict/dict_compiler.cc index eefc843ef..56f200bc1 100644 --- a/src/rime/dict/dict_compiler.cc +++ b/src/rime/dict/dict_compiler.cc @@ -21,15 +21,16 @@ namespace rime { -DictCompiler::DictCompiler(Dictionary *dictionary) +DictCompiler::DictCompiler(Dictionary *dictionary, const string& prefix) : dict_name_(dictionary->name()), prism_(dictionary->prism()), - table_(dictionary->table()) { + table_(dictionary->table()), + prefix_(prefix) { } static string LocateFile(const string& file_name) { the resolver( - Service::instance().CreateResourceResolver({"", "", ""})); + Service::instance().CreateResourceResolver({"build_source", "", ""})); return resolver->ResolvePath(file_name).string(); } @@ -107,7 +108,8 @@ bool DictCompiler::Compile(const string &schema_file) { LOG(INFO) << schema_file << " (" << schema_file_checksum << ")"; { the resolver( - Service::instance().CreateResourceResolver({"", "", ".reverse.bin"})); + Service::instance().CreateResourceResolver( + {"find_reverse_db", prefix_, ".reverse.bin"})); ReverseDb reverse_db(resolver->ResolvePath(dict_name_).string()); if (!reverse_db.Exists() || !reverse_db.Load() || @@ -130,8 +132,9 @@ bool DictCompiler::Compile(const string &schema_file) { return true; } -static string RelocateToUserDirectory(const string& file_name) { - ResourceResolver resolver(ResourceType{"", "", ""}); +static string RelocateToUserDirectory(const string& prefix, + const string& file_name) { + ResourceResolver resolver(ResourceType{"build_target", prefix, ""}); resolver.set_root_path(Service::instance().deployer().user_data_dir); auto resource_id = boost::filesystem::path(file_name).filename().string(); return resolver.ResolvePath(resource_id).string(); @@ -141,7 +144,7 @@ bool DictCompiler::BuildTable(DictSettings* settings, const vector& dict_files, uint32_t dict_file_checksum) { LOG(INFO) << "building table..."; - table_ = New(RelocateToUserDirectory(table_->file_name())); + table_ = New
(RelocateToUserDirectory(prefix_, table_->file_name())); EntryCollector collector; collector.Configure(settings); @@ -186,7 +189,8 @@ bool DictCompiler::BuildTable(DictSettings* settings, } } // build .reverse.bin - ReverseDb reverse_db(RelocateToUserDirectory(dict_name_ + ".reverse.bin")); + ReverseDb reverse_db(RelocateToUserDirectory(prefix_, + dict_name_ + ".reverse.bin")); if (!reverse_db.Build(settings, collector.syllabary, vocabulary, @@ -199,9 +203,10 @@ bool DictCompiler::BuildTable(DictSettings* settings, } bool DictCompiler::BuildPrism(const string &schema_file, - uint32_t dict_file_checksum, uint32_t schema_file_checksum) { + uint32_t dict_file_checksum, + uint32_t schema_file_checksum) { LOG(INFO) << "building prism..."; - prism_ = New(RelocateToUserDirectory(prism_->file_name())); + prism_ = New(RelocateToUserDirectory(prefix_, prism_->file_name())); // get syllabary from table Syllabary syllabary; diff --git a/src/rime/dict/dict_compiler.h b/src/rime/dict/dict_compiler.h index 7eb9641e4..0e274970a 100644 --- a/src/rime/dict/dict_compiler.h +++ b/src/rime/dict/dict_compiler.h @@ -27,7 +27,7 @@ class DictCompiler { kDump = 4, }; - RIME_API DictCompiler(Dictionary *dictionary); + RIME_API DictCompiler(Dictionary *dictionary, const string& prefix = ""); RIME_API bool Compile(const string &schema_file); void set_options(int options) { options_ = options; } @@ -37,13 +37,15 @@ class DictCompiler { const vector& dict_files, uint32_t dict_file_checksum); bool BuildPrism(const string& schema_file, - uint32_t dict_file_checksum, uint32_t schema_file_checksum); + uint32_t dict_file_checksum, + uint32_t schema_file_checksum); bool BuildReverseLookupDict(ReverseDb* db, uint32_t dict_file_checksum); string dict_name_; an prism_; an
table_; int options_ = 0; + string prefix_; }; } // namespace rime diff --git a/src/rime/dict/dictionary.cc b/src/rime/dict/dictionary.cc index ee29a057c..996d83a54 100644 --- a/src/rime/dict/dictionary.cc +++ b/src/rime/dict/dictionary.cc @@ -281,11 +281,11 @@ bool Dictionary::loaded() const { // DictionaryComponent members static const ResourceType kPrismResourceType = { - "prism", "", ".prism.bin" + "prism", "build/", ".prism.bin" }; static const ResourceType kTableResourceType = { - "table", "", ".table.bin" + "table", "build/", ".table.bin" }; DictionaryComponent::DictionaryComponent() @@ -321,7 +321,6 @@ Dictionary* DictionaryComponent::CreateDictionaryWithName(const string& dict_name, const string& prism_name) { // obtain prism and table objects - boost::filesystem::path path(Service::instance().deployer().user_data_dir); auto table = table_map_[dict_name].lock(); if (!table) { auto file_path = table_resource_resolver_->ResolvePath(dict_name).string(); diff --git a/src/rime/dict/reverse_lookup_dictionary.cc b/src/rime/dict/reverse_lookup_dictionary.cc index c6404e090..46cd27f1b 100644 --- a/src/rime/dict/reverse_lookup_dictionary.cc +++ b/src/rime/dict/reverse_lookup_dictionary.cc @@ -226,7 +226,7 @@ an ReverseLookupDictionary::GetDictSettings() { } static const ResourceType kReverseDbResourceType = { - "reverse_db", "", ".reverse.bin" + "reverse_db", "build/", ".reverse.bin" }; ReverseLookupDictionaryComponent::ReverseLookupDictionaryComponent() diff --git a/src/rime/lever/deployment_tasks.cc b/src/rime/lever/deployment_tasks.cc index 639db48ac..962092844 100644 --- a/src/rime/lever/deployment_tasks.cc +++ b/src/rime/lever/deployment_tasks.cc @@ -288,6 +288,17 @@ static bool TrashCustomizedCopy(const fs::path& shared_copy, return false; } +static bool MaybeCreateDirectory(fs::path dir) { + if (!fs::exists(dir)) { + boost::system::error_code ec; + if (!fs::create_directories(dir, ec)) { + LOG(ERROR) << "error creating directory '" << dir.string() << "'."; + return false; + } + } + return true; +} + bool SchemaUpdate::Run(Deployer* deployer) { fs::path source_path(schema_file_); if (!fs::exists(source_path)) { @@ -314,6 +325,7 @@ bool SchemaUpdate::Run(Deployer* deployer) { LOG(INFO) << "patched copy of schema '" << schema_id << "' is moved to trash"; } + // TODO: compile the config file if needs update string dict_name; @@ -329,7 +341,10 @@ bool SchemaUpdate::Run(Deployer* deployer) { return false; } LOG(INFO) << "preparing dictionary '" << dict_name << "'."; - DictCompiler dict_compiler(dict.get()); + if (!MaybeCreateDirectory(user_data_path / "build")) { + return false; + } + DictCompiler dict_compiler(dict.get(), "build/"); if (verbose_) { dict_compiler.set_options(DictCompiler::kRebuild | DictCompiler::kDump); }