[ffigen] Cleanup some code around ObjC goldens (#368)

diff --git a/pkgs/ffigen/analysis_options.yaml b/pkgs/ffigen/analysis_options.yaml
index 06af095..5028f95 100644
--- a/pkgs/ffigen/analysis_options.yaml
+++ b/pkgs/ffigen/analysis_options.yaml
@@ -7,6 +7,8 @@
 analyzer:
   exclude:
     - 'test/**_expected*'
+    # Goldens cannot be generated outside MacOS causing analysis errors.
+    - test/native_objc_test/** 
   language:
     strict-casts: true
     strict-inference: true
diff --git a/pkgs/ffigen/test/native_objc_test/setup.dart b/pkgs/ffigen/test/native_objc_test/setup.dart
index c27604d..5b170cc 100644
--- a/pkgs/ffigen/test/native_objc_test/setup.dart
+++ b/pkgs/ffigen/test/native_objc_test/setup.dart
@@ -45,32 +45,55 @@
   print('Generated bindings for: $config');
 }
 
+const testNames = [
+  'block',
+  'cast',
+  'category',
+  'forward_decl',
+  'method',
+  'native_objc',
+  'nullable',
+  'property',
+  'rename',
+  'string',
+];
+
+Future<void> build() async {
+  print('Building Dynamic Library for Objective C Native Tests...');
+  for (final name in testNames) {
+    await _buildLib('${name}_test.m', '${name}_test.dylib');
+  }
+
+  print('Generating Bindings for Objective C Native Tests...');
+  for (final name in testNames) {
+    await _generateBindings('${name}_config.yaml');
+  }
+}
+
+Future<void> clean() async {
+  print('Deleting generated and built files...');
+  final filenames = [
+    for (final name in testNames) ...[
+      '${name}_bindings.dart',
+      '${name}_test_bindings.dart',
+      '${name}_test.dylib'
+    ],
+  ];
+  Future.wait(filenames.map((fileName) async {
+    final file = File(fileName);
+    final exists = await file.exists();
+    if (exists) await file.delete();
+  }));
+}
+
 Future<void> main(List<String> arguments) async {
   if (!Platform.isMacOS) {
     throw OSError('Objective C tests are only supported on MacOS');
   }
 
-  print('Building Dynamic Library for Objective C Native Tests...');
-  await _buildLib('native_objc_test.m', 'native_objc_test.dylib');
-  await _buildLib('cast_test.m', 'cast_test.dylib');
-  await _buildLib('category_test.m', 'category_test.dylib');
-  await _buildLib('method_test.m', 'method_test.dylib');
-  await _buildLib('nullable_test.m', 'nullable_test.dylib');
-  await _buildLib('property_test.m', 'property_test.dylib');
-  await _buildLib('forward_decl_test.m', 'forward_decl_test.dylib');
-  await _buildLib('string_test.m', 'string_test.dylib');
-  await _buildLib('block_test.m', 'block_test.dylib');
-  await _buildLib('rename_test.m', 'rename_test.dylib');
+  if (arguments.isNotEmpty && arguments[0] == 'clean') {
+    return await clean();
+  }
 
-  print('Generating Bindings for Objective C Native Tests...');
-  await _generateBindings('native_objc_config.yaml');
-  await _generateBindings('cast_config.yaml');
-  await _generateBindings('category_config.yaml');
-  await _generateBindings('method_config.yaml');
-  await _generateBindings('nullable_config.yaml');
-  await _generateBindings('property_config.yaml');
-  await _generateBindings('forward_decl_config.yaml');
-  await _generateBindings('string_config.yaml');
-  await _generateBindings('block_config.yaml');
-  await _generateBindings('rename_config.yaml');
+  return await build();
 }