[tools]build ipa validate template icon files (#114841)

* [tools]build ipa validate template icon files

* use the same box for both validations, and added some unit test, and some nits

* add unit test for templateImageDirectory

* use fs.path.join intead of raw path

* use the correct filesystem

* lint

* use absolute path for flutter_template_images

* fix rebase

* update indentation
This commit is contained in:
hellohuanlin
2022-11-16 11:29:17 -08:00
committed by GitHub
parent b5345ff55e
commit dcae424783
6 changed files with 452 additions and 46 deletions

View File

@@ -94,6 +94,22 @@ void main() {
fileSystem.directory(fileSystem.path.join('ios', 'Runner.xcodeproj')).createSync(recursive: true);
fileSystem.directory(fileSystem.path.join('ios', 'Runner.xcworkspace')).createSync(recursive: true);
fileSystem.file(fileSystem.path.join('ios', 'Runner.xcodeproj', 'project.pbxproj')).createSync();
final String packageConfigPath = '${Cache.flutterRoot!}/packages/flutter_tools/.dart_tool/package_config.json';
fileSystem.file(packageConfigPath)
..createSync(recursive: true)
..writeAsStringSync('''
{
"configVersion": 2,
"packages": [
{
"name": "flutter_template_images",
"rootUri": "/flutter_template_images",
"packageUri": "lib/",
"languageVersion": "2.12"
}
]
}
''');
createCoreMockProjectFiles();
}
@@ -898,20 +914,20 @@ void main() {
<String>['build', 'ipa', '--no-pub']);
expect(
testLogger.statusText,
contains(
'┌─ App Settings ────────────────────────────────────────┐\n'
'│ Version Number: Missing │\n'
'│ Build Number: Missing │\n'
'│ Display Name: Missing │\n'
'│ Deployment Target: Missing │\n'
'│ Bundle Identifier: io.flutter.someProject │\n'
'│ │\n'
'│ You must set up the missing settings │\n'
'│ Instructions: https://docs.flutter.dev/deployment/ios │\n'
'└───────────────────────────────────────────────────────┘'
)
);
testLogger.statusText,
contains(
'┌─ App Settings ──────────────────────────────────────────────────────────────────┐\n'
'│ Version Number: Missing │\n'
'│ Build Number: Missing │\n'
'│ Display Name: Missing │\n'
'│ Deployment Target: Missing │\n'
'│ Bundle Identifier: io.flutter.someProject │\n'
'│ │\n'
'│ You must set up the missing settings. │\n'
'│ │\n'
'│ To update the settings, please refer to https://docs.flutter.dev/deployment/ios │\n'
'└─────────────────────────────────────────────────────────────────────────────────┘\n'
));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => fakeProcessManager,
@@ -952,16 +968,18 @@ void main() {
<String>['build', 'ipa', '--no-pub']);
expect(
testLogger.statusText,
contains(
'┌─ App Settings ────────────────────────────┐\n'
'│ Version Number: 12.34.56 │\n'
'│ Build Number: 666 │\n'
'│ Display Name: Awesome Gallery │\n'
'│ Deployment Target: 11.0 │\n'
'│ Bundle Identifier: io.flutter.someProject │\n'
'└───────────────────────────────────────────┘\n'
)
testLogger.statusText,
contains(
'┌─ App Settings ──────────────────────────────────────────────────────────────────┐\n'
'│ Version Number: 12.34.56 │\n'
'│ Build Number: 666 │\n'
'│ Display Name: Awesome Gallery │\n'
'│ Deployment Target: 11.0 │\n'
'│ Bundle Identifier: io.flutter.someProject │\n'
'│ │\n'
'│ To update the settings, please refer to https://docs.flutter.dev/deployment/ios │\n'
'└─────────────────────────────────────────────────────────────────────────────────┘\n'
)
);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
@@ -971,7 +989,147 @@ void main() {
PlistParser: () => plistUtils,
});
testUsingContext('Validate template app icons with conflicts', () async {
const String projectIconContentsJsonPath = 'ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json';
const String projectIconImagePath = 'ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png';
final String templateIconContentsJsonPath = '${Cache.flutterRoot!}/packages/flutter_tools/templates/app_shared/ios.tmpl/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json';
const String templateIconImagePath = '/flutter_template_images/templates/app_shared/ios.tmpl/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png';
fakeProcessManager.addCommands(<FakeCommand>[
xattrCommand,
setUpFakeXcodeBuildHandler(onRun: () {
fileSystem.file(templateIconContentsJsonPath)
..createSync(recursive: true)
..writeAsStringSync('''
{
"images": [
{
"size": "20x20",
"idiom": "iphone",
"filename": "Icon-App-20x20@2x.png",
"scale": "2x"
}
]
}
''');
fileSystem.file(templateIconImagePath)
..createSync(recursive: true)
..writeAsBytes(<int>[1, 2, 3]);
fileSystem.file(projectIconContentsJsonPath)
..createSync(recursive: true)
..writeAsStringSync('''
{
"images": [
{
"size": "20x20",
"idiom": "iphone",
"filename": "Icon-App-20x20@2x.png",
"scale": "2x"
}
]
}
''');
fileSystem.file(projectIconImagePath)
..createSync(recursive: true)
..writeAsBytes(<int>[1, 2, 3]);
}),
exportArchiveCommand(exportOptionsPlist: _exportOptionsPlist),
]);
createMinimalMockProjectFiles();
final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
await createTestCommandRunner(command).run(
<String>['build', 'ipa', '--no-pub']);
expect(
testLogger.statusText,
contains('Warning: App icon is set to the default placeholder icon. Replace with unique icons.'),
);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => fakeProcessManager,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
});
testUsingContext('Validate template app icons without conflicts', () async {
const String projectIconContentsJsonPath = 'ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json';
const String projectIconImagePath = 'ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png';
final String templateIconContentsJsonPath = '${Cache.flutterRoot!}/packages/flutter_tools/templates/app_shared/ios.tmpl/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json';
const String templateIconImagePath = '/flutter_template_images/templates/app_shared/ios.tmpl/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png';
fakeProcessManager.addCommands(<FakeCommand>[
xattrCommand,
setUpFakeXcodeBuildHandler(onRun: () {
fileSystem.file(templateIconContentsJsonPath)
..createSync(recursive: true)
..writeAsStringSync('''
{
"images": [
{
"size": "20x20",
"idiom": "iphone",
"filename": "Icon-App-20x20@2x.png",
"scale": "2x"
}
]
}
''');
fileSystem.file(templateIconImagePath)
..createSync(recursive: true)
..writeAsBytes(<int>[1, 2, 3]);
fileSystem.file(projectIconContentsJsonPath)
..createSync(recursive: true)
..writeAsStringSync('''
{
"images": [
{
"size": "20x20",
"idiom": "iphone",
"filename": "Icon-App-20x20@2x.png",
"scale": "2x"
}
]
}
''');
fileSystem.file(projectIconImagePath)
..createSync(recursive: true)
..writeAsBytes(<int>[4, 5, 6]);
}),
exportArchiveCommand(exportOptionsPlist: _exportOptionsPlist),
]);
createMinimalMockProjectFiles();
final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
await createTestCommandRunner(command).run(
<String>['build', 'ipa', '--no-pub']);
expect(testLogger.statusText, isNot(contains('Warning: App icon is set to the default placeholder icon. Replace with unique icons.')));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => fakeProcessManager,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
});
}
const String _xcBundleFilePath = '/.tmp_rand0/flutter_ios_build_temp_dirrand0/temporary_xcresult_bundle';
const String _exportOptionsPlist = '/.tmp_rand0/flutter_build_ios.rand0/ExportOptions.plist';

View File

@@ -386,10 +386,96 @@ void main() {
final Directory project = globals.fs.directory('ios/Runner.xcodeproj')..createSync(recursive: true);
project.childFile('project.pbxproj').createSync();
final BuildableIOSApp? iosApp = await IOSApp.fromIosProject(
FlutterProject.fromDirectory(globals.fs.currentDirectory).ios, null) as BuildableIOSApp?;
FlutterProject.fromDirectory(globals.fs.currentDirectory).ios, null) as BuildableIOSApp?;
expect(iosApp, null);
}, overrides: overrides);
testUsingContext('returns project app icon dirname', () async {
final BuildableIOSApp iosApp = BuildableIOSApp(
IosProject.fromFlutter(FlutterProject.fromDirectory(globals.fs.currentDirectory)),
'com.foo.bar',
'Runner',
);
final String iconDirSuffix = globals.fs.path.join(
'Runner',
'Assets.xcassets',
'AppIcon.appiconset',
);
expect(iosApp.projectAppIconDirName, globals.fs.path.join('ios', iconDirSuffix));
}, overrides: overrides);
testUsingContext('returns template app icon dirname for Contents.json', () async {
final BuildableIOSApp iosApp = BuildableIOSApp(
IosProject.fromFlutter(FlutterProject.fromDirectory(globals.fs.currentDirectory)),
'com.foo.bar',
'Runner',
);
final String iconDirSuffix = globals.fs.path.join(
'Runner',
'Assets.xcassets',
'AppIcon.appiconset',
);
expect(
iosApp.templateAppIconDirNameForContentsJson,
globals.fs.path.join(
Cache.flutterRoot!,
'packages',
'flutter_tools',
'templates',
'app_shared',
'ios.tmpl',
iconDirSuffix,
),
);
}, overrides: overrides);
testUsingContext('returns template app icon dirname for images', () async {
final String toolsDir = globals.fs.path.join(
Cache.flutterRoot!,
'packages',
'flutter_tools',
);
final String packageConfigPath = globals.fs.path.join(
toolsDir,
'.dart_tool',
'package_config.json'
);
globals.fs.file(packageConfigPath)
..createSync(recursive: true)
..writeAsStringSync('''
{
"configVersion": 2,
"packages": [
{
"name": "flutter_template_images",
"rootUri": "/flutter_template_images",
"packageUri": "lib/",
"languageVersion": "2.12"
}
]
}
''');
final BuildableIOSApp iosApp = BuildableIOSApp(
IosProject.fromFlutter(FlutterProject.fromDirectory(globals.fs.currentDirectory)),
'com.foo.bar',
'Runner');
final String iconDirSuffix = globals.fs.path.join(
'Runner',
'Assets.xcassets',
'AppIcon.appiconset',
);
expect(
await iosApp.templateAppIconDirNameForImages,
globals.fs.path.absolute(
'flutter_template_images',
'templates',
'app_shared',
'ios.tmpl',
iconDirSuffix,
),
);
}, overrides: overrides);
});
group('FuchsiaApp', () {

View File

@@ -9,8 +9,11 @@ import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/template.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/template.dart';
import '../src/common.dart';
import '../src/context.dart';
void main() {
testWithoutContext('Template constructor throws ToolExit when source directory is missing', () {
@@ -43,6 +46,79 @@ void main() {
throwsToolExit());
});
group('template image directory', () {
final Map<Type, Generator> overrides = <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
};
testUsingContext('templateImageDirectory returns parent template directory if passed null name', () async {
final String packageConfigPath = globals.fs.path.join(
Cache.flutterRoot!,
'packages',
'flutter_tools',
'.dart_tool',
'package_config.json',
);
globals.fs.file(packageConfigPath)
..createSync(recursive: true)
..writeAsStringSync('''
{
"configVersion": 2,
"packages": [
{
"name": "flutter_template_images",
"rootUri": "/flutter_template_images",
"packageUri": "lib/",
"languageVersion": "2.12"
}
]
}
''');
expect(
(await templateImageDirectory(null, globals.fs, globals.logger)).path,
globals.fs.path.absolute(
'flutter_template_images',
'templates',
),
);
}, overrides: overrides);
testUsingContext('templateImageDirectory returns the directory containing the `name` template directory', () async {
final String packageConfigPath = globals.fs.path.join(
Cache.flutterRoot!,
'packages',
'flutter_tools',
'.dart_tool',
'package_config.json',
);
globals.fs.file(packageConfigPath)
..createSync(recursive: true)
..writeAsStringSync('''
{
"configVersion": 2,
"packages": [
{
"name": "flutter_template_images",
"rootUri": "/flutter_template_images",
"packageUri": "lib/",
"languageVersion": "2.12"
}
]
}
''');
expect(
(await templateImageDirectory('app_shared', globals.fs, globals.logger)).path,
globals.fs.path.absolute(
'flutter_template_images',
'templates',
'app_shared',
),
);
}, overrides: overrides);
});
group('renders template', () {
late Directory destination;
const String imageName = 'some_image.png';