提交 29998f07 编写于 作者: F Filip Filmar 提交者: Kaushik Iska

Configures ICU to load the timezone data (#13952)

The timezone data in Fuchsia is at a fixed path. This will have the
flutter runner attempt to load it and log, but not fail if loading
does not work out.

Added two tests

(1) Shows that the specific TZ data version loaded takes effect after
initialization

(2) Shows that when TZ data files are absent the initialization
continues.
上级 af511bab
......@@ -1014,6 +1014,7 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/flutter_aot_runner.cm
FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/flutter_jit_product_runner.cmx
FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/flutter_jit_runner.cmx
FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/flutter_runner_tests.cmx
FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/flutter_runner_tzdata_tests.cmx
FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/jit_product_runtime
FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/jit_runtime
FILE: ../../../flutter/shell/platform/fuchsia/flutter/platform_view.cc
......@@ -1021,6 +1022,8 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/platform_view.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/runner.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/runner.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/runner_tzdata_unittest.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/runner_unittest.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/session_connection.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/session_connection.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/surface.cc
......
......@@ -4,6 +4,7 @@
},
"sandbox": {
"features": [
"config-data",
"deprecated-ambient-replace-as-executable",
"root-ssl-certificates"
],
......
......@@ -4,6 +4,7 @@
},
"sandbox": {
"features": [
"config-data",
"deprecated-ambient-replace-as-executable",
"root-ssl-certificates"
],
......
......@@ -4,8 +4,9 @@
},
"sandbox": {
"features": [
"root-ssl-certificates",
"deprecated-ambient-replace-as-executable"
"config-data",
"deprecated-ambient-replace-as-executable",
"root-ssl-certificates"
],
"services": [
"fuchsia.feedback.CrashReporter",
......
......@@ -4,8 +4,9 @@
},
"sandbox": {
"features": [
"root-ssl-certificates",
"deprecated-ambient-replace-as-executable"
"config-data",
"deprecated-ambient-replace-as-executable",
"root-ssl-certificates"
],
"services": [
"fuchsia.feedback.CrashReporter",
......
......@@ -308,6 +308,9 @@ executable("flutter_runner_unittests") {
"platform_view.cc",
"platform_view.h",
"platform_view_unittest.cc",
"runner.cc",
"runner.h",
"runner_unittest.cc",
"surface.cc",
"surface.h",
"task_observers.cc",
......@@ -335,6 +338,7 @@ executable("flutter_runner_unittests") {
"//build/fuchsia/pkg:scenic_cpp",
"//build/fuchsia/pkg:sys_cpp_testing",
"//flutter/lib/ui",
"//flutter/runtime",
"//flutter/shell/common",
"//flutter/shell/platform/fuchsia/runtime/dart/utils",
"//flutter/testing",
......@@ -343,6 +347,40 @@ executable("flutter_runner_unittests") {
]
}
executable("flutter_runner_tzdata_unittests") {
testonly = true
output_name = "flutter_runner_tzdata_tests"
sources = [
"runner.cc",
"runner.h",
"runner_tzdata_unittest.cc",
]
# This is needed for //third_party/googletest for linking zircon symbols.
libs = [ "//fuchsia/sdk/$host_os/arch/$target_cpu/sysroot/lib/libzircon.so" ]
deps = [
":aot",
":flutter_runner_fixtures",
"//build/fuchsia/fidl:fuchsia.accessibility.semantics",
"//build/fuchsia/pkg:async-loop-cpp",
"//build/fuchsia/pkg:async-loop-default",
"//build/fuchsia/pkg:scenic_cpp",
"//build/fuchsia/pkg:sys_cpp_testing",
"//flutter/lib/ui",
"//flutter/runtime",
"//flutter/shell/common",
"//flutter/shell/platform/fuchsia/runtime/dart/utils",
"//flutter/testing",
"//third_party/dart/runtime:libdart_jit",
"//third_party/dart/runtime/platform:libdart_platform_jit",
"//third_party/icu",
"//third_party/skia",
]
}
fuchsia_archive("flutter_runner_tests") {
testonly = true
......@@ -352,6 +390,49 @@ fuchsia_archive("flutter_runner_tests") {
binary = "$target_name"
resources = [
{
path = rebase_path("//third_party/icu/common/icudtl.dat")
dest = "icudtl.dat"
},
{
path = rebase_path(
"$flutter_root/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/metaZones.res")
dest = "tzdata/metaZones.res"
},
{
path = rebase_path(
"$flutter_root/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/timezoneTypes.res")
dest = "tzdata/timezoneTypes.res"
},
{
path = rebase_path(
"$flutter_root/shell/platform/fuchsia/flutter/tests/tzdata/2019a/44/le/zoneinfo64.res")
dest = "tzdata/zoneinfo64.res"
},
]
meta_dir = "$flutter_root/shell/platform/fuchsia/flutter/meta"
libraries = common_libs
meta = [
{
path = rebase_path("meta/$target_name.cmx")
dest = "$target_name.cmx"
},
]
}
fuchsia_archive("flutter_runner_tzdata_tests") {
testonly = true
deps = [
":flutter_runner_tzdata_unittests",
]
binary = "$target_name"
resources = [
{
path = rebase_path("//third_party/icu/common/icudtl.dat")
......
......@@ -4,8 +4,9 @@
},
"sandbox": {
"features": [
"root-ssl-certificates",
"config-data",
"deprecated-ambient-replace-as-executable",
"root-ssl-certificates",
"vulkan"
],
"services": [
......
......@@ -4,8 +4,9 @@
},
"sandbox": {
"features": [
"root-ssl-certificates",
"config-data",
"deprecated-ambient-replace-as-executable",
"root-ssl-certificates",
"vulkan"
],
"services": [
......
......@@ -4,9 +4,10 @@
},
"sandbox": {
"features": [
"config-data",
"deprecated-ambient-replace-as-executable",
"root-ssl-certificates",
"vulkan",
"deprecated-ambient-replace-as-executable"
"vulkan"
],
"services": [
"fuchsia.accessibility.SettingsManager",
......
......@@ -4,9 +4,10 @@
},
"sandbox": {
"features": [
"config-data",
"deprecated-ambient-replace-as-executable",
"root-ssl-certificates",
"vulkan",
"deprecated-ambient-replace-as-executable"
"vulkan"
],
"services": [
"fuchsia.accessibility.SettingsManager",
......
{
"program": {
"binary": "bin/app"
"binary": "bin/app",
"env_vars": [
"ICU_TIMEZONE_FILES_DIR=/pkg/data/tzdata"
]
},
"sandbox": {
"features": [
"vulkan",
"deprecated-ambient-replace-as-executable"
"deprecated-ambient-replace-as-executable",
"vulkan"
],
"services": [
"fuchsia.accessibility.semantics.SemanticsManager",
......
{
"program": {
"binary": "bin/app"
},
"sandbox": {
"features": [
"deprecated-ambient-replace-as-executable",
"vulkan"
],
"services": [
"fuchsia.accessibility.semantics.SemanticsManager",
"fuchsia.intl.PropertyProvider",
"fuchsia.process.Launcher"
]
}
}
......@@ -10,6 +10,8 @@
#include <zircon/status.h>
#include <zircon/types.h>
#include <fcntl.h>
#include <stdint.h>
#include <sstream>
#include <utility>
......@@ -29,6 +31,13 @@ namespace {
static constexpr char kIcuDataPath[] = "/pkg/data/icudtl.dat";
// Environment variable containing the path to the directory containing the
// timezone files.
static constexpr char kICUTZEnv[] = "ICU_TIMEZONE_FILES_DIR";
// The data directory containing ICU timezone data files.
static constexpr char kICUTZDataDir[] = "/config/data/tzdata/icu/44/le";
// Map the memory into the process and return a pointer to the memory.
uintptr_t GetICUData(const fuchsia::mem::Buffer& icu_data) {
uint64_t data_size = icu_data.size;
......@@ -46,6 +55,33 @@ uintptr_t GetICUData(const fuchsia::mem::Buffer& icu_data) {
return 0u;
}
// Initializes the timezone data if available. Timezone data file in Fuchsia
// is at a fixed directory path. Returns true on success. As a side effect
// sets the value of the environment variable "ICU_TIMEZONE_FILES_DIR" to a
// fixed value which is fuchsia-specific.
bool InitializeTZData() {
// We need the ability to change the env variable for testing, so not
// overwriting if set.
setenv(kICUTZEnv, kICUTZDataDir, 0 /* No overwrite */);
const std::string tzdata_dir = getenv(kICUTZEnv);
// Try opening the path to check if present. No need to verify that it is a
// directory since ICU loading will return an error if the TZ data path is
// wrong.
int fd = openat(AT_FDCWD, tzdata_dir.c_str(), O_RDONLY);
if (fd < 0) {
FML_LOG(INFO) << "Could not open: '" << tzdata_dir
<< "', proceeding without loading the timezone database: "
<< strerror(errno);
return false;
}
if (!close(fd)) {
FML_LOG(WARNING) << "Could not close: " << tzdata_dir << ": "
<< strerror(errno);
}
return true;
}
// Return value indicates if initialization was successful.
bool InitializeICU() {
const char* data_path = kIcuDataPath;
......@@ -60,10 +96,18 @@ bool InitializeICU() {
return false;
}
// If the loading fails, soldier on. The loading is optional as we don't
// want to crash the engine in transition.
InitializeTZData();
// Pass the data to ICU.
UErrorCode err = U_ZERO_ERROR;
udata_setCommonData(reinterpret_cast<const char*>(data), &err);
return err == U_ZERO_ERROR;
if (err != U_ZERO_ERROR) {
FML_LOG(ERROR) << "error loading ICU data: " << err;
return false;
}
return true;
}
} // namespace
......@@ -223,11 +267,23 @@ void Runner::OnApplicationTerminate(const Application* application) {
}
void Runner::SetupICU() {
if (!InitializeICU()) {
// Exposes the TZ data setup for testing. Failing here is not fatal.
Runner::SetupTZDataInternal();
if (!Runner::SetupICUInternal()) {
FML_LOG(ERROR) << "Could not initialize ICU data.";
}
}
// static
bool Runner::SetupICUInternal() {
return InitializeICU();
}
// static
bool Runner::SetupTZDataInternal() {
return InitializeTZData();
}
#if !defined(DART_PRODUCT)
void Runner::SetupTraceObserver() {
trace_observer_ = std::make_unique<trace::TraceObserver>();
......
......@@ -64,6 +64,15 @@ class Runner final : public fuchsia::sys::Runner {
void SetupTraceObserver();
#endif // !defined(DART_PRODUCT)
// Called from SetupICU, for testing only. Returns false on error.
static bool SetupICUInternal();
// Called from SetupICU, for testing only. Returns false on error.
static bool SetupTZDataInternal();
#if defined(FRIEND_TEST)
FRIEND_TEST(RunnerTest, TZData);
FRIEND_TEST(RunnerTZDataTest, LoadsWithoutTZDataPresent);
#endif // defined(FRIEND_TEST)
FML_DISALLOW_COPY_AND_ASSIGN(Runner);
};
......
// Copyright 2013 The Flutter 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 <gtest/gtest.h>
#include "runner.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
namespace flutter_runner {
// This test has not been configured with tzdata files. This test shows that
// even without the data files, the runner continues initialization. It will
// use whatever the base data exists in icudtl.dat.
TEST(RunnerTZDataTest, LoadsWithoutTZDataPresent) {
bool success = Runner::SetupICUInternal();
ASSERT_TRUE(success) << "failed to load set up ICU data";
}
} // namespace flutter_runner
// Copyright 2013 The Flutter 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 <gtest/gtest.h>
#include "runner.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
namespace flutter_runner {
TEST(RunnerTest, TZData) {
UErrorCode err = U_ZERO_ERROR;
const auto version_before = std::string(icu::TimeZone::getTZDataVersion(err));
ASSERT_EQ(U_ZERO_ERROR, err) << "unicode error: " << u_errorName(err);
// This loads the tzdata. In Fuchsia, we force the data from this package
// to be version 2019a, so that we can test the resource load.
bool success = Runner::SetupICUInternal();
ASSERT_TRUE(success) << "failed to load timezone data";
const auto version_after = std::string(icu::TimeZone::getTZDataVersion(err));
ASSERT_EQ(U_ZERO_ERROR, err) << "unicode error: " << u_errorName(err);
EXPECT_EQ("2019a", version_after);
}
} // namespace flutter_runner
# Timezone data for testing
This directory contains the fixed timezone data version 2019a for testing. It
is used in the runner tests to show that loading these files from a specified
location results in the TZ data version "2019a" becoming available to the
binaries.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册