Commit cec0ed0f authored by machenbach's avatar machenbach Committed by Commit bot

[icu] Support loading data file from default location

This allows using icu data, bundled in the icudtl.dat file,
to be loaded automatically from a default location
side-by-side with the executable.

The v8 stand-alone default is still to use statically
linked ICU data, but this will be switched in a separate
follow-up CL.

BUG=chromium:616033
LOG=y

Review-Url: https://codereview.chromium.org/2042253002
Cr-Commit-Position: refs/heads/master@{#36823}
parent ea139c5b
...@@ -641,12 +641,18 @@ action("run_mksnapshot") { ...@@ -641,12 +641,18 @@ action("run_mksnapshot") {
source_set("v8_maybe_snapshot") { source_set("v8_maybe_snapshot") {
if (v8_use_snapshot && v8_use_external_startup_data) { if (v8_use_snapshot && v8_use_external_startup_data) {
public_deps = [ ":v8_external_snapshot" ] public_deps = [
":v8_external_snapshot",
]
} else if (v8_use_snapshot) { } else if (v8_use_snapshot) {
public_deps = [ ":v8_snapshot" ] public_deps = [
":v8_snapshot",
]
} else { } else {
assert(!v8_use_external_startup_data) assert(!v8_use_external_startup_data)
public_deps = [ ":v8_nosnapshot" ] public_deps = [
":v8_nosnapshot",
]
} }
} }
...@@ -1886,6 +1892,8 @@ v8_source_set("v8_libbase") { ...@@ -1886,6 +1892,8 @@ v8_source_set("v8_libbase") {
"src/base/cpu.h", "src/base/cpu.h",
"src/base/division-by-constant.cc", "src/base/division-by-constant.cc",
"src/base/division-by-constant.h", "src/base/division-by-constant.h",
"src/base/file-utils.cc",
"src/base/file-utils.h",
"src/base/flags.h", "src/base/flags.h",
"src/base/format-macros.h", "src/base/format-macros.h",
"src/base/functional.cc", "src/base/functional.cc",
...@@ -2065,11 +2073,11 @@ if (current_toolchain == v8_snapshot_toolchain) { ...@@ -2065,11 +2073,11 @@ if (current_toolchain == v8_snapshot_toolchain) {
# Public targets # Public targets
# #
want_v8_shell = ( want_v8_shell =
(current_toolchain == host_toolchain && v8_toolset_for_shell == "host") || (current_toolchain == host_toolchain && v8_toolset_for_shell == "host") ||
(current_toolchain == v8_snapshot_toolchain && (current_toolchain == v8_snapshot_toolchain &&
v8_toolset_for_shell == "host") || v8_toolset_for_shell == "host") ||
(current_toolchain != host_toolchain && v8_toolset_for_shell == "target")) (current_toolchain != host_toolchain && v8_toolset_for_shell == "target")
group("gn_all") { group("gn_all") {
testonly = true testonly = true
...@@ -2079,22 +2087,18 @@ group("gn_all") { ...@@ -2079,22 +2087,18 @@ group("gn_all") {
":v8_simple_json_fuzzer", ":v8_simple_json_fuzzer",
":v8_simple_parser_fuzzer", ":v8_simple_parser_fuzzer",
":v8_simple_regexp_fuzzer", ":v8_simple_regexp_fuzzer",
":v8_simple_wasm_fuzzer",
":v8_simple_wasm_asmjs_fuzzer", ":v8_simple_wasm_asmjs_fuzzer",
":v8_simple_wasm_fuzzer",
"test:gn_all", "test:gn_all",
"tools:gn_all", "tools:gn_all",
] ]
if (want_v8_shell) { if (want_v8_shell) {
deps += [ deps += [ ":v8_shell" ]
":v8_shell",
]
} }
if (v8_test_isolation_mode != "noop") { if (v8_test_isolation_mode != "noop") {
deps += [ deps += [ ":d8_run" ]
":d8_run",
]
} }
} }
...@@ -2234,7 +2238,8 @@ v8_source_set("json_fuzzer") { ...@@ -2234,7 +2238,8 @@ v8_source_set("json_fuzzer") {
configs = [ ":internal_config" ] configs = [ ":internal_config" ]
} }
v8_fuzzer("json_fuzzer") {} v8_fuzzer("json_fuzzer") {
}
v8_source_set("parser_fuzzer") { v8_source_set("parser_fuzzer") {
sources = [ sources = [
...@@ -2248,7 +2253,8 @@ v8_source_set("parser_fuzzer") { ...@@ -2248,7 +2253,8 @@ v8_source_set("parser_fuzzer") {
configs = [ ":internal_config" ] configs = [ ":internal_config" ]
} }
v8_fuzzer("parser_fuzzer") {} v8_fuzzer("parser_fuzzer") {
}
v8_source_set("regexp_fuzzer") { v8_source_set("regexp_fuzzer") {
sources = [ sources = [
...@@ -2262,7 +2268,8 @@ v8_source_set("regexp_fuzzer") { ...@@ -2262,7 +2268,8 @@ v8_source_set("regexp_fuzzer") {
configs = [ ":internal_config" ] configs = [ ":internal_config" ]
} }
v8_fuzzer("regexp_fuzzer") {} v8_fuzzer("regexp_fuzzer") {
}
v8_source_set("wasm_fuzzer") { v8_source_set("wasm_fuzzer") {
sources = [ sources = [
...@@ -2276,7 +2283,8 @@ v8_source_set("wasm_fuzzer") { ...@@ -2276,7 +2283,8 @@ v8_source_set("wasm_fuzzer") {
configs = [ ":internal_config" ] configs = [ ":internal_config" ]
} }
v8_fuzzer("wasm_fuzzer") {} v8_fuzzer("wasm_fuzzer") {
}
v8_source_set("wasm_asmjs_fuzzer") { v8_source_set("wasm_asmjs_fuzzer") {
sources = [ sources = [
...@@ -2290,4 +2298,5 @@ v8_source_set("wasm_asmjs_fuzzer") { ...@@ -2290,4 +2298,5 @@ v8_source_set("wasm_asmjs_fuzzer") {
configs = [ ":internal_config" ] configs = [ ":internal_config" ]
} }
v8_fuzzer("wasm_asmjs_fuzzer") {} v8_fuzzer("wasm_asmjs_fuzzer") {
}
...@@ -6707,7 +6707,24 @@ class V8_EXPORT V8 { ...@@ -6707,7 +6707,24 @@ class V8_EXPORT V8 {
* If V8 was compiled with the ICU data in an external file, the location * If V8 was compiled with the ICU data in an external file, the location
* of the data file has to be provided. * of the data file has to be provided.
*/ */
static bool InitializeICU(const char* icu_data_file = NULL); V8_DEPRECATE_SOON(
"Use version with default location.",
static bool InitializeICU(const char* icu_data_file = nullptr));
/**
* Initialize the ICU library bundled with V8. The embedder should only
* invoke this method when using the bundled ICU. If V8 was compiled with
* the ICU data in an external file and when the default location of that
* file should be used, a path to the executable must be provided.
* Returns true on success.
*
* The default is a file called icudtl.dat side-by-side with the executable.
*
* Optionally, the location of the data file can be provided to override the
* default.
*/
static bool InitializeICUDefaultLocation(const char* exec_path,
const char* icu_data_file = nullptr);
/** /**
* Initialize the external startup data. The embedder only needs to * Initialize the external startup data. The embedder only needs to
......
...@@ -24,7 +24,7 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { ...@@ -24,7 +24,7 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Initialize V8. // Initialize V8.
V8::InitializeICU(); V8::InitializeICUDefaultLocation(argv[0]);
V8::InitializeExternalStartupData(argv[0]); V8::InitializeExternalStartupData(argv[0]);
Platform* platform = platform::CreateDefaultPlatform(); Platform* platform = platform::CreateDefaultPlatform();
V8::InitializePlatform(platform); V8::InitializePlatform(platform);
......
...@@ -687,7 +687,7 @@ void PrintMap(map<string, string>* m) { ...@@ -687,7 +687,7 @@ void PrintMap(map<string, string>* m) {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
v8::V8::InitializeICU(); v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::V8::InitializeExternalStartupData(argv[0]); v8::V8::InitializeExternalStartupData(argv[0]);
v8::Platform* platform = v8::platform::CreateDefaultPlatform(); v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform); v8::V8::InitializePlatform(platform);
......
...@@ -75,7 +75,7 @@ class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { ...@@ -75,7 +75,7 @@ class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
v8::V8::InitializeICU(); v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::V8::InitializeExternalStartupData(argv[0]); v8::V8::InitializeExternalStartupData(argv[0]);
v8::Platform* platform = v8::platform::CreateDefaultPlatform(); v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform); v8::V8::InitializePlatform(platform);
......
...@@ -5513,6 +5513,10 @@ bool v8::V8::InitializeICU(const char* icu_data_file) { ...@@ -5513,6 +5513,10 @@ bool v8::V8::InitializeICU(const char* icu_data_file) {
return i::InitializeICU(icu_data_file); return i::InitializeICU(icu_data_file);
} }
bool v8::V8::InitializeICUDefaultLocation(const char* exec_path,
const char* icu_data_file) {
return i::InitializeICUDefaultLocation(exec_path, icu_data_file);
}
void v8::V8::InitializeExternalStartupData(const char* directory_path) { void v8::V8::InitializeExternalStartupData(const char* directory_path) {
i::InitializeExternalStartupData(directory_path); i::InitializeExternalStartupData(directory_path);
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/base/file-utils.h"
#include <string.h>
#include "src/base/platform/platform.h"
namespace v8 {
namespace internal {
char* RelativePath(char** buffer, const char* exec_path, const char* name) {
DCHECK(exec_path);
int path_separator = static_cast<int>(strlen(exec_path)) - 1;
while (path_separator >= 0 &&
!base::OS::isDirectorySeparator(exec_path[path_separator])) {
path_separator--;
}
if (path_separator >= 0) {
int name_length = static_cast<int>(strlen(name));
*buffer =
reinterpret_cast<char*>(calloc(path_separator + name_length + 2, 1));
*buffer[0] = '\0';
strncat(*buffer, exec_path, path_separator + 1);
strncat(*buffer, name, name_length);
} else {
*buffer = strdup(name);
}
return *buffer;
}
} // namespace internal
} // namespace v8
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_FILE_UTILS_H_
#define V8_FILE_UTILS_H_
namespace v8 {
namespace internal {
// Helper functions to manipulate file paths.
char* RelativePath(char** buffer, const char* exec_path, const char* name);
} // namespace internal
} // namespace v8
#endif // V8_FILE_UTILS_H_
...@@ -2422,7 +2422,7 @@ int Shell::Main(int argc, char* argv[]) { ...@@ -2422,7 +2422,7 @@ int Shell::Main(int argc, char* argv[]) {
#endif // defined(_MSC_VER) #endif // defined(_MSC_VER)
#endif // defined(_WIN32) || defined(_WIN64) #endif // defined(_WIN32) || defined(_WIN64)
if (!SetOptions(argc, argv)) return 1; if (!SetOptions(argc, argv)) return 1;
v8::V8::InitializeICU(options.icu_data_file); v8::V8::InitializeICUDefaultLocation(argv[0], options.icu_data_file);
#ifndef V8_SHARED #ifndef V8_SHARED
g_platform = i::FLAG_verify_predictable g_platform = i::FLAG_verify_predictable
? new PredictablePlatform() ? new PredictablePlatform()
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "unicode/putil.h" #include "unicode/putil.h"
#include "unicode/udata.h" #include "unicode/udata.h"
#include "src/base/file-utils.h"
#define ICU_UTIL_DATA_FILE 0 #define ICU_UTIL_DATA_FILE 0
#define ICU_UTIL_DATA_SHARED 1 #define ICU_UTIL_DATA_SHARED 1
#define ICU_UTIL_DATA_STATIC 2 #define ICU_UTIL_DATA_STATIC 2
...@@ -38,6 +40,26 @@ void free_icu_data_ptr() { ...@@ -38,6 +40,26 @@ void free_icu_data_ptr() {
} // namespace } // namespace
#endif #endif
bool InitializeICUDefaultLocation(const char* exec_path,
const char* icu_data_file) {
#if !defined(V8_I18N_SUPPORT)
return true;
#else
#if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
if (icu_data_file) {
return InitializeICU(icu_data_file);
}
char* icu_data_file_default;
RelativePath(&icu_data_file_default, exec_path, "icudtl.dat");
bool result = InitializeICU(icu_data_file_default);
free(icu_data_file_default);
return result;
#else
return InitializeICU(NULL);
#endif
#endif
}
bool InitializeICU(const char* icu_data_file) { bool InitializeICU(const char* icu_data_file) {
#if !defined(V8_I18N_SUPPORT) #if !defined(V8_I18N_SUPPORT)
return true; return true;
......
...@@ -14,6 +14,11 @@ namespace internal { ...@@ -14,6 +14,11 @@ namespace internal {
// function should be called before ICU is used. // function should be called before ICU is used.
bool InitializeICU(const char* icu_data_file); bool InitializeICU(const char* icu_data_file);
// Like above, but using the default icudtl.dat location if icu_data_file is
// not specified.
bool InitializeICUDefaultLocation(const char* exec_path,
const char* icu_data_file);
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -150,7 +150,7 @@ int main(int argc, char** argv) { ...@@ -150,7 +150,7 @@ int main(int argc, char** argv) {
} }
i::CpuFeatures::Probe(true); i::CpuFeatures::Probe(true);
V8::InitializeICU(); V8::InitializeICUDefaultLocation(argv[0]);
v8::Platform* platform = v8::platform::CreateDefaultPlatform(); v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform); v8::V8::InitializePlatform(platform);
v8::V8::Initialize(); v8::V8::Initialize();
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "src/base/file-utils.h"
#include "src/base/logging.h" #include "src/base/logging.h"
#include "src/base/platform/platform.h" #include "src/base/platform/platform.h"
#include "src/utils.h" #include "src/utils.h"
...@@ -77,27 +78,6 @@ void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) { ...@@ -77,27 +78,6 @@ void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) {
atexit(&FreeStartupData); atexit(&FreeStartupData);
} }
char* RelativePath(char** buffer, const char* exec_path, const char* name) {
DCHECK(exec_path);
int path_separator = static_cast<int>(strlen(exec_path)) - 1;
while (path_separator >= 0 &&
!base::OS::isDirectorySeparator(exec_path[path_separator])) {
path_separator--;
}
if (path_separator >= 0) {
int name_length = static_cast<int>(strlen(name));
*buffer =
reinterpret_cast<char*>(calloc(path_separator + name_length + 2, 1));
*buffer[0] = '\0';
strncat(*buffer, exec_path, path_separator + 1);
strncat(*buffer, name, name_length);
} else {
*buffer = strdup(name);
}
return *buffer;
}
} // namespace } // namespace
#endif // V8_USE_EXTERNAL_STARTUP_DATA #endif // V8_USE_EXTERNAL_STARTUP_DATA
......
...@@ -1675,6 +1675,8 @@ ...@@ -1675,6 +1675,8 @@
'base/cpu.h', 'base/cpu.h',
'base/division-by-constant.cc', 'base/division-by-constant.cc',
'base/division-by-constant.h', 'base/division-by-constant.h',
'base/file-utils.cc',
'base/file-utils.h',
'base/flags.h', 'base/flags.h',
'base/format-macros.h', 'base/format-macros.h',
'base/functional.cc', 'base/functional.cc',
......
...@@ -186,7 +186,7 @@ int main(int argc, char* argv[]) { ...@@ -186,7 +186,7 @@ int main(int argc, char* argv[]) {
} }
} }
v8::V8::InitializeICU(); v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::Platform* platform = v8::platform::CreateDefaultPlatform(); v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform); v8::V8::InitializePlatform(platform);
v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true); v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
......
...@@ -358,7 +358,7 @@ V8InitializationScope::V8InitializationScope(const char* exec_path) ...@@ -358,7 +358,7 @@ V8InitializationScope::V8InitializationScope(const char* exec_path)
i::FLAG_always_opt = false; i::FLAG_always_opt = false;
i::FLAG_allow_natives_syntax = true; i::FLAG_allow_natives_syntax = true;
v8::V8::InitializeICU(); v8::V8::InitializeICUDefaultLocation(exec_path);
v8::V8::InitializeExternalStartupData(exec_path); v8::V8::InitializeExternalStartupData(exec_path);
v8::V8::InitializePlatform(platform_.get()); v8::V8::InitializePlatform(platform_.get());
v8::V8::Initialize(); v8::V8::Initialize();
......
...@@ -40,7 +40,7 @@ class FuzzerSupport::ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { ...@@ -40,7 +40,7 @@ class FuzzerSupport::ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
FuzzerSupport::FuzzerSupport(int* argc, char*** argv) { FuzzerSupport::FuzzerSupport(int* argc, char*** argv) {
v8::internal::FLAG_expose_gc = true; v8::internal::FLAG_expose_gc = true;
v8::V8::SetFlagsFromCommandLine(argc, *argv, true); v8::V8::SetFlagsFromCommandLine(argc, *argv, true);
v8::V8::InitializeICU(); v8::V8::InitializeICUDefaultLocation((*argv)[0]);
v8::V8::InitializeExternalStartupData((*argv)[0]); v8::V8::InitializeExternalStartupData((*argv)[0]);
platform_ = v8::platform::CreateDefaultPlatform(); platform_ = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform_); v8::V8::InitializePlatform(platform_);
......
...@@ -142,7 +142,7 @@ std::pair<v8::base::TimeDelta, v8::base::TimeDelta> RunBaselineParser( ...@@ -142,7 +142,7 @@ std::pair<v8::base::TimeDelta, v8::base::TimeDelta> RunBaselineParser(
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
v8::V8::SetFlagsFromCommandLine(&argc, argv, true); v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
v8::V8::InitializeICU(); v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::Platform* platform = v8::platform::CreateDefaultPlatform(); v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform); v8::V8::InitializePlatform(platform);
v8::V8::Initialize(); v8::V8::Initialize();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment