Skip to content

Commit

Permalink
Merge From Upstream (#2)
Browse files Browse the repository at this point in the history
This includes changes from ab7e69e upto 4d8bb87, i.e. librime 1.11.0.

Co-authored-by: Bambooin <[email protected]>
Co-authored-by: 居戎氏 <[email protected]>
Co-authored-by: fxliang <[email protected]>
  • Loading branch information
4 people authored Mar 31, 2024
1 parent 1a25326 commit b42d235
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 47 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/commit-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
steps:
- name: Checkout last commit
uses: actions/checkout@v4
- name: Install clang-format
run: brew install clang-format
- name: Lint
- name: Install latest lang-format
run: brew update && brew install clang-format
- name: Code style lint
run: make clang-format-lint

linux:
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ install-debug uninstall-debug
all: release

clang-format-lint:
find ${RIME_SOURCE_PATH} -name '*.cc' -o -name '*.h' | xargs clang-format -Werror --dry-run || { echo Please lint your code by '"'"make clang-format-apply"'"'.; false; }
find ${RIME_SOURCE_PATH} \! -path 'plugins/*/*' -a \( -name '*.cc' -o -name '*.h' \) | \
xargs clang-format -Werror --dry-run || { echo Please lint your code by '"'"make clang-format-apply"'"'.; false; }

clang-format-apply:
find ${RIME_SOURCE_PATH} -name '*.cc' -o -name '*.h' | xargs clang-format --verbose -i
find ${RIME_SOURCE_PATH} \! -path 'plugins/*/*' -a \( -name '*.cc' -o -name '*.h' \) | xargs clang-format --verbose -i

deps:
$(MAKE) -f deps.mk
Expand Down
8 changes: 4 additions & 4 deletions src/rime/algo/encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ bool TableEncoder::DfsEncode(const string& phrase,
}
string encoded;
if (Encode(*code, &encoded)) {
DLOG(INFO) << "encode '" << phrase << "': "
<< "[" << code->ToString() << "] -> [" << encoded << "]";
DLOG(INFO) << "encode '" << phrase << "': " << "[" << code->ToString()
<< "] -> [" << encoded << "]";
collector_->CreateEntry(phrase, encoded, value);
return true;
} else {
DLOG(WARNING) << "failed to encode '" << phrase << "': "
<< "[" << code->ToString() << "]";
DLOG(WARNING) << "failed to encode '" << phrase << "': " << "["
<< code->ToString() << "]";
return false;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/rime/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ class path : public std::filesystem::path {
friend path operator/(const fs_path& lhs, const char* rhs) {
return path(lhs) /= path(rhs);
}
#ifdef RIME_ENABLE_LOGGING
friend std::ostream& operator<<(std::ostream& os, const path& p) {
return os << p.u8string();
}
#endif
};

} // namespace rime
Expand Down
4 changes: 2 additions & 2 deletions src/rime/dict/dict_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ bool DictCompiler::Compile(const path& schema_file) {
} else {
rebuild_prism = true;
}
LOG(INFO) << dict_file << "[" << dict_files.size() << " file(s)]"
<< " (" << dict_file_checksum << ")";
LOG(INFO) << dict_file << "[" << dict_files.size() << " file(s)]" << " ("
<< dict_file_checksum << ")";
LOG(INFO) << schema_file << " (" << schema_file_checksum << ")";
{
the<ResourceResolver> resolver(
Expand Down
4 changes: 2 additions & 2 deletions src/rime/dict/entry_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ void EntryCollector::Collect(const path& dict_file) {
encode_queue.push({word, weight_str});
}
if (!stem_str.empty() && !code_str.empty()) {
DLOG(INFO) << "add stem '" << word << "': "
<< "[" << code_str << "] = [" << stem_str << "]";
DLOG(INFO) << "add stem '" << word << "': " << "[" << code_str << "] = ["
<< stem_str << "]";
stems[word].insert(stem_str);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rime/gear/simplifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Simplifier::Simplifier(const Ticket& ticket)
void Simplifier::Initialize() {
initialized_ = true; // no retry
path opencc_config_path = path(opencc_config_);
if (opencc_config_path.extension().string() == ".ini") {
if (opencc_config_path.extension().u8string() == ".ini") {
LOG(ERROR) << "please upgrade opencc_config to an opencc 1.0 config file.";
return;
}
Expand Down
14 changes: 7 additions & 7 deletions src/rime/lever/deployment_tasks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ bool DetectModifications::Run(Deployer* deployer) {
for (fs::directory_iterator iter(p), end; iter != end; ++iter) {
path entry(iter->path());
if (fs::is_regular_file(fs::canonical(entry)) &&
entry.extension().string() == ".yaml" &&
entry.filename().string() != "user.yaml") {
entry.extension().u8string() == ".yaml" &&
entry.filename().u8string() != "user.yaml") {
last_modified =
(std::max)(last_modified,
filesystem::to_time_t(fs::last_write_time(entry)));
Expand Down Expand Up @@ -471,7 +471,7 @@ bool PrebuildAllSchemas::Run(Deployer* deployer) {
for (fs::directory_iterator iter(shared_data_path), end; iter != end;
++iter) {
path entry(iter->path());
if (boost::ends_with(entry.filename().string(), ".schema.yaml")) {
if (boost::ends_with(entry.filename().u8string(), ".schema.yaml")) {
the<DeploymentTask> t(new SchemaUpdate(entry));
if (!t->Run(deployer))
success = false;
Expand Down Expand Up @@ -536,7 +536,7 @@ bool UserDictSync::Run(Deployer* deployer) {
}

static bool IsCustomizedCopy(const path& file_path) {
auto file_name = file_path.filename().string();
auto file_name = file_path.filename().u8string();
if (boost::ends_with(file_name, ".yaml") &&
!boost::ends_with(file_name, ".custom.yaml")) {
Config config;
Expand All @@ -563,7 +563,7 @@ bool BackupConfigFiles::Run(Deployer* deployer) {
path entry(iter->path());
if (!fs::is_regular_file(entry))
continue;
auto file_extension = entry.extension().string();
auto file_extension = entry.extension().u8string();
bool is_yaml_file = file_extension == ".yaml";
bool is_text_file = file_extension == ".txt";
if (!is_yaml_file && !is_text_file)
Expand Down Expand Up @@ -603,7 +603,7 @@ bool CleanupTrash::Run(Deployer* deployer) {
path entry(iter->path());
if (!fs::is_regular_file(entry))
continue;
auto file_name = entry.filename().string();
auto file_name = entry.filename().u8string();
if (file_name == "rime.log" || boost::ends_with(file_name, ".bin") ||
boost::ends_with(file_name, ".reverse.kct") ||
boost::ends_with(file_name, ".userdb.kct.old") ||
Expand Down Expand Up @@ -656,7 +656,7 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
try {
// preparing files
for (const auto& entry : fs::directory_iterator(dir)) {
const string& file_name(entry.path().filename().string());
const string& file_name(entry.path().filename().u8string());
if (entry.is_regular_file() && !entry.is_symlink() &&
boost::starts_with(file_name, app_name) &&
boost::ends_with(file_name, ".log") &&
Expand Down
3 changes: 2 additions & 1 deletion src/rime/lever/switcher_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void SwitcherSettings::GetAvailableSchemasFromDirectory(const path& dir) {
}
for (fs::directory_iterator it(dir), end; it != end; ++it) {
path file_path(it->path());
if (boost::ends_with(file_path.string(), ".schema.yaml")) {
if (boost::ends_with(file_path.u8string(), ".schema.yaml")) {
Config config;
if (config.LoadFromFile(file_path)) {
SchemaInfo info;
Expand Down Expand Up @@ -88,6 +88,7 @@ void SwitcherSettings::GetAvailableSchemasFromDirectory(const path& dir) {
}
}
config.GetString("schema/description", &info.description);
// output path in native encoding.
info.file_path = file_path.string();
available_.push_back(info);
}
Expand Down
48 changes: 23 additions & 25 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,11 @@ set(rime_api_console_src "rime_api_console.cc")
add_executable(rime_api_console ${rime_api_console_src})
target_link_libraries(rime_api_console ${rime_console_deps})

set(rime_patch_src "rime_patch.cc")
add_executable(rime_patch ${rime_patch_src})
target_link_libraries(rime_patch
${rime_library}
${rime_levers_library})

set(rime_console_src "rime_console.cc")
add_executable(rime_console ${rime_console_src})
target_compile_definitions(rime_console PRIVATE RIME_IMPORTS)
target_link_libraries(rime_console ${rime_console_deps})

set(rime_dict_manager_src "rime_dict_manager.cc")
add_executable(rime_dict_manager ${rime_dict_manager_src})
target_link_libraries(rime_dict_manager
${rime_library}
${rime_dict_library}
${rime_levers_library})

set(rime_deployer_src "rime_deployer.cc")
add_executable(rime_deployer ${rime_deployer_src})
target_compile_definitions(rime_deployer PRIVATE RIME_IMPORTS)
Expand All @@ -37,20 +24,31 @@ target_link_libraries(rime_deployer
${rime_dict_library}
${rime_levers_library})

set(rime_table_decompiler_src
"rime_table_decompiler.cc"
${CMAKE_SOURCE_DIR}/src/rime/dict/table.cc
${CMAKE_SOURCE_DIR}/src/rime/dict/mapped_file.cc
${CMAKE_SOURCE_DIR}/src/rime/dict/string_table.cc
${CMAKE_SOURCE_DIR}/src/rime/dict/vocabulary.cc
)
add_executable(rime_table_decompiler ${rime_table_decompiler_src})
target_link_libraries(rime_table_decompiler
set(rime_dict_manager_src "rime_dict_manager.cc")
add_executable(rime_dict_manager ${rime_dict_manager_src})
target_link_libraries(rime_dict_manager
${rime_library}
${rime_dict_library})
${rime_dict_library}
${rime_levers_library})

set(rime_patch_src "rime_patch.cc")
add_executable(rime_patch ${rime_patch_src})
target_link_libraries(rime_patch
${rime_library}
${rime_levers_library})

install(TARGETS rime_deployer DESTINATION ${BIN_INSTALL_DIR})
install(TARGETS rime_dict_manager DESTINATION ${BIN_INSTALL_DIR})
install(TARGETS rime_table_decompiler DESTINATION ${BIN_INSTALL_DIR})

install(TARGETS rime_patch DESTINATION ${BIN_INSTALL_DIR})

# do not work with Windows DLL; interfaces to dict are missing DLL export.
if(NOT WIN32 OR NOT BUILD_SHARED_LIBS)
set(rime_table_decompiler_src "rime_table_decompiler.cc")
add_executable(rime_table_decompiler ${rime_table_decompiler_src})
target_compile_definitions(rime_deployer PRIVATE RIME_IMPORTS)
target_link_libraries(rime_table_decompiler
${rime_library}
${rime_dict_library})

install(TARGETS rime_table_decompiler DESTINATION ${BIN_INSTALL_DIR})
endif()

0 comments on commit b42d235

Please sign in to comment.