mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Limit font fallback to those in the cache dir (#5270)
This reduces dependence on machine-specific font configuration, making tests a bit more reproducible.
This commit is contained in:
parent
574b2829c8
commit
49e172e54c
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user