From 49e172e54c468bec9de05b91a697d90c207dbdc6 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Fri, 5 Aug 2016 15:58:15 -0700 Subject: [PATCH] Limit font fallback to those in the cache dir (#5270) This reduces dependence on machine-specific font configuration, making tests a bit more reproducible. --- .../lib/src/test/flutter_platform.dart | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/test/flutter_platform.dart b/packages/flutter_tools/lib/src/test/flutter_platform.dart index 4e3f114ab80..ee4ac588f9a 100644 --- a/packages/flutter_tools/lib/src/test/flutter_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_platform.dart @@ -25,6 +25,8 @@ const String _kPath = '/runner'; String shellPath; +List fontDirectories = [cache.getCacheArtifacts().path]; + void installHook() { hack.registerPlatformPlugin([TestPlatform.vm], () => new FlutterPlatform()); } @@ -62,7 +64,11 @@ Future _startProcess(String mainPath, { String packages, int observator mainPath ]); printTrace('$executable ${arguments.join(' ')}'); - return Process.start(executable, arguments, environment: { 'FLUTTER_TEST': 'true' }); + Map environment = { + 'FLUTTER_TEST': 'true', + 'FONTCONFIG_FILE': _fontConfigFile.path, + }; + return Process.start(executable, arguments, environment: environment); } void _attachStandardStreams(Process process) { @@ -77,6 +83,29 @@ void _attachStandardStreams(Process process) { } } +File _cachedFontConfig; + +/// Returns a Fontconfig config file that limits font fallback to directories +/// specified in [fontDirectories]. +File get _fontConfigFile { + if (_cachedFontConfig != null) return _cachedFontConfig; + + Directory fontsDir = Directory.systemTemp.createTempSync('flutter_fonts'); + + StringBuffer sb = new StringBuffer(); + sb.writeln(''); + for (String fontDir in fontDirectories) { + sb.writeln(' $fontDir'); + } + sb.writeln(' /var/cache/fontconfig'); + sb.writeln(''); + + _cachedFontConfig = new File('${fontsDir.path}/fonts.conf'); + _cachedFontConfig.createSync(); + _cachedFontConfig.writeAsStringSync(sb.toString()); + return _cachedFontConfig; +} + class FlutterPlatform extends PlatformPlugin { @override StreamChannel loadChannel(String mainPath, TestPlatform platform) {