Skip to content

Commit

Permalink
use semicolon as path delimiter on win32
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Feb 9, 2025
1 parent 7921881 commit c693163
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
19 changes: 11 additions & 8 deletions src/lib/fcitx-utils/standardpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#ifdef _WIN32
#include <io.h>
#include "utf8.h"
#define PATH_DELIMITER ";"
#else
#define PATH_DELIMITER ":"
#endif

#if __has_include(<paths.h>)
Expand Down Expand Up @@ -117,10 +120,10 @@ class StandardPathPrivate {
for (auto &path : pkgconfigDirFallback) {
path = constructPath(path, packageName);
}
pkgconfigDirs_ =
defaultPaths((isFcitx ? "FCITX_CONFIG_DIRS" : nullptr),
stringutils::join(pkgconfigDirFallback, ":").c_str(),
builtInPathMap, nullptr);
pkgconfigDirs_ = defaultPaths(
(isFcitx ? "FCITX_CONFIG_DIRS" : nullptr),
stringutils::join(pkgconfigDirFallback, PATH_DELIMITER).c_str(),
builtInPathMap, nullptr);

dataHome_ = defaultPath("XDG_DATA_HOME", ".local/share");
pkgdataHome_ =
Expand All @@ -135,8 +138,8 @@ class StandardPathPrivate {
}
pkgdataDirs_ = defaultPaths(
(isFcitx ? "FCITX_DATA_DIRS" : nullptr),
stringutils::join(pkgdataDirFallback, ":").c_str(), builtInPathMap,
skipBuiltInPath_ ? nullptr : "pkgdatadir");
stringutils::join(pkgdataDirFallback, PATH_DELIMITER).c_str(),
builtInPathMap, skipBuiltInPath_ ? nullptr : "pkgdatadir");
cacheHome_ = defaultPath("XDG_CACHE_HOME", ".cache");
auto tmpdir = getEnvironment("TMPDIR");
runtimeDir_ =
Expand Down Expand Up @@ -262,7 +265,7 @@ class StandardPathPrivate {
}
assert(dir.has_value());

auto rawDirs = stringutils::split(*dir, ":");
auto rawDirs = stringutils::split(*dir, PATH_DELIMITER);
for (auto &rawDir : rawDirs) {
rawDir = fs::cleanPath(rawDir);
}
Expand Down Expand Up @@ -762,7 +765,7 @@ std::string StandardPath::findExecutable(const std::string &name) {
}
#endif
}
auto paths = stringutils::split(sEnv, ":");
auto paths = stringutils::split(sEnv, PATH_DELIMITER);
for (auto &path : paths) {
path = fs::cleanPath(path);
auto fullPath = constructPath(path, name);
Expand Down
13 changes: 10 additions & 3 deletions src/lib/fcitx-utils/testing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
*/
#include "testing.h"
#include <cstdlib>
#include <filesystem>
#include <string>
#include <vector>
#include "environ.h"
#include "standardpath.h"
#include "stringutils.h"

#ifdef _WIN32
#define PATH_DELIMITER ";"
#else
#define PATH_DELIMITER ":"
#endif

namespace fcitx {

void setupTestingEnvironment(const std::string &testBinaryDir,
Expand All @@ -36,7 +43,7 @@ void setupTestingEnvironment(const std::string &testBinaryDir,
fullAddonDirs.push_back(StandardPath::fcitxPath("addondir"));

setEnvironment("FCITX_ADDON_DIRS",
stringutils::join(fullAddonDirs, ":").data());
stringutils::join(fullAddonDirs, PATH_DELIMITER).data());
// Make sure we don't write to user data.
setEnvironment("FCITX_DATA_HOME", "/Invalid/Path");
// Make sure we don't write to user data.
Expand All @@ -48,7 +55,7 @@ void setupTestingEnvironment(const std::string &testBinaryDir,
if (dataDir.empty()) {
continue;
}
if (dataDir[0] == '/') {
if (std::filesystem::path(dataDir).is_absolute()) {
fullDataDirs.push_back(dataDir);
} else {
fullDataDirs.push_back(
Expand All @@ -58,7 +65,7 @@ void setupTestingEnvironment(const std::string &testBinaryDir,
// Include the three testing only addons.
fullDataDirs.push_back(StandardPath::fcitxPath("pkgdatadir", "testing"));
setEnvironment("FCITX_DATA_DIRS",
stringutils::join(fullDataDirs, ":").data());
stringutils::join(fullDataDirs, PATH_DELIMITER).data());
}

} // namespace fcitx
15 changes: 12 additions & 3 deletions test/teststandardpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ using namespace fcitx;

#define TEST_ADDON_DIR FCITX5_SOURCE_DIR "/test/addon"

#ifdef _WIN32
#define PATH_DELIMITER ";"
#else
#define PATH_DELIMITER ":"
#endif

void test_basic() {
setEnvironment("XDG_CONFIG_HOME", "/TEST/PATH");
setEnvironment("XDG_CONFIG_DIRS",
"/TEST/PATH1/:/TEST/PATH2:/TEST/PATH2/:/TEST/PATH1");
"/TEST/PATH1/" PATH_DELIMITER "/TEST/PATH2" PATH_DELIMITER
"/TEST/PATH2/" PATH_DELIMITER "/TEST/PATH1");
setEnvironment("XDG_DATA_DIRS", TEST_ADDON_DIR);
StandardPath standardPath(true);

Expand Down Expand Up @@ -88,7 +95,8 @@ void test_basic() {

void test_nouser() {
setEnvironment("XDG_CONFIG_HOME", "/TEST/PATH");
setEnvironment("XDG_CONFIG_DIRS", "/TEST/PATH1:/TEST/PATH2");
setEnvironment("XDG_CONFIG_DIRS",
"/TEST/PATH1" PATH_DELIMITER "/TEST/PATH2");
setEnvironment("XDG_DATA_DIRS", TEST_ADDON_DIR);
StandardPath standardPath(true, true);

Expand Down Expand Up @@ -138,7 +146,8 @@ void test_nouser() {

void test_custom() {
setEnvironment("XDG_CONFIG_HOME", "/TEST/PATH");
setEnvironment("XDG_CONFIG_DIRS", "/TEST/PATH1:/TEST/PATH2");
setEnvironment("XDG_CONFIG_DIRS",
"/TEST/PATH1" PATH_DELIMITER "/TEST/PATH2");
setEnvironment("XDG_DATA_DIRS", TEST_ADDON_DIR);
StandardPath path("mypackage", {{"datadir", "/TEST/PATH3"}}, false, false);
FCITX_ASSERT(path.directories(fcitx::StandardPath::Type::PkgConfig) ==
Expand Down

0 comments on commit c693163

Please sign in to comment.