diff --git a/.github/workflows/commit-ci.yml b/.github/workflows/commit-ci.yml index d1ea73f245..61a5b3ddfc 100644 --- a/.github/workflows/commit-ci.yml +++ b/.github/workflows/commit-ci.yml @@ -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: diff --git a/Makefile b/Makefile index db306332b6..58784112a2 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/rime/algo/encoder.cc b/src/rime/algo/encoder.cc index 64290424a8..8e793c6aa3 100644 --- a/src/rime/algo/encoder.cc +++ b/src/rime/algo/encoder.cc @@ -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; } } diff --git a/src/rime/common.h b/src/rime/common.h index 9b937b0736..71971a445f 100644 --- a/src/rime/common.h +++ b/src/rime/common.h @@ -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 diff --git a/src/rime/dict/dict_compiler.cc b/src/rime/dict/dict_compiler.cc index 5996ee2cc3..3d4ddaa23c 100644 --- a/src/rime/dict/dict_compiler.cc +++ b/src/rime/dict/dict_compiler.cc @@ -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 resolver( diff --git a/src/rime/dict/entry_collector.cc b/src/rime/dict/entry_collector.cc index e9fa7404a9..2fa571d87e 100644 --- a/src/rime/dict/entry_collector.cc +++ b/src/rime/dict/entry_collector.cc @@ -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); } } diff --git a/src/rime/gear/simplifier.cc b/src/rime/gear/simplifier.cc index 073e3f0e75..6109194376 100644 --- a/src/rime/gear/simplifier.cc +++ b/src/rime/gear/simplifier.cc @@ -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; } diff --git a/src/rime/lever/deployment_tasks.cc b/src/rime/lever/deployment_tasks.cc index 6dedb63c81..305c8385ab 100644 --- a/src/rime/lever/deployment_tasks.cc +++ b/src/rime/lever/deployment_tasks.cc @@ -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))); @@ -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 t(new SchemaUpdate(entry)); if (!t->Run(deployer)) success = false; @@ -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; @@ -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) @@ -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") || @@ -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") && diff --git a/src/rime/lever/switcher_settings.cc b/src/rime/lever/switcher_settings.cc index 6439a2fa9d..50f8f0df7c 100644 --- a/src/rime/lever/switcher_settings.cc +++ b/src/rime/lever/switcher_settings.cc @@ -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; @@ -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); } diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 9e6e153713..a24cd51f0f 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -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) @@ -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()