mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Revert "[flutter_tools] default tree-shake-icons to enabled and improve performance (#54923)" (#55413)
This reverts commit 0b93a9219b
.
This commit is contained in:
parent
72986f7bcf
commit
27d11da88f
@ -16,7 +16,6 @@ dependencies:
|
|||||||
# and run
|
# and run
|
||||||
# flutter update-packages --force-upgrade
|
# flutter update-packages --force-upgrade
|
||||||
flutter_gallery_assets: 0.1.9+2
|
flutter_gallery_assets: 0.1.9+2
|
||||||
cupertino_icons: 0.1.3
|
|
||||||
|
|
||||||
archive: 2.0.13 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
archive: 2.0.13 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||||
args: 1.6.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
args: 1.6.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||||
@ -92,4 +91,4 @@ flutter:
|
|||||||
- packages/flutter_gallery_assets/food/cherry_pie.png
|
- packages/flutter_gallery_assets/food/cherry_pie.png
|
||||||
- assets/999x1000.png
|
- assets/999x1000.png
|
||||||
|
|
||||||
# PUBSPEC CHECKSUM: 49fa
|
# PUBSPEC CHECKSUM: 3a55
|
||||||
|
@ -60,9 +60,9 @@ Future<Depfile> copyAssets(Environment environment, Directory outputDirectory) a
|
|||||||
file.parent.createSync(recursive: true);
|
file.parent.createSync(recursive: true);
|
||||||
final DevFSContent content = entry.value;
|
final DevFSContent content = entry.value;
|
||||||
if (content is DevFSFileContent && content.file is File) {
|
if (content is DevFSFileContent && content.file is File) {
|
||||||
inputs.add(content.file as File);
|
inputs.add(globals.fs.file(content.file.path));
|
||||||
if (!await iconTreeShaker.subsetFont(
|
if (!await iconTreeShaker.subsetFont(
|
||||||
input: content.file as File,
|
inputPath: content.file.path,
|
||||||
outputPath: file.path,
|
outputPath: file.path,
|
||||||
relativePath: entry.key,
|
relativePath: entry.key,
|
||||||
)) {
|
)) {
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:process/process.dart';
|
import 'package:process/process.dart';
|
||||||
import 'package:mime/mime.dart' as mime;
|
|
||||||
|
|
||||||
import '../../artifacts.dart';
|
import '../../artifacts.dart';
|
||||||
import '../../base/common.dart';
|
import '../../base/common.dart';
|
||||||
@ -21,7 +20,7 @@ import 'dart.dart';
|
|||||||
const String kIconTreeShakerFlag = 'TreeShakeIcons';
|
const String kIconTreeShakerFlag = 'TreeShakeIcons';
|
||||||
|
|
||||||
/// Whether icon font subsetting is enabled by default.
|
/// Whether icon font subsetting is enabled by default.
|
||||||
const bool kIconTreeShakerEnabledDefault = true;
|
const bool kIconTreeShakerEnabledDefault = false;
|
||||||
|
|
||||||
List<Map<String, dynamic>> _getList(dynamic object, String errorMessage) {
|
List<Map<String, dynamic>> _getList(dynamic object, String errorMessage) {
|
||||||
try {
|
try {
|
||||||
@ -67,12 +66,6 @@ class IconTreeShaker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The MIME type for ttf fonts.
|
|
||||||
static const Set<String> kTtfMimeTypes = <String>{
|
|
||||||
'font/ttf', // based on internet search
|
|
||||||
'application/x-font-ttf', // based on running locally.
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The [Source] inputs that targets using this should depend on.
|
/// The [Source] inputs that targets using this should depend on.
|
||||||
///
|
///
|
||||||
/// See [Target.inputs].
|
/// See [Target.inputs].
|
||||||
@ -84,7 +77,6 @@ class IconTreeShaker {
|
|||||||
|
|
||||||
final Environment _environment;
|
final Environment _environment;
|
||||||
final String _fontManifest;
|
final String _fontManifest;
|
||||||
Future<void> _iconDataProcessing;
|
|
||||||
Map<String, _IconTreeShakerData> _iconData;
|
Map<String, _IconTreeShakerData> _iconData;
|
||||||
|
|
||||||
final ProcessManager _processManager;
|
final ProcessManager _processManager;
|
||||||
@ -97,10 +89,10 @@ class IconTreeShaker {
|
|||||||
&& _environment.defines[kIconTreeShakerFlag] == 'true'
|
&& _environment.defines[kIconTreeShakerFlag] == 'true'
|
||||||
&& _environment.defines[kBuildMode] != 'debug';
|
&& _environment.defines[kBuildMode] != 'debug';
|
||||||
|
|
||||||
// Fills the [_iconData] map.
|
/// Fills the [_iconData] map.
|
||||||
Future<void> _getIconData(Environment environment) async {
|
Future<Map<String, _IconTreeShakerData>> _getIconData(Environment environment) async {
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final File appDill = environment.buildDir.childFile('app.dill');
|
final File appDill = environment.buildDir.childFile('app.dill');
|
||||||
@ -143,11 +135,13 @@ class IconTreeShaker {
|
|||||||
codePoints: iconData[entry.key],
|
codePoints: iconData[entry.key],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_iconData = result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calls font-subset, which transforms the [input] font file to a
|
/// Calls font-subset, which transforms the `inputPath` font file to a
|
||||||
/// subsetted version at [outputPath].
|
/// subsetted version at `outputPath`.
|
||||||
|
///
|
||||||
|
/// The `relativePath` parameter
|
||||||
///
|
///
|
||||||
/// All parameters are required.
|
/// All parameters are required.
|
||||||
///
|
///
|
||||||
@ -156,24 +150,15 @@ class IconTreeShaker {
|
|||||||
/// If the font-subset subprocess fails, it will [throwToolExit].
|
/// If the font-subset subprocess fails, it will [throwToolExit].
|
||||||
/// Otherwise, it will return true.
|
/// Otherwise, it will return true.
|
||||||
Future<bool> subsetFont({
|
Future<bool> subsetFont({
|
||||||
@required File input,
|
@required String inputPath,
|
||||||
@required String outputPath,
|
@required String outputPath,
|
||||||
@required String relativePath,
|
@required String relativePath,
|
||||||
}) async {
|
}) async {
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (input.lengthSync() < 12) {
|
|
||||||
return false;
|
_iconData ??= await _getIconData(_environment);
|
||||||
}
|
|
||||||
final String mimeType = mime.lookupMimeType(
|
|
||||||
input.path,
|
|
||||||
headerBytes: await input.openRead(0, 12).first,
|
|
||||||
);
|
|
||||||
if (!kTtfMimeTypes.contains(mimeType)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
await (_iconDataProcessing ??= _getIconData(_environment));
|
|
||||||
assert(_iconData != null);
|
assert(_iconData != null);
|
||||||
|
|
||||||
final _IconTreeShakerData iconTreeShakerData = _iconData[relativePath];
|
final _IconTreeShakerData iconTreeShakerData = _iconData[relativePath];
|
||||||
@ -191,7 +176,7 @@ class IconTreeShaker {
|
|||||||
final List<String> cmd = <String>[
|
final List<String> cmd = <String>[
|
||||||
fontSubset.path,
|
fontSubset.path,
|
||||||
outputPath,
|
outputPath,
|
||||||
input.path,
|
inputPath,
|
||||||
];
|
];
|
||||||
final String codePoints = iconTreeShakerData.codePoints.join(' ');
|
final String codePoints = iconTreeShakerData.codePoints.join(' ');
|
||||||
_logger.printTrace('Running font-subset: ${cmd.join(' ')}, '
|
_logger.printTrace('Running font-subset: ${cmd.join(' ')}, '
|
||||||
@ -201,7 +186,9 @@ class IconTreeShaker {
|
|||||||
fontSubsetProcess.stdin.writeln(codePoints);
|
fontSubsetProcess.stdin.writeln(codePoints);
|
||||||
await fontSubsetProcess.stdin.flush();
|
await fontSubsetProcess.stdin.flush();
|
||||||
await fontSubsetProcess.stdin.close();
|
await fontSubsetProcess.stdin.close();
|
||||||
} on Exception {
|
} on Exception catch (_) {
|
||||||
|
// handled by checking the exit code.
|
||||||
|
} on OSError catch (_) { // ignore: dead_code_on_catch_subtype
|
||||||
// handled by checking the exit code.
|
// handled by checking the exit code.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ void main() {
|
|||||||
kBuildMode: 'debug',
|
kBuildMode: 'debug',
|
||||||
kTargetPlatform: 'android-arm',
|
kTargetPlatform: 'android-arm',
|
||||||
kTrackWidgetCreation: 'true',
|
kTrackWidgetCreation: 'true',
|
||||||
kIconTreeShakerFlag: 'true',
|
kIconTreeShakerFlag: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
return BuildResult(success: true);
|
return BuildResult(success: true);
|
||||||
|
@ -23,8 +23,15 @@ import '../../../src/common.dart';
|
|||||||
import '../../../src/context.dart';
|
import '../../../src/context.dart';
|
||||||
import '../../../src/mocks.dart' as mocks;
|
import '../../../src/mocks.dart' as mocks;
|
||||||
|
|
||||||
final Platform kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false);
|
final Platform _kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false);
|
||||||
const List<int> _kTtfHeaderBytes = <int>[0, 1, 0, 0, 0, 15, 0, 128, 0, 3, 0, 112];
|
|
||||||
|
void main() {
|
||||||
|
BufferLogger logger;
|
||||||
|
MemoryFileSystem fs;
|
||||||
|
MockProcessManager mockProcessManager;
|
||||||
|
MockProcess fontSubsetProcess;
|
||||||
|
MockArtifacts mockArtifacts;
|
||||||
|
DevFSStringContent fontManifestContent;
|
||||||
|
|
||||||
const String dartPath = '/flutter/dart';
|
const String dartPath = '/flutter/dart';
|
||||||
const String constFinderPath = '/flutter/const_finder.snapshot.dart';
|
const String constFinderPath = '/flutter/const_finder.snapshot.dart';
|
||||||
@ -48,14 +55,6 @@ const List<String> fontSubsetArgs = <String>[
|
|||||||
inputPath,
|
inputPath,
|
||||||
];
|
];
|
||||||
|
|
||||||
void main() {
|
|
||||||
BufferLogger logger;
|
|
||||||
MemoryFileSystem fileSystem;
|
|
||||||
MockProcessManager mockProcessManager;
|
|
||||||
MockProcess fontSubsetProcess;
|
|
||||||
MockArtifacts mockArtifacts;
|
|
||||||
DevFSStringContent fontManifestContent;
|
|
||||||
|
|
||||||
void _addConstFinderInvocation(
|
void _addConstFinderInvocation(
|
||||||
String appDillPath, {
|
String appDillPath, {
|
||||||
int exitCode = 0,
|
int exitCode = 0,
|
||||||
@ -90,21 +89,19 @@ void main() {
|
|||||||
mockProcessManager = MockProcessManager();
|
mockProcessManager = MockProcessManager();
|
||||||
fontSubsetProcess = MockProcess();
|
fontSubsetProcess = MockProcess();
|
||||||
mockArtifacts = MockArtifacts();
|
mockArtifacts = MockArtifacts();
|
||||||
fileSystem = MemoryFileSystem();
|
|
||||||
|
fs = MemoryFileSystem();
|
||||||
logger = BufferLogger(
|
logger = BufferLogger(
|
||||||
terminal: AnsiTerminal(
|
terminal: AnsiTerminal(
|
||||||
stdio: mocks.MockStdio(),
|
stdio: mocks.MockStdio(),
|
||||||
platform: kNoAnsiPlatform,
|
platform: _kNoAnsiPlatform,
|
||||||
),
|
),
|
||||||
outputPreferences: OutputPreferences.test(showColor: false),
|
outputPreferences: OutputPreferences.test(showColor: false),
|
||||||
);
|
);
|
||||||
|
|
||||||
fileSystem.file(constFinderPath).createSync(recursive: true);
|
fs.file(constFinderPath).createSync(recursive: true);
|
||||||
fileSystem.file(dartPath).createSync(recursive: true);
|
fs.file(dartPath).createSync(recursive: true);
|
||||||
fileSystem.file(fontSubsetPath).createSync(recursive: true);
|
fs.file(fontSubsetPath).createSync(recursive: true);
|
||||||
fileSystem.file(inputPath)
|
|
||||||
..createSync(recursive: true)
|
|
||||||
..writeAsBytesSync(_kTtfHeaderBytes);
|
|
||||||
when(mockArtifacts.getArtifactPath(Artifact.constFinder)).thenReturn(constFinderPath);
|
when(mockArtifacts.getArtifactPath(Artifact.constFinder)).thenReturn(constFinderPath);
|
||||||
when(mockArtifacts.getArtifactPath(Artifact.fontSubset)).thenReturn(fontSubsetPath);
|
when(mockArtifacts.getArtifactPath(Artifact.fontSubset)).thenReturn(fontSubsetPath);
|
||||||
when(mockArtifacts.getArtifactPath(Artifact.engineDartBinary)).thenReturn(dartPath);
|
when(mockArtifacts.getArtifactPath(Artifact.engineDartBinary)).thenReturn(dartPath);
|
||||||
@ -112,11 +109,11 @@ void main() {
|
|||||||
|
|
||||||
Environment _createEnvironment(Map<String, String> defines) {
|
Environment _createEnvironment(Map<String, String> defines) {
|
||||||
return Environment.test(
|
return Environment.test(
|
||||||
fileSystem.directory('/icon_test')..createSync(recursive: true),
|
fs.directory('/icon_test')..createSync(recursive: true),
|
||||||
defines: defines,
|
defines: defines,
|
||||||
artifacts: mockArtifacts,
|
artifacts: mockArtifacts,
|
||||||
processManager: FakeProcessManager.any(),
|
processManager: FakeProcessManager.any(),
|
||||||
fileSystem: fileSystem,
|
fileSystem: fs,
|
||||||
logger: BufferLogger.test(),
|
logger: BufferLogger.test(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -132,19 +129,18 @@ void main() {
|
|||||||
fontManifestContent,
|
fontManifestContent,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
processManager: mockProcessManager,
|
processManager: mockProcessManager,
|
||||||
fileSystem: fileSystem,
|
fileSystem: fs,
|
||||||
artifacts: mockArtifacts,
|
artifacts: mockArtifacts,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
logger.errorText,
|
logger.errorText,
|
||||||
'Font subetting is not supported in debug mode. The --tree-shake-icons'
|
'Font subetting is not supported in debug mode. The --tree-shake-icons flag will be ignored.\n',
|
||||||
' flag will be ignored.\n',
|
|
||||||
);
|
);
|
||||||
expect(iconTreeShaker.enabled, false);
|
expect(iconTreeShaker.enabled, false);
|
||||||
|
|
||||||
final bool subsets = await iconTreeShaker.subsetFont(
|
final bool subsets = await iconTreeShaker.subsetFont(
|
||||||
input: fileSystem.file(inputPath),
|
inputPath: inputPath,
|
||||||
outputPath: outputPath,
|
outputPath: outputPath,
|
||||||
relativePath: relativePath,
|
relativePath: relativePath,
|
||||||
);
|
);
|
||||||
@ -165,7 +161,7 @@ void main() {
|
|||||||
null,
|
null,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
processManager: mockProcessManager,
|
processManager: mockProcessManager,
|
||||||
fileSystem: fileSystem,
|
fileSystem: fs,
|
||||||
artifacts: mockArtifacts,
|
artifacts: mockArtifacts,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -189,7 +185,7 @@ void main() {
|
|||||||
fontManifestContent,
|
fontManifestContent,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
processManager: mockProcessManager,
|
processManager: mockProcessManager,
|
||||||
fileSystem: fileSystem,
|
fileSystem: fs,
|
||||||
artifacts: mockArtifacts,
|
artifacts: mockArtifacts,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -213,13 +209,13 @@ void main() {
|
|||||||
fontManifestContent,
|
fontManifestContent,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
processManager: mockProcessManager,
|
processManager: mockProcessManager,
|
||||||
fileSystem: fileSystem,
|
fileSystem: fs,
|
||||||
artifacts: mockArtifacts,
|
artifacts: mockArtifacts,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
() async => await iconTreeShaker.subsetFont(
|
() => iconTreeShaker.subsetFont(
|
||||||
input: fileSystem.file(inputPath),
|
inputPath: inputPath,
|
||||||
outputPath: outputPath,
|
outputPath: outputPath,
|
||||||
relativePath: relativePath,
|
relativePath: relativePath,
|
||||||
),
|
),
|
||||||
@ -227,20 +223,20 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('Can subset a font', () async {
|
testWithoutContext('The happy path', () async {
|
||||||
final Environment environment = _createEnvironment(<String, String>{
|
final Environment environment = _createEnvironment(<String, String>{
|
||||||
kIconTreeShakerFlag: 'true',
|
kIconTreeShakerFlag: 'true',
|
||||||
kBuildMode: 'release',
|
kBuildMode: 'release',
|
||||||
});
|
});
|
||||||
final File appDill = environment.buildDir.childFile('app.dill')
|
final File appDill = environment.buildDir.childFile('app.dill')..createSync(recursive: true);
|
||||||
..createSync(recursive: true);
|
fs.file(inputPath).createSync(recursive: true);
|
||||||
|
|
||||||
final IconTreeShaker iconTreeShaker = IconTreeShaker(
|
final IconTreeShaker iconTreeShaker = IconTreeShaker(
|
||||||
environment,
|
environment,
|
||||||
fontManifestContent,
|
fontManifestContent,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
processManager: mockProcessManager,
|
processManager: mockProcessManager,
|
||||||
fileSystem: fileSystem,
|
fileSystem: fs,
|
||||||
artifacts: mockArtifacts,
|
artifacts: mockArtifacts,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -249,7 +245,7 @@ void main() {
|
|||||||
_resetFontSubsetInvocation(stdinSink: stdinSink);
|
_resetFontSubsetInvocation(stdinSink: stdinSink);
|
||||||
|
|
||||||
bool subsetted = await iconTreeShaker.subsetFont(
|
bool subsetted = await iconTreeShaker.subsetFont(
|
||||||
input: fileSystem.file(inputPath),
|
inputPath: inputPath,
|
||||||
outputPath: outputPath,
|
outputPath: outputPath,
|
||||||
relativePath: relativePath,
|
relativePath: relativePath,
|
||||||
);
|
);
|
||||||
@ -258,7 +254,7 @@ void main() {
|
|||||||
|
|
||||||
expect(subsetted, true);
|
expect(subsetted, true);
|
||||||
subsetted = await iconTreeShaker.subsetFont(
|
subsetted = await iconTreeShaker.subsetFont(
|
||||||
input: fileSystem.file(inputPath),
|
inputPath: inputPath,
|
||||||
outputPath: outputPath,
|
outputPath: outputPath,
|
||||||
relativePath: relativePath,
|
relativePath: relativePath,
|
||||||
);
|
);
|
||||||
@ -269,104 +265,33 @@ void main() {
|
|||||||
verify(mockProcessManager.start(fontSubsetArgs)).called(2);
|
verify(mockProcessManager.start(fontSubsetArgs)).called(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('Does not subset a non-ttf font', () async {
|
|
||||||
final Environment environment = _createEnvironment(<String, String>{
|
|
||||||
kIconTreeShakerFlag: 'true',
|
|
||||||
kBuildMode: 'release',
|
|
||||||
});
|
|
||||||
final File appDill = environment.buildDir.childFile('app.dill')
|
|
||||||
..createSync(recursive: true);
|
|
||||||
|
|
||||||
final IconTreeShaker iconTreeShaker = IconTreeShaker(
|
|
||||||
environment,
|
|
||||||
fontManifestContent,
|
|
||||||
logger: logger,
|
|
||||||
processManager: mockProcessManager,
|
|
||||||
fileSystem: fileSystem,
|
|
||||||
artifacts: mockArtifacts,
|
|
||||||
);
|
|
||||||
|
|
||||||
final mocks.CompleterIOSink stdinSink = mocks.CompleterIOSink();
|
|
||||||
_addConstFinderInvocation(appDill.path, stdout: validConstFinderResult);
|
|
||||||
_resetFontSubsetInvocation(stdinSink: stdinSink);
|
|
||||||
|
|
||||||
final File notAFont = fileSystem.file('input/foo/bar.txt')
|
|
||||||
..createSync(recursive: true)
|
|
||||||
..writeAsStringSync('I could not think of a better string');
|
|
||||||
final bool subsetted = await iconTreeShaker.subsetFont(
|
|
||||||
input: notAFont,
|
|
||||||
outputPath: outputPath,
|
|
||||||
relativePath: relativePath,
|
|
||||||
);
|
|
||||||
expect(subsetted, false);
|
|
||||||
|
|
||||||
verifyNever(mockProcessManager.run(getConstFinderArgs(appDill.path)));
|
|
||||||
verifyNever(mockProcessManager.start(fontSubsetArgs));
|
|
||||||
});
|
|
||||||
|
|
||||||
testWithoutContext('Does not subset an invalid ttf font', () async {
|
|
||||||
final Environment environment = _createEnvironment(<String, String>{
|
|
||||||
kIconTreeShakerFlag: 'true',
|
|
||||||
kBuildMode: 'release',
|
|
||||||
});
|
|
||||||
final File appDill = environment.buildDir.childFile('app.dill')
|
|
||||||
..createSync(recursive: true);
|
|
||||||
|
|
||||||
final IconTreeShaker iconTreeShaker = IconTreeShaker(
|
|
||||||
environment,
|
|
||||||
fontManifestContent,
|
|
||||||
logger: logger,
|
|
||||||
processManager: mockProcessManager,
|
|
||||||
fileSystem: fileSystem,
|
|
||||||
artifacts: mockArtifacts,
|
|
||||||
);
|
|
||||||
|
|
||||||
final mocks.CompleterIOSink stdinSink = mocks.CompleterIOSink();
|
|
||||||
_addConstFinderInvocation(appDill.path, stdout: validConstFinderResult);
|
|
||||||
_resetFontSubsetInvocation(stdinSink: stdinSink);
|
|
||||||
|
|
||||||
final File notAFont = fileSystem.file(inputPath)
|
|
||||||
..writeAsBytesSync(<int>[0, 1, 2]);
|
|
||||||
final bool subsetted = await iconTreeShaker.subsetFont(
|
|
||||||
input: notAFont,
|
|
||||||
outputPath: outputPath,
|
|
||||||
relativePath: relativePath,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(subsetted, false);
|
|
||||||
verifyNever(mockProcessManager.run(getConstFinderArgs(appDill.path)));
|
|
||||||
verifyNever(mockProcessManager.start(fontSubsetArgs));
|
|
||||||
});
|
|
||||||
|
|
||||||
testWithoutContext('Non-constant instances', () async {
|
testWithoutContext('Non-constant instances', () async {
|
||||||
final Environment environment = _createEnvironment(<String, String>{
|
final Environment environment = _createEnvironment(<String, String>{
|
||||||
kIconTreeShakerFlag: 'true',
|
kIconTreeShakerFlag: 'true',
|
||||||
kBuildMode: 'release',
|
kBuildMode: 'release',
|
||||||
});
|
});
|
||||||
final File appDill = environment.buildDir.childFile('app.dill')
|
final File appDill = environment.buildDir.childFile('app.dill')..createSync(recursive: true);
|
||||||
..createSync(recursive: true);
|
fs.file(inputPath).createSync(recursive: true);
|
||||||
|
|
||||||
final IconTreeShaker iconTreeShaker = IconTreeShaker(
|
final IconTreeShaker iconTreeShaker = IconTreeShaker(
|
||||||
environment,
|
environment,
|
||||||
fontManifestContent,
|
fontManifestContent,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
processManager: mockProcessManager,
|
processManager: mockProcessManager,
|
||||||
fileSystem: fileSystem,
|
fileSystem: fs,
|
||||||
artifacts: mockArtifacts,
|
artifacts: mockArtifacts,
|
||||||
);
|
);
|
||||||
|
|
||||||
_addConstFinderInvocation(appDill.path, stdout: constFinderResultWithInvalid);
|
_addConstFinderInvocation(appDill.path, stdout: constFinderResultWithInvalid);
|
||||||
|
|
||||||
await expectLater(
|
expect(
|
||||||
() async => await iconTreeShaker.subsetFont(
|
iconTreeShaker.subsetFont(
|
||||||
input: fileSystem.file(inputPath),
|
inputPath: inputPath,
|
||||||
outputPath: outputPath,
|
outputPath: outputPath,
|
||||||
relativePath: relativePath,
|
relativePath: relativePath,
|
||||||
),
|
),
|
||||||
throwsToolExit(
|
throwsToolExit(
|
||||||
message:
|
message: 'Avoid non-constant invocations of IconData or try to build again with --no-tree-shake-icons.',
|
||||||
'Avoid non-constant invocations of IconData or try to build'
|
|
||||||
' again with --no-tree-shake-icons.',
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -379,16 +304,15 @@ void main() {
|
|||||||
kIconTreeShakerFlag: 'true',
|
kIconTreeShakerFlag: 'true',
|
||||||
kBuildMode: 'release',
|
kBuildMode: 'release',
|
||||||
});
|
});
|
||||||
final File appDill = environment.buildDir.childFile('app.dill')
|
final File appDill = environment.buildDir.childFile('app.dill')..createSync(recursive: true);
|
||||||
..createSync(recursive: true);
|
fs.file(inputPath).createSync(recursive: true);
|
||||||
fileSystem.file(inputPath).createSync(recursive: true);
|
|
||||||
|
|
||||||
final IconTreeShaker iconTreeShaker = IconTreeShaker(
|
final IconTreeShaker iconTreeShaker = IconTreeShaker(
|
||||||
environment,
|
environment,
|
||||||
fontManifestContent,
|
fontManifestContent,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
processManager: mockProcessManager,
|
processManager: mockProcessManager,
|
||||||
fileSystem: fileSystem,
|
fileSystem: fs,
|
||||||
artifacts: mockArtifacts,
|
artifacts: mockArtifacts,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -396,9 +320,9 @@ void main() {
|
|||||||
_addConstFinderInvocation(appDill.path, stdout: validConstFinderResult);
|
_addConstFinderInvocation(appDill.path, stdout: validConstFinderResult);
|
||||||
_resetFontSubsetInvocation(exitCode: -1, stdinSink: stdinSink);
|
_resetFontSubsetInvocation(exitCode: -1, stdinSink: stdinSink);
|
||||||
|
|
||||||
await expectLater(
|
expect(
|
||||||
() async => await iconTreeShaker.subsetFont(
|
iconTreeShaker.subsetFont(
|
||||||
input: fileSystem.file(inputPath),
|
inputPath: inputPath,
|
||||||
outputPath: outputPath,
|
outputPath: outputPath,
|
||||||
relativePath: relativePath,
|
relativePath: relativePath,
|
||||||
),
|
),
|
||||||
@ -406,7 +330,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
verify(mockProcessManager.run(getConstFinderArgs(appDill.path))).called(1);
|
verify(mockProcessManager.run(getConstFinderArgs(appDill.path))).called(1);
|
||||||
verify(mockProcessManager.start(fontSubsetArgs)).called(1);
|
verifyNever(mockProcessManager.start(fontSubsetArgs));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('font-subset throws on write to sdtin', () async {
|
testWithoutContext('font-subset throws on write to sdtin', () async {
|
||||||
@ -414,15 +338,15 @@ void main() {
|
|||||||
kIconTreeShakerFlag: 'true',
|
kIconTreeShakerFlag: 'true',
|
||||||
kBuildMode: 'release',
|
kBuildMode: 'release',
|
||||||
});
|
});
|
||||||
final File appDill = environment.buildDir.childFile('app.dill')
|
final File appDill = environment.buildDir.childFile('app.dill')..createSync(recursive: true);
|
||||||
..createSync(recursive: true);
|
fs.file(inputPath).createSync(recursive: true);
|
||||||
|
|
||||||
final IconTreeShaker iconTreeShaker = IconTreeShaker(
|
final IconTreeShaker iconTreeShaker = IconTreeShaker(
|
||||||
environment,
|
environment,
|
||||||
fontManifestContent,
|
fontManifestContent,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
processManager: mockProcessManager,
|
processManager: mockProcessManager,
|
||||||
fileSystem: fileSystem,
|
fileSystem: fs,
|
||||||
artifacts: mockArtifacts,
|
artifacts: mockArtifacts,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -430,9 +354,9 @@ void main() {
|
|||||||
_addConstFinderInvocation(appDill.path, stdout: validConstFinderResult);
|
_addConstFinderInvocation(appDill.path, stdout: validConstFinderResult);
|
||||||
_resetFontSubsetInvocation(exitCode: -1, stdinSink: stdinSink);
|
_resetFontSubsetInvocation(exitCode: -1, stdinSink: stdinSink);
|
||||||
|
|
||||||
await expectLater(
|
expect(
|
||||||
() async => await iconTreeShaker.subsetFont(
|
iconTreeShaker.subsetFont(
|
||||||
input: fileSystem.file(inputPath),
|
inputPath: inputPath,
|
||||||
outputPath: outputPath,
|
outputPath: outputPath,
|
||||||
relativePath: relativePath,
|
relativePath: relativePath,
|
||||||
),
|
),
|
||||||
@ -440,7 +364,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
verify(mockProcessManager.run(getConstFinderArgs(appDill.path))).called(1);
|
verify(mockProcessManager.run(getConstFinderArgs(appDill.path))).called(1);
|
||||||
verify(mockProcessManager.start(fontSubsetArgs)).called(1);
|
verifyNever(mockProcessManager.start(fontSubsetArgs));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('Invalid font manifest', () async {
|
testWithoutContext('Invalid font manifest', () async {
|
||||||
@ -448,8 +372,8 @@ void main() {
|
|||||||
kIconTreeShakerFlag: 'true',
|
kIconTreeShakerFlag: 'true',
|
||||||
kBuildMode: 'release',
|
kBuildMode: 'release',
|
||||||
});
|
});
|
||||||
final File appDill = environment.buildDir.childFile('app.dill')
|
final File appDill = environment.buildDir.childFile('app.dill')..createSync(recursive: true);
|
||||||
..createSync(recursive: true);
|
fs.file(inputPath).createSync(recursive: true);
|
||||||
|
|
||||||
fontManifestContent = DevFSStringContent(invalidFontManifestJson);
|
fontManifestContent = DevFSStringContent(invalidFontManifestJson);
|
||||||
|
|
||||||
@ -458,15 +382,15 @@ void main() {
|
|||||||
fontManifestContent,
|
fontManifestContent,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
processManager: mockProcessManager,
|
processManager: mockProcessManager,
|
||||||
fileSystem: fileSystem,
|
fileSystem: fs,
|
||||||
artifacts: mockArtifacts,
|
artifacts: mockArtifacts,
|
||||||
);
|
);
|
||||||
|
|
||||||
_addConstFinderInvocation(appDill.path, stdout: validConstFinderResult);
|
_addConstFinderInvocation(appDill.path, stdout: validConstFinderResult);
|
||||||
|
|
||||||
await expectLater(
|
expect(
|
||||||
() async => await iconTreeShaker.subsetFont(
|
iconTreeShaker.subsetFont(
|
||||||
input: fileSystem.file(inputPath),
|
inputPath: inputPath,
|
||||||
outputPath: outputPath,
|
outputPath: outputPath,
|
||||||
relativePath: relativePath,
|
relativePath: relativePath,
|
||||||
),
|
),
|
||||||
@ -482,8 +406,8 @@ void main() {
|
|||||||
kIconTreeShakerFlag: 'true',
|
kIconTreeShakerFlag: 'true',
|
||||||
kBuildMode: 'release',
|
kBuildMode: 'release',
|
||||||
});
|
});
|
||||||
final File appDill = environment.buildDir.childFile('app.dill')
|
final File appDill = environment.buildDir.childFile('app.dill')..createSync(recursive: true);
|
||||||
..createSync(recursive: true);
|
fs.file(inputPath).createSync(recursive: true);
|
||||||
|
|
||||||
fontManifestContent = DevFSStringContent(invalidFontManifestJson);
|
fontManifestContent = DevFSStringContent(invalidFontManifestJson);
|
||||||
|
|
||||||
@ -492,15 +416,15 @@ void main() {
|
|||||||
fontManifestContent,
|
fontManifestContent,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
processManager: mockProcessManager,
|
processManager: mockProcessManager,
|
||||||
fileSystem: fileSystem,
|
fileSystem: fs,
|
||||||
artifacts: mockArtifacts,
|
artifacts: mockArtifacts,
|
||||||
);
|
);
|
||||||
|
|
||||||
_addConstFinderInvocation(appDill.path, exitCode: -1);
|
_addConstFinderInvocation(appDill.path, exitCode: -1);
|
||||||
|
|
||||||
await expectLater(
|
expect(
|
||||||
() async => await iconTreeShaker.subsetFont(
|
iconTreeShaker.subsetFont(
|
||||||
input: fileSystem.file(inputPath),
|
inputPath: inputPath,
|
||||||
outputPath: outputPath,
|
outputPath: outputPath,
|
||||||
relativePath: relativePath,
|
relativePath: relativePath,
|
||||||
),
|
),
|
||||||
|
@ -110,7 +110,7 @@ void main() {
|
|||||||
|
|
||||||
testUsingContext('build aot outputs timing info', () async {
|
testUsingContext('build aot outputs timing info', () async {
|
||||||
globals.fs
|
globals.fs
|
||||||
.file('.dart_tool/flutter_build/3f206b606f73e08587a94405f2e86fad/app.so')
|
.file('.dart_tool/flutter_build/0c21fd4ab3b8bde8b385ff01d08e0093/app.so')
|
||||||
.createSync(recursive: true);
|
.createSync(recursive: true);
|
||||||
when(globals.buildSystem.build(any, any))
|
when(globals.buildSystem.build(any, any))
|
||||||
.thenAnswer((Invocation invocation) async {
|
.thenAnswer((Invocation invocation) async {
|
||||||
|
@ -238,7 +238,6 @@ void main() {
|
|||||||
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
||||||
'-Ptrack-widget-creation=true',
|
'-Ptrack-widget-creation=true',
|
||||||
'-Pshrink=true',
|
'-Pshrink=true',
|
||||||
'-Ptree-shake-icons=true',
|
|
||||||
'assembleRelease',
|
'assembleRelease',
|
||||||
],
|
],
|
||||||
workingDirectory: anyNamed('workingDirectory'),
|
workingDirectory: anyNamed('workingDirectory'),
|
||||||
@ -268,7 +267,6 @@ void main() {
|
|||||||
'-Ptrack-widget-creation=true',
|
'-Ptrack-widget-creation=true',
|
||||||
'-Pshrink=true',
|
'-Pshrink=true',
|
||||||
'-Psplit-debug-info=${tempDir.path}',
|
'-Psplit-debug-info=${tempDir.path}',
|
||||||
'-Ptree-shake-icons=true',
|
|
||||||
'assembleRelease',
|
'assembleRelease',
|
||||||
],
|
],
|
||||||
workingDirectory: anyNamed('workingDirectory'),
|
workingDirectory: anyNamed('workingDirectory'),
|
||||||
@ -301,7 +299,6 @@ void main() {
|
|||||||
'-Ptrack-widget-creation=true',
|
'-Ptrack-widget-creation=true',
|
||||||
'-Pextra-front-end-options=foo,bar',
|
'-Pextra-front-end-options=foo,bar',
|
||||||
'-Pshrink=true',
|
'-Pshrink=true',
|
||||||
'-Ptree-shake-icons=true',
|
|
||||||
'assembleRelease',
|
'assembleRelease',
|
||||||
],
|
],
|
||||||
workingDirectory: anyNamed('workingDirectory'),
|
workingDirectory: anyNamed('workingDirectory'),
|
||||||
@ -332,7 +329,6 @@ void main() {
|
|||||||
'-Ptarget-platform=android-arm,android-arm64,android-x64',
|
'-Ptarget-platform=android-arm,android-arm64,android-x64',
|
||||||
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
||||||
'-Ptrack-widget-creation=true',
|
'-Ptrack-widget-creation=true',
|
||||||
'-Ptree-shake-icons=true',
|
|
||||||
'assembleRelease',
|
'assembleRelease',
|
||||||
],
|
],
|
||||||
workingDirectory: anyNamed('workingDirectory'),
|
workingDirectory: anyNamed('workingDirectory'),
|
||||||
@ -357,7 +353,6 @@ void main() {
|
|||||||
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
||||||
'-Ptrack-widget-creation=true',
|
'-Ptrack-widget-creation=true',
|
||||||
'-Pshrink=true',
|
'-Pshrink=true',
|
||||||
'-Ptree-shake-icons=true',
|
|
||||||
'assembleRelease',
|
'assembleRelease',
|
||||||
],
|
],
|
||||||
workingDirectory: anyNamed('workingDirectory'),
|
workingDirectory: anyNamed('workingDirectory'),
|
||||||
@ -419,7 +414,6 @@ void main() {
|
|||||||
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
||||||
'-Ptrack-widget-creation=true',
|
'-Ptrack-widget-creation=true',
|
||||||
'-Pshrink=true',
|
'-Pshrink=true',
|
||||||
'-Ptree-shake-icons=true',
|
|
||||||
'assembleRelease',
|
'assembleRelease',
|
||||||
],
|
],
|
||||||
workingDirectory: anyNamed('workingDirectory'),
|
workingDirectory: anyNamed('workingDirectory'),
|
||||||
@ -471,7 +465,6 @@ void main() {
|
|||||||
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
||||||
'-Ptrack-widget-creation=true',
|
'-Ptrack-widget-creation=true',
|
||||||
'-Pshrink=true',
|
'-Pshrink=true',
|
||||||
'-Ptree-shake-icons=true',
|
|
||||||
'assembleRelease',
|
'assembleRelease',
|
||||||
],
|
],
|
||||||
workingDirectory: anyNamed('workingDirectory'),
|
workingDirectory: anyNamed('workingDirectory'),
|
||||||
|
@ -225,7 +225,6 @@ void main() {
|
|||||||
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
||||||
'-Ptrack-widget-creation=false',
|
'-Ptrack-widget-creation=false',
|
||||||
'-Pshrink=true',
|
'-Pshrink=true',
|
||||||
'-Ptree-shake-icons=true',
|
|
||||||
'bundleRelease',
|
'bundleRelease',
|
||||||
],
|
],
|
||||||
workingDirectory: anyNamed('workingDirectory'),
|
workingDirectory: anyNamed('workingDirectory'),
|
||||||
@ -258,7 +257,6 @@ void main() {
|
|||||||
'-Ptarget-platform=android-arm,android-arm64,android-x64',
|
'-Ptarget-platform=android-arm,android-arm64,android-x64',
|
||||||
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
||||||
'-Ptrack-widget-creation=false',
|
'-Ptrack-widget-creation=false',
|
||||||
'-Ptree-shake-icons=true',
|
|
||||||
'bundleRelease',
|
'bundleRelease',
|
||||||
],
|
],
|
||||||
workingDirectory: anyNamed('workingDirectory'),
|
workingDirectory: anyNamed('workingDirectory'),
|
||||||
@ -283,7 +281,6 @@ void main() {
|
|||||||
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
||||||
'-Ptrack-widget-creation=false',
|
'-Ptrack-widget-creation=false',
|
||||||
'-Pshrink=true',
|
'-Pshrink=true',
|
||||||
'-Ptree-shake-icons=true',
|
|
||||||
'bundleRelease',
|
'bundleRelease',
|
||||||
],
|
],
|
||||||
workingDirectory: anyNamed('workingDirectory'),
|
workingDirectory: anyNamed('workingDirectory'),
|
||||||
@ -345,7 +342,6 @@ void main() {
|
|||||||
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
||||||
'-Ptrack-widget-creation=false',
|
'-Ptrack-widget-creation=false',
|
||||||
'-Pshrink=true',
|
'-Pshrink=true',
|
||||||
'-Ptree-shake-icons=true',
|
|
||||||
'assembleRelease',
|
'assembleRelease',
|
||||||
],
|
],
|
||||||
workingDirectory: anyNamed('workingDirectory'),
|
workingDirectory: anyNamed('workingDirectory'),
|
||||||
@ -397,7 +393,6 @@ void main() {
|
|||||||
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
|
||||||
'-Ptrack-widget-creation=false',
|
'-Ptrack-widget-creation=false',
|
||||||
'-Pshrink=true',
|
'-Pshrink=true',
|
||||||
'-Ptree-shake-icons=true',
|
|
||||||
'assembleRelease',
|
'assembleRelease',
|
||||||
],
|
],
|
||||||
workingDirectory: anyNamed('workingDirectory'),
|
workingDirectory: anyNamed('workingDirectory'),
|
||||||
|
Loading…
Reference in New Issue
Block a user