8000 fixed locator for icudtl.dat (#2950) · Hotkey/arangodb@fa9246c · GitHub
[go: up one dir, main page]

Skip to content

Commit fa9246c

Browse files
authored
fixed locator for icudtl.dat (arangodb#2950)
1 parent 60e6237 commit fa9246c

File tree

4 files changed

+46
-34
lines changed

4 files changed

+46
-34
lines changed

Installation/Pipeline/include/build_EDITION_OS.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ mkdir -p build/tests
9999
cp -a build-$edition/bin build
100100
cp -a build-$edition/etc build
101101
cp -a build-$edition/tests/arangodbtests build/tests
102+
cp -a build-$edition/tests/icudtl.dat build/tests
102103

103104
echo "`date +%T` done..."

lib/ApplicationFeatures/LanguageFeature.cpp

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
#include "ApplicationFeatures/LanguageFeature.h"
2424
#include "Basics/ArangoGlobalContext.h"
2525

26-
#include "Basics/Utf8Helper.h"
27-
#include "Basics/files.h"
2826
#include "Basics/FileUtils.h"
27+
#include "Basics/Utf8Helper.h"
2928
#include "Basics/directories.h"
29+
#include "Basics/files.h"
3030
#include "Logger/Logger.h"
3131
#include "ProgramOptions/ProgramOptions.h"
3232
#include "ProgramOptions/Section.h"
@@ -37,10 +37,9 @@ using namespace arangodb::options;
3737

3838
LanguageFeature::LanguageFeature(
3939
application_features::ApplicationServer* server)
40-
:
41-
ApplicationFeature(server, "Language"),
42-
_binaryPath(server->getBinaryPath()),
43-
_icuDataPtr(nullptr) {
40+
: ApplicationFeature(server, "Language"),
41+
_binaryPath(server->getBinaryPath()),
42+
_icuDataPtr(nullptr) {
4443
setOptional(false);
4544
requiresElevatedPrivileges(false);
4645
startsAfter("Logger");
@@ -52,57 +51,58 @@ LanguageFeature::~LanguageFeature() {
5251
}
5352
}
5453

55-
5654
void LanguageFeature::collectOptions(
5755
std::shared_ptr<options::ProgramOptions> options) {
5856
options->addHiddenOption("--default-language", "ISO-639 language code",
5957
new StringParameter(&_language));
6058
}
6159

62-
void* LanguageFeature::prepareIcu(std::string const& binaryPath, std::string const& binaryExecutionPath, std::string& path, std::string const& binaryName) {
60+
void* LanguageFeature::prepareIcu(std::string const& binaryPath,
61+
std::string const& binaryExecutionPath,
62+
std::string& path,
63+
std::string const& binaryName) {
6364
char const* icuDataEnv = getenv("ICU_DATA");
64-
6565
std::string fn("icudtl.dat");
66+
6667
if (icuDataEnv != nullptr) {
67-
path = icuDataEnv + fn;
68+
path = FileUtils::buildFilename(icuDataEnv, fn);
6869
}
6970

7071
if (path.empty() || !TRI_IsRegularFile(path.c_str())) {
7172
if (!path.empty()) {
7273
LOG_TOPIC(WARN, arangodb::Logger::FIXME)
73-
<< "failed to locate '" << fn
74-
<< "' at '"<< path << "'";
74+
<< "failed to locate '" << fn << "' at '" << path << "'";
7575
}
76-
std::string bpfn = binaryExecutionPath + TRI_DIR_SEPARATOR_STR + fn;
77-
76+
77+
std::string bpfn = FileUtils::buildFilename(binaryExecutionPath, fn);
78+
7879
if (TRI_IsRegularFile(fn.c_str())) {
7980
path = fn;
80-
}
81-
else if (TRI_IsRegularFile(bpfn.c_str())) {
81+
} else if (TRI_IsRegularFile(bpfn.c_str())) {
8282
path = bpfn;
83-
}
84-
else {
85-
std::string argv_0 = binaryExecutionPath + TRI_DIR_SEPARATOR_STR + binaryName;
83+
} else {
84+
std::string argv_0 = FileUtils::buildFilename(binaryExecutionPath, binaryName);
8685
path = TRI_LocateInstallDirectory(argv_0.c_str(), binaryPath.c_str());
87-
path += ICU_DESTINATION_DIRECTORY TRI_DIR_SEPARATOR_STR + fn;
86+
path = FileUtils::buildFilename(path, ICU_DESTINATION_DIRECTORY, fn);
87+
8888
if (!TRI_IsRegularFile(path.c_str())) {
89-
// Try whether we have an absolute install prefix:
90-
path = ICU_DESTINATION_DIRECTORY TRI_DIR_SEPARATOR_STR + fn;
89+
// Try whether we have an absolute install prefix:
90+
path = FileUtils::buildFilename(ICU_DESTINATION_DIRECTORY, fn);
9191
}
9292
}
93+
9394
if (!TRI_IsRegularFile(path.c_str())) {
94-
std::string msg =
95-
std::string("cannot locate '") + path + "'; please make sure it is available; "
96-
"the variable ICU_DATA='";
95+
std::string msg = std::string("cannot locate '") + path +
96+
"'; please make sure it is available; "
97+
"the variable ICU_DATA='";
9798
if (getenv("ICU_DATA") != nullptr) {
9899
msg += getenv("ICU_DATA");
99100
}
100101
msg += "' should point to the directory containing '" + fn + "'";
101102

102103
LOG_TOPIC(FATAL, arangodb::Logger::FIXME) << msg;
103104
FATAL_ERROR_EXIT();
104-
}
105-
else {
105+
} else {
106106
std::string icu_path = path.substr(0, path.length() - fn.length());
107107
FileUtils::makePathAbsolute(icu_path);
108108
FileUtils::normalizePath(icu_path);
@@ -117,7 +117,9 @@ void* LanguageFeature::prepareIcu(std::string const& binaryPath, std::string con
117117
void* icuDataPtr = TRI_SlurpFile(TRI_UNKNOWN_MEM_ZONE, path.c_str(), nullptr);
118118

119119
if (icuDataPtr == nullptr) {
120-
LOG_TOPIC(FATAL, arangodb::Logger::FIXME) << "failed to load '" << fn << "' at '" << path << "' - " << TRI_last_error();
120+
LOG_TOPIC(FATAL, arangodb::Logger::FIXME)
121+
<< "failed to load '" << fn << "' at '" << path << "' - "
122+
<< TRI_last_error();
121123
FATAL_ERROR_EXIT();
122124
}
123125
return icuDataPtr;
@@ -128,11 +130,14 @@ void LanguageFeature::prepare() {
128130
auto context = ArangoGlobalContext::CONTEXT;
129131
std::string binaryExecutionPath = context->getBinaryPath();
130132
std::string binaryName = context->binaryName();
131-
_icuDataPtr = LanguageFeature::prepareIcu(_binaryPath, binaryExecutionPath, p, binaryName);
133+
_icuDataPtr = LanguageFeature::prepareIcu(_binaryPath, binaryExecutionPath, p,
134+
binaryName);
132135

133-
if (!Utf8Helper::DefaultUtf8Helper.setCollatorLanguage(_language, _icuDataPtr)) {
134-
LOG_TOPIC(FATAL, arangodb::Logger::FIXME) << "error initializing ICU with the contents of '" << p << "'";
135-
FATAL_ERROR_EXIT();
136+
if (!Utf8Helper::DefaultUtf8Helper.setCollatorLanguage(_language,
137+
_icuDataPtr)) {
138+
LOG_TOPIC(FATAL, arangodb::Logger::FIXME)
139+
<< "error initializing ICU with the contents of '" << p << "'";
140+
FATAL_ERROR_EXIT();
136141
}
137142
}
138143

@@ -147,5 +152,6 @@ void LanguageFeature::start() {
147152
languageName = Utf8Helper::DefaultUtf8Helper.getCollatorLanguage();
148153
}
149154

150-
LOG_TOPIC(DEBUG, arangodb::Logger::FIXME) << "using default language '" << languageName << "'";
155+
LOG_TOPIC(DEBUG, arangodb::Logger::FIXME)
156+
<< "using default language '" << languageName << "'";
151157
}

tests/Basics/json-test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@
5353
// --SECTION-- setup / tear-down
5454
// -----------------------------------------------------------------------------
5555

56+
extern char const* ARGV0;
57+
5658
struct CJsonSetup {
5759
CJsonSetup () {
58-
IcuInitializer::setup("./3rdParty/V8/v8/third_party/icu/common/icudtl.dat");
60+
IcuInitializer::setup(ARGV0);
5961
}
6062
};
6163

tests/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
#include "Logger/Logger.h"
44
#include "Random/RandomGenerator.h"
55

6+
char const* ARGV0 = "";
7+
68
int main( int argc, char* argv[] )
79
{
10+
ARGV0 = argv[0];
811
arangodb::RandomGenerator::initialize(arangodb::RandomGenerator::RandomType::MERSENNE);
912
// global setup...
1013
arangodb::Logger::initialize(false);

0 commit comments

Comments
 (0)
0