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) {