diff --git a/packages/flutter_tools/bin/macos_assemble.sh b/packages/flutter_tools/bin/macos_assemble.sh index 40c6a5051f..a7f05d9113 100755 --- a/packages/flutter_tools/bin/macos_assemble.sh +++ b/packages/flutter_tools/bin/macos_assemble.sh @@ -222,6 +222,7 @@ EmbedFrameworks() { # Iterate through all .frameworks in native assets directory. for native_asset in "${native_assets_path}"*.framework; do + [ -e "$native_asset" ] || continue # Skip when there are no matches. # Codesign the framework inside the app bundle. RunCommand codesign --force --verbose --sign "${EXPANDED_CODE_SIGN_IDENTITY}" -- "${xcode_frameworks_dir}/$(basename "$native_asset")" done diff --git a/packages/flutter_tools/test/integration.shard/isolated/native_assets_test.dart b/packages/flutter_tools/test/integration.shard/isolated/native_assets_test.dart index ae6456cb55..e8cb1050b6 100644 --- a/packages/flutter_tools/test/integration.shard/isolated/native_assets_test.dart +++ b/packages/flutter_tools/test/integration.shard/isolated/native_assets_test.dart @@ -222,6 +222,26 @@ void main() { }); } + testWithoutContext('flutter build $buildSubcommand succeeds without libraries', () async { + await inTempDir((Directory tempDirectory) async { + final Directory projectDirectory = await createTestProjectWithNoCBuild(packageName, tempDirectory); + + final ProcessResult result = processManager.runSync( + [ + flutterBin, + 'build', + buildSubcommand, + '--debug', + if (buildSubcommand == 'ios') '--no-codesign', + ], + workingDirectory: projectDirectory.path, + ); + if (result.exitCode != 0) { + throw Exception('flutter build failed: ${result.exitCode}\n${result.stderr}\n${result.stdout}'); + } + }); + }); + // This could be an hermetic unit test if the native_assets_builder // could mock process runs and file system. // https://github.com/dart-lang/native/issues/90. @@ -565,6 +585,61 @@ Future createTestProject(String packageName, Directory tempDirectory) return packageDirectory; } +Future createTestProjectWithNoCBuild(String packageName, Directory tempDirectory) async { + final ProcessResult result = processManager.runSync( + [ + flutterBin, + 'create', + '--no-pub', + packageName, + ], + workingDirectory: tempDirectory.path, + ); + if (result.exitCode != 0) { + throw Exception( + 'flutter create failed: ${result.exitCode}\n${result.stderr}\n${result.stdout}', + ); + } + + final Directory packageDirectory = tempDirectory.childDirectory(packageName); + + final ProcessResult result2 = await processManager.run( + [ + flutterBin, + 'pub', + 'add', + 'native_assets_cli', + ], + workingDirectory: packageDirectory.path, + ); + expect(result2, const ProcessResultMatcher()); + + await pinDependencies(packageDirectory.childFile('pubspec.yaml')); + + final ProcessResult result3 = await processManager.run( + [ + flutterBin, + 'pub', + 'get', + ], + workingDirectory: packageDirectory.path, + ); + expect(result3, const ProcessResultMatcher()); + + // Add build hook that does nothing to the package. + final File buildHook = packageDirectory.childDirectory('hook').childFile('build.dart'); + buildHook.createSync(recursive: true); + buildHook.writeAsStringSync(''' +import 'package:native_assets_cli/native_assets_cli.dart'; + +void main(List args) async { + await build(args, (config, output) async {}); +} +'''); + + return packageDirectory; +} + Future addLinkHookDepedendency(Directory packageDirectory) async { final Directory flutterDirectory = fileSystem.currentDirectory.parent.parent; final Directory linkHookDirectory = flutterDirectory