Commit a48130cf authored by Erik Chen's avatar Erik Chen Committed by Commit Bot

Make fontconfig cache construction deterministic...for now.

We currently front-load construction of the font cache [which takes 600ms] from
test run time to compile time. This saves 600ms on each test shard which uses
the font cache. The problem is that fontconfig cache construction is not
intended to be deterministic.

This CL sets some external state to ensure deterministic output. We have no way
of guaranteeing that this produces correct results, or even has the intended
effect. I personally think we should get rid of this step entirely. The time
saved per test shard is not worth the developer time it takes to try to make
fontconfig cache output deterministic.

This CL makes two changes:
  * Pregenerates a fixed uuid in the test_fonts directory.
  * Sets the mtime of the test_fonts directory to a date far in the past.

This CL also fixes the gn steps to correctly specify data outputs so the isolate
will actually pick up all the output.

Future rolls of fontconfig may break build determinism again. Hopefully
https://bugs.chromium.org/p/chromium/issues/detail?id=870731 will be fixed by
then so that this will be caught by the CQ/waterfall.

Change-Id: I89180cd3645ced2f83513c796195977f865df42c
Bug: 870622
Reviewed-on: https://chromium-review.googlesource.com/1161969
Commit-Queue: Erik Chen <erikchen@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarTakuto Ikuta <tikuta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580715}
parent 6fa916cc
...@@ -209,7 +209,6 @@ static_library("test_support") { ...@@ -209,7 +209,6 @@ static_library("test_support") {
] ]
if (current_toolchain == host_toolchain) { if (current_toolchain == host_toolchain) {
data_deps += [ ":do_generate_fontconfig_caches" ] data_deps += [ ":do_generate_fontconfig_caches" ]
data += [ "$root_out_dir/fontconfig_caches/" ]
} }
} }
...@@ -379,7 +378,8 @@ if (is_linux) { ...@@ -379,7 +378,8 @@ if (is_linux) {
] ]
args = [] args = []
outputs = [ outputs = [
"$root_out_dir/fontconfig_caches/STAMP", "$root_out_dir/fontconfig_caches/",
"$root_out_dir/test_fonts/.uuid",
] ]
} }
} }
......
...@@ -2,19 +2,53 @@ ...@@ -2,19 +2,53 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <sys/stat.h>
#include <time.h>
#include <utime.h>
#include <string> #include <string>
#include "base/base_paths.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/test/fontconfig_util_linux.h" #include "base/test/fontconfig_util_linux.h"
// GIANT WARNING: The point of this file is to front-load construction of the
// font cache [which takes 600ms] from test run time to compile time. This saves
// 600ms on each test shard which uses the font cache into compile time. The
// problem is that fontconfig cache construction is not intended to be
// deterministic. This executable tries to set some external state to ensure
// determinism. We have no way of guaranteeing that this produces correct
// results, or even has the intended effect.
int main(void) { int main(void) {
// fontconfig generates a random uuid and uses it to match font folders with
// the font cache. Rather than letting fontconfig generate a random uuid,
// which introduces build non-determinism, we place a fixed uuid in the font
// folder, which fontconfig will use to generate the cache.
base::FilePath dir_module;
base::PathService::Get(base::DIR_MODULE, &dir_module);
base::FilePath uuid_file_path =
dir_module.Append("test_fonts").Append(".uuid");
const char uuid[] = "df1acc8c-39d5-4a8b-8507-b1a7396ac3ac";
WriteFile(uuid_file_path, uuid, strlen(uuid));
// fontconfig writes the mtime of the test_fonts directory into the cache. It
// presumably checks this later to ensure that the cache is still up to date.
// We set the mtime to an arbitrary, fixed time in the past.
base::FilePath test_fonts_file_path = dir_module.Append("test_fonts");
struct stat old_times;
struct utimbuf new_times;
stat(test_fonts_file_path.value().c_str(), &old_times);
new_times.actime = old_times.st_atime;
// Use an arbitrary, fixed time.
new_times.modtime = 123456789;
utime(test_fonts_file_path.value().c_str(), &new_times);
base::SetUpFontconfig(); base::SetUpFontconfig();
base::TearDownFontconfig(); base::TearDownFontconfig();
base::FilePath dir_module;
CHECK(base::PathService::Get(base::DIR_MODULE, &dir_module));
base::FilePath fontconfig_caches = dir_module.Append("fontconfig_caches"); base::FilePath fontconfig_caches = dir_module.Append("fontconfig_caches");
CHECK(base::DirectoryExists(fontconfig_caches)); CHECK(base::DirectoryExists(fontconfig_caches));
base::FilePath stamp = fontconfig_caches.Append("STAMP"); base::FilePath stamp = fontconfig_caches.Append("STAMP");
......
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