Commit 49e172e5 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Limit font fallback to those in the cache dir (#5270)

This reduces dependence on machine-specific font configuration, making
tests a bit more reproducible.
parent 574b2829
......@@ -25,6 +25,8 @@ const String _kPath = '/runner';
String shellPath;
List<String> fontDirectories = <String>[cache.getCacheArtifacts().path];
void installHook() {
hack.registerPlatformPlugin(<TestPlatform>[TestPlatform.vm], () => new FlutterPlatform());
}
......@@ -62,7 +64,11 @@ Future<Process> _startProcess(String mainPath, { String packages, int observator
mainPath
]);
printTrace('$executable ${arguments.join(' ')}');
return Process.start(executable, arguments, environment: <String, String>{ 'FLUTTER_TEST': 'true' });
Map<String, String> environment = <String, String>{
'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('<fontconfig>');
for (String fontDir in fontDirectories) {
sb.writeln(' <dir>$fontDir</dir>');
}
sb.writeln(' <cachedir>/var/cache/fontconfig</cachedir>');
sb.writeln('</fontconfig>');
_cachedFontConfig = new File('${fontsDir.path}/fonts.conf');
_cachedFontConfig.createSync();
_cachedFontConfig.writeAsStringSync(sb.toString());
return _cachedFontConfig;
}
class FlutterPlatform extends PlatformPlugin {
@override
StreamChannel<dynamic> loadChannel(String mainPath, TestPlatform platform) {
......
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