[objective_c] Migrate to workspace (#3780)
diff --git a/.github/workflows/ffigen.yml b/.github/workflows/ffigen.yml index 41d026a..0ddac99 100644 --- a/.github/workflows/ffigen.yml +++ b/.github/workflows/ffigen.yml
@@ -43,7 +43,7 @@ channel: stable - id: install name: Install dependencies - run: dart pub get && dart pub get --directory="example/shared_bindings" && dart pub get --directory="../objective_c" && dart pub get --directory="example/add" && dart pub get --directory="../.." + run: dart pub get && dart pub get --directory="example/shared_bindings" && dart pub get --directory="example/add" && dart pub get --directory="../.." - name: Check formatting run: dart format --output=none --set-exit-if-changed . if: always() && steps.install.outcome == 'success' @@ -98,7 +98,7 @@ with: channel: stable - name: Install dependencies - run: dart pub get && dart pub get --directory="../objective_c" && flutter pub get --directory="../jni" + run: dart pub get && dart pub get --directory="../.." && flutter pub get --directory="../jni" - name: Install Homebrew LLVM if: matrix.clang == 'homebrew' run: brew install llvm @@ -151,7 +151,7 @@ with: channel: stable - name: Install dependencies - run: dart pub get && dart pub get --directory="../objective_c" && flutter pub get --directory="../jni" + run: dart pub get && dart pub get --directory="../.." && flutter pub get --directory="../jni" - name: Install clang-format uses: ConorMacBride/install-package@3e7ad059e07782ee54fa35f827df52aae0626f30 with: @@ -175,7 +175,7 @@ with: channel: stable - name: Install dependencies - run: dart pub get && dart pub get --directory="../objective_c" + run: dart pub get && dart pub get --directory="../.." - name: Run Flutter tests run: dart test
diff --git a/.github/workflows/native.yaml b/.github/workflows/native.yaml index f7064dd..e00618a 100644 --- a/.github/workflows/native.yaml +++ b/.github/workflows/native.yaml
@@ -22,6 +22,7 @@ - 'pkgs/json_syntax_generator/**' - 'pkgs/native_test_helpers/**' - 'pkgs/native_toolchain_c/**' + - 'pkgs/objective_c/**' - 'pkgs/pub_formats/**' - 'pkgs/record_use/**' - 'pkgs/snippet_tool/**' @@ -44,6 +45,7 @@ - 'pkgs/json_syntax_generator/**' - 'pkgs/native_test_helpers/**' - 'pkgs/native_toolchain_c/**' + - 'pkgs/objective_c/**' - 'pkgs/pub_formats/**' - 'pkgs/record_use/**' - 'pkgs/snippet_tool/**'
diff --git a/.github/workflows/objective_c.yaml b/.github/workflows/objective_c.yaml index fd5393b..8ad0fe6 100644 --- a/.github/workflows/objective_c.yaml +++ b/.github/workflows/objective_c.yaml
@@ -9,7 +9,6 @@ - 'pkgs/ffigen/**' - 'pkgs/native_test_helpers/**' - 'pkgs/objective_c/**' - - 'pkgs/snippet_tool/**' pull_request: branches: [main] paths: @@ -17,7 +16,6 @@ - 'pkgs/ffigen/**' - 'pkgs/native_test_helpers/**' - 'pkgs/objective_c/**' - - 'pkgs/snippet_tool/**' schedule: - cron: "0 0 * * 0" @@ -25,71 +23,7 @@ PUB_ENVIRONMENT: bot.github jobs: - # Check code formatting and static analysis. - analyze: - runs-on: macos-latest - permissions: - contents: read - defaults: - run: - working-directory: pkgs/objective_c/ - strategy: - fail-fast: false - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 - with: - persist-credentials: false - - uses: subosito/flutter-action@1a449444c387b1966244ae4d4f8c696479add0b2 - with: - channel: stable - - id: install - name: Install dependencies - run: flutter pub get && flutter pub get --directory="example/command_line" && flutter pub get --directory="example/flutter_app" && flutter pub get --directory="example/path_provider_example" && dart pub get --directory="../.." - - name: Check formatting - run: dart format --output=none --set-exit-if-changed . - if: always() && steps.install.outcome == 'success' - - name: Analyze code - run: flutter analyze --fatal-infos - if: always() && steps.install.outcome == 'success' - - name: Check snippets - run: dart run ../snippet_tool/bin/snippet_tool.dart --set-exit-if-changed . - - test-mac: - needs: analyze - runs-on: 'macos-latest' - permissions: - contents: read - defaults: - run: - working-directory: pkgs/objective_c/ - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 - with: - persist-credentials: false - - uses: dart-lang/setup-dart@2286a0c042b44434fe26d292bbce8d34f7ec662b - with: - sdk: stable - - name: Install dependencies - run: dart pub get - - name: Install coverage - run: dart pub global activate coverage - - name: Run VM tests and collect coverage - run: dart pub global run coverage:test_with_coverage --scope-output=ffigen --scope-output=objective_c - - name: Verify generated code is up to date - # test/generate_code_test.dart runs the code generator, so if there are - # any git-diffs at this point, it means the generated code is outdated. - run: if [[ -n $(git status --porcelain | tee /dev/stderr) ]]; then echo -e "\nDIFF:"; git diff; false; fi - - name: Upload coverage - uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 - with: - files: pkgs/objective_c/coverage/lcov.info - flags: objective_c - token: ${{ secrets.CODECOV_TOKEN }} - fail_ci_if_error: false - - test-flutter: - needs: analyze runs-on: ${{ matrix.runner }} permissions: contents: read @@ -113,7 +47,9 @@ with: channel: stable - name: Install dependencies - run: flutter pub get + run: flutter pub get && flutter pub get --directory="../path_provider_example" + - name: Analyze Flutter examples + run: flutter analyze --fatal-infos && flutter analyze --fatal-infos ../path_provider_example - name: Build the example app for macos run: flutter build macos - name: Build the example app for ios @@ -124,23 +60,3 @@ flutter test integration_test/objective_c_test.dart -d "$UDID" - name: Check for xcode for analyzer warnings run: xcodebuild analyze -workspace macos/Runner.xcworkspace -scheme Runner -configuration Debug GCC_TREAT_WARNINGS_AS_ERRORS=YES - - build-command-line-example: - needs: analyze - runs-on: 'macos-latest' - permissions: - contents: read - defaults: - run: - working-directory: pkgs/objective_c/example/command_line - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 - with: - persist-credentials: false - - uses: dart-lang/setup-dart@2286a0c042b44434fe26d292bbce8d34f7ec662b - with: - sdk: stable - - name: Install dependencies - run: dart pub get - - name: Run the example app - run: dart run lib/main.dart
diff --git a/pkgs/objective_c/example/command_line/lib/main.dart b/pkgs/objective_c/example/command_line/lib/main.dart index 6bf9da6..afc5bee 100644 --- a/pkgs/objective_c/example/command_line/lib/main.dart +++ b/pkgs/objective_c/example/command_line/lib/main.dart
@@ -1,3 +1,7 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + import 'dart:io'; import 'package:objective_c/objective_c.dart';
diff --git a/pkgs/objective_c/example/command_line/pubspec.yaml b/pkgs/objective_c/example/command_line/pubspec.yaml index 1890859..c1844c1 100644 --- a/pkgs/objective_c/example/command_line/pubspec.yaml +++ b/pkgs/objective_c/example/command_line/pubspec.yaml
@@ -4,7 +4,9 @@ publish_to: none environment: - sdk: '>=3.9.0-21.0.dev <4.0.0' + sdk: '>=3.10.0 <4.0.0' + +resolution: workspace dependencies: objective_c: @@ -13,13 +15,3 @@ dev_dependencies: lints: ^6.0.0 test: ^1.27.0 - -dependency_overrides: - code_assets: - path: ../../../code_assets - hooks: - path: ../../../hooks - native_toolchain_c: - path: ../../../native_toolchain_c - record_use: - path: ../../../record_use
diff --git a/pkgs/objective_c/example/path_provider_example/lib/main.dart b/pkgs/objective_c/example/path_provider_example/lib/main.dart index 158e808..a54a49d 100644 --- a/pkgs/objective_c/example/path_provider_example/lib/main.dart +++ b/pkgs/objective_c/example/path_provider_example/lib/main.dart
@@ -1,3 +1,7 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + import 'package:material_ui/material_ui.dart'; import 'package:path_provider/path_provider.dart';
diff --git a/pkgs/objective_c/pubspec.yaml b/pkgs/objective_c/pubspec.yaml index c917d75..a48fcc0 100644 --- a/pkgs/objective_c/pubspec.yaml +++ b/pkgs/objective_c/pubspec.yaml
@@ -16,6 +16,8 @@ environment: sdk: '>=3.10.0 <4.0.0' +resolution: workspace + dependencies: code_assets: ^2.2.0 collection: ^1.19.1 @@ -34,21 +36,3 @@ path: ../native_test_helpers/ path: ^1.9.0 test: ^1.26.2 - yaml: ^3.1.0 - -dependency_overrides: - code_assets: - path: ../code_assets - ffigen: - path: ../ffigen - hooks: - path: ../hooks - native_toolchain_c: - path: ../native_toolchain_c - record_use: - path: ../record_use - -hooks: - user_defines: - objective_c: - include_test_utils: true
diff --git a/pkgs/objective_c/test/generate_code_test.dart b/pkgs/objective_c/test/generate_code_test.dart index 8419a5b..c04b6c2 100644 --- a/pkgs/objective_c/test/generate_code_test.dart +++ b/pkgs/objective_c/test/generate_code_test.dart
@@ -8,22 +8,35 @@ import 'dart:io'; +import 'package:path/path.dart' as p; import 'package:test/test.dart'; import '../tool/ffigen.dart' as ffigen_tool; +import 'util.dart'; void main() { group('ffigen.dart', () { test('Runs without exception', () async { // As well as testing that this returns normally, this also generates // coverage info for the parts of FFIgen that are gated by - // generate-for-package-objective-c. The github workflow that runs this - // test also uses it to verify that there are no git-diffs in the output. - await expectLater(ffigen_tool.run(format: true), completes); + // generate-for-package-objective-c. + final changedFiles = await ffigen_tool.run( + format: true, + packageRoot: Directory(pkgDir).uri, + runTests: false, + restoreIfChanged: true, + ); + expect( + changedFiles, + isEmpty, + reason: + 'Generated files are out of date. ' + 'Run `dart pkgs/objective_c/tool/ffigen.dart` to regenerate.', + ); // Sanity check the generated code. final rBindings = File( - 'lib/src/runtime_bindings_generated.dart', + p.join(pkgDir, 'lib', 'src', 'runtime_bindings_generated.dart'), ).readAsStringSync(); expect(rBindings, contains('sel_registerName')); expect(rBindings, contains('objc_msgSend')); @@ -31,7 +44,7 @@ expect(rBindings, contains('ObjCObject')); final cBindings = File( - 'lib/src/c_bindings_generated.dart', + p.join(pkgDir, 'lib', 'src', 'c_bindings_generated.dart'), ).readAsStringSync(); expect(cBindings, contains('createContext')); expect(cBindings, contains('DOBJC_Context')); @@ -40,7 +53,7 @@ expect(cBindings, contains('ObjCBlockImpl')); final objcBindings = File( - 'lib/src/objective_c_bindings_generated.dart', + p.join(pkgDir, 'lib', 'src', 'objective_c_bindings_generated.dart'), ).readAsStringSync(); expect(objcBindings, contains('class NSObject')); expect(objcBindings, contains('class NSString'));
diff --git a/pkgs/objective_c/test/version_check_test.dart b/pkgs/objective_c/test/version_check_test.dart index 22d22c3..e54612b 100644 --- a/pkgs/objective_c/test/version_check_test.dart +++ b/pkgs/objective_c/test/version_check_test.dart
@@ -5,11 +5,14 @@ import 'dart:io'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as p; import 'package:test/test.dart'; +import 'util.dart'; + void main() { test('ObjCVersionCheck constants match pubspec', () { - final pubspecFile = File('pubspec.yaml'); + final pubspecFile = File(p.join(pkgDir, 'pubspec.yaml')); final pubspecContent = pubspecFile.readAsStringSync(); final versionRegex = RegExp( r'^version:\s+(\d+)\.(\d+)\.\d+',
diff --git a/pkgs/objective_c/tool/ffigen.dart b/pkgs/objective_c/tool/ffigen.dart index 433a888..2c22446 100644 --- a/pkgs/objective_c/tool/ffigen.dart +++ b/pkgs/objective_c/tool/ffigen.dart
@@ -15,6 +15,10 @@ const runtimeBindings = 'lib/src/runtime_bindings_generated.dart'; const cBindings = 'lib/src/c_bindings_generated.dart'; const objcBindings = 'lib/src/objective_c_bindings_generated.dart'; +const objcMBindings = 'src/objective_c_bindings_generated.m'; +const objcExports = 'lib/src/objective_c_bindings_exported.dart'; +const builtInTypes = + '../ffigen/lib/src/code_generator/objc_built_in_types.dart'; const objcInterfaces = { 'DOBJCDartInputStreamAdapter': 'DartInputStreamAdapter', @@ -175,18 +179,42 @@ }; Future<void> main(List<String> args) async { - final argResults = - (ArgParser()..addFlag( - 'format', - help: 'Format the generated code.', - defaultsTo: true, - negatable: true, - )) - .parse(args); - await run(format: argResults.flag('format')); + final parser = ArgParser() + ..addFlag( + 'format', + help: 'Format the generated code.', + defaultsTo: true, + negatable: true, + ) + ..addFlag( + 'set-exit-if-changed', + negatable: false, + help: 'Return a non-zero exit code if any files were changed.', + ) + ..addFlag( + 'test', + help: 'Run interface_lists_test.dart after generating.', + defaultsTo: false, + negatable: true, + ); + final argResults = parser.parse(args); + final setExitIfChanged = argResults.flag('set-exit-if-changed'); + final changedFiles = await run( + format: argResults.flag('format'), + runTests: argResults.flag('test') && !setExitIfChanged, + restoreIfChanged: setExitIfChanged, + ); + if (setExitIfChanged && changedFiles.isNotEmpty) { + exit(1); + } } -Future<void> run({required bool format, Uri? packageRoot}) async { +Future<List<String>> run({ + required bool format, + required bool runTests, + bool restoreIfChanged = false, + Uri? packageRoot, +}) async { packageRoot ??= _defaultPackageRoot(); final logger = Logger.root; logger.level = Level.SEVERE; @@ -194,52 +222,113 @@ final runtimeBindingsPath = packageRoot.resolve(runtimeBindings).toFilePath(); final cBindingsPath = packageRoot.resolve(cBindings).toFilePath(); final objcBindingsPath = packageRoot.resolve(objcBindings).toFilePath(); - final objcExportsPath = packageRoot - .resolve('lib/src/objective_c_bindings_exported.dart') - .toFilePath(); + final objcMBindingsPath = packageRoot.resolve(objcMBindings).toFilePath(); + final objcExportsPath = packageRoot.resolve(objcExports).toFilePath(); final extraMethodsFilePath = packageRoot .resolve('tool/data/extra_methods.dart.in') .toFilePath(); - final builtInTypesPath = packageRoot - .resolve('../ffigen/lib/src/code_generator/objc_built_in_types.dart') - .toFilePath(); + final builtInTypesPath = packageRoot.resolve(builtInTypes).toFilePath(); final interfaceListTestPath = packageRoot .resolve('test/interface_lists_test.dart') .toFilePath(); - print('Generating runtime bindings...'); - await getRuntimeConfig(packageRoot).generate(logger: logger); + final outputPaths = [ + runtimeBindingsPath, + cBindingsPath, + objcBindingsPath, + objcMBindingsPath, + builtInTypesPath, + objcExportsPath, + ]; + final snapshots = { + for (final path in outputPaths) + path: File(path).existsSync() ? File(path).readAsStringSync() : null, + }; - print('Generating C bindings...'); - await getCConfig(packageRoot).generate(logger: logger); + final libclangDylib = _findXcodeLibclangDylib(); + final changedFiles = <String>[]; + try { + print('Generating runtime bindings...'); + await getRuntimeConfig( + packageRoot, + ).generate(logger: logger, libclangDylib: libclangDylib); - print('Generating ObjC bindings...'); - await getObjCConfig(packageRoot).generate(logger: logger); - mergeExtraMethods(objcBindingsPath, parseExtraMethods(extraMethodsFilePath)); + print('Generating C bindings...'); + await getCConfig( + packageRoot, + ).generate(logger: logger, libclangDylib: libclangDylib); - print('Generating objc_built_in_types.dart...'); - final exports = writeBuiltInTypes(builtInTypesPath); - - print('Generating objc_bindings_exported.dart...'); - writeExports(exports, objcExportsPath); - - if (format) { - print('Formatting bindings...'); - dartCmd([ - 'format', - runtimeBindingsPath, - cBindingsPath, + print('Generating ObjC bindings...'); + await getObjCConfig( + packageRoot, + ).generate(logger: logger, libclangDylib: libclangDylib); + mergeExtraMethods( objcBindingsPath, - builtInTypesPath, - objcExportsPath, + parseExtraMethods(extraMethodsFilePath), + ); + + print('Generating objc_built_in_types.dart...'); + final exports = writeBuiltInTypes(builtInTypesPath); + + print('Generating objc_bindings_exported.dart...'); + writeExports(exports, objcExportsPath); + + if (format) { + print('Formatting bindings...'); + dartCmd([ + 'format', + runtimeBindingsPath, + cBindingsPath, + objcBindingsPath, + builtInTypesPath, + objcExportsPath, + ], workingDir: packageRoot.toFilePath()); + } + + for (final path in outputPaths) { + final oldNormalized = snapshots[path]?.replaceAll('\r\n', '\n'); + final newContent = File(path).existsSync() + ? File(path).readAsStringSync() + : null; + final newNormalized = newContent?.replaceAll('\r\n', '\n'); + if (oldNormalized != newNormalized) { + print('Generated $path (content changed)'); + changedFiles.add(path); + } + } + if (restoreIfChanged && changedFiles.isNotEmpty) { + _printGitDiff(changedFiles, workingDir: packageRoot.toFilePath()); + } + } finally { + if (restoreIfChanged) { + for (final entry in snapshots.entries) { + final file = File(entry.key); + final oldContent = entry.value; + if (oldContent == null) { + if (file.existsSync()) { + file.deleteSync(); + } + } else if (!file.existsSync() || + file.readAsStringSync() != oldContent) { + file.writeAsStringSync(oldContent); + } + } + } + } + + print( + 'Generated ${outputPaths.length} files (${changedFiles.length} changed).', + ); + + if (runTests) { + print('Running tests...'); + dartCmd([ + 'test', + interfaceListTestPath, ], workingDir: packageRoot.toFilePath()); } - print('Running tests...'); - dartCmd([ - 'test', - interfaceListTestPath, - ], workingDir: packageRoot.toFilePath()); + return changedFiles; } List<String> writeBuiltInTypes(String out) { @@ -465,9 +554,7 @@ return FfiGenerator( output: Output( dart: DartOutput(path: packageRoot.resolve(objcBindings)), - objectiveCFile: packageRoot.resolve( - 'src/objective_c_bindings_generated.m', - ), + objectiveCFile: packageRoot.resolve(objcMBindings), style: const NativeExternalBindings(assetId: assetId), format: false, preamble: ''' @@ -565,6 +652,21 @@ return Directory.current.uri; } +Uri? _findXcodeLibclangDylib() { + if (!Platform.isMacOS) return null; + final result = Process.runSync('xcodebuild', [ + '-find-library', + 'libclang.dylib', + ]); + if (result.exitCode == 0) { + final path = (result.stdout as String).split('\n').first.trim(); + if (path.isNotEmpty && File(path).existsSync()) { + return Uri.file(path); + } + } + return null; +} + void dartCmd(List<String> args, {String? workingDir}) { final exec = Platform.resolvedExecutable; final proc = Process.runSync( @@ -581,6 +683,26 @@ } } +void _printGitDiff(List<String> files, {required String workingDir}) { + try { + final proc = Process.runSync('git', [ + 'diff', + '--', + ...files, + ], workingDirectory: workingDir); + final stdout = (proc.stdout as String).trimRight(); + final stderr = (proc.stderr as String).trimRight(); + if (stdout.isNotEmpty) { + print(stdout); + } + if (stderr.isNotEmpty) { + print(stderr); + } + } on ProcessException catch (e) { + print('Failed to run git diff: $e'); + } +} + final _clsDecl = RegExp(r'^extension type (\w+)\W'); String? parseClassDecl(String line) => _clsDecl.firstMatch(line)?[1];
diff --git a/pubspec.yaml b/pubspec.yaml index 12d4eea..2bee771 100644 --- a/pubspec.yaml +++ b/pubspec.yaml
@@ -120,8 +120,8 @@ - pkgs/json_syntax_generator - pkgs/native_test_helpers - pkgs/native_toolchain_c - # - pkgs/objective_c # TODO - # - pkgs/objective_c/example/command_line # TODO + - pkgs/objective_c + - pkgs/objective_c/example/command_line # - pkgs/objective_c/example/flutter_app # Requires Flutter. # - pkgs/objective_c/example/path_provider_example # Requires Flutter. - pkgs/pub_formats @@ -148,6 +148,8 @@ # Hook user-defines are specified in the pub workspace. hooks: user_defines: + objective_c: + include_test_utils: true prebuilt_assets_example: local_build: false download_asset:
diff --git a/tool/ci.dart b/tool/ci.dart index f9967f0..e9a1b13 100644 --- a/tool/ci.dart +++ b/tool/ci.dart
@@ -284,7 +284,10 @@ /// https://github.com/dart-lang/native/issues/90#issuecomment-3879193057 const slowTestPackages = [ 'pkgs/hooks_runner', + 'pkgs/jni_util', 'pkgs/native_toolchain_c', + 'pkgs/objective_c', + 'pkgs/swift2objc', ]; /// Runs `dart analyze` to find static analysis issues. @@ -347,7 +350,7 @@ required List<String> packages, required ArgResults argResults, }) async { - const generators = [ + final generators = [ 'pkgs/code_assets/example/host_name/tool/ffigen.dart', 'pkgs/code_assets/example/mini_audio/tool/ffigen.dart', 'pkgs/code_assets/example/sqlite/tool/ffigen.dart', @@ -358,6 +361,7 @@ 'pkgs/hooks/tool/generate_schemas.dart', 'pkgs/hooks/tool/generate_syntax.dart', 'pkgs/hooks/tool/normalize.dart', + if (Platform.isMacOS) 'pkgs/objective_c/tool/ffigen.dart', 'pkgs/pub_formats/tool/generate.dart', 'pkgs/record_use/tool/generate_syntax.dart', ]; @@ -369,6 +373,7 @@ 'pkgs/web_assets', 'pkgs/record_use', 'pkgs/swift2objc', + 'pkgs/objective_c', ]; final fix = argResults['fix'] as bool; await _runMaybeParallel([ @@ -412,19 +417,62 @@ .where((p) => !slowTestPackages.any((slow) => p.contains(slow))) .toList(); } - final testUris = getUriInPackage(packages, 'test'); - if (coverageTask.shouldRun(argResults)) { + // Run packages with build hooks separately from their own package + // directory, because running `dart test` from the workspace root does not + // run build hooks for workspace packages. + // TODO(https://github.com/dart-lang/sdk/issues/63713): Remove this + // workaround once `dart test` runs build hooks from the workspace root. + final packagesWithHook = [ + for (final package in packages) + if (File.fromUri( + repositoryRoot.resolve('$package/hook/build.dart'), + ).existsSync()) + package, + ]; + final packagesWithoutHook = [ + for (final package in packages) + if (!packagesWithHook.contains(package)) package, + ]; + final testUris = getUriInPackage(packagesWithoutHook, 'test'); + final collectCoverage = coverageTask.shouldRun(argResults); + if (collectCoverage) { final coverageDir = Directory.fromUri(repositoryRoot.resolve('coverage')); if (coverageDir.existsSync()) { coverageDir.deleteSync(recursive: true); } } - await _runProcess('dart', [ - 'test', - if (coverageTask.shouldRun(argResults)) '--coverage=./coverage', + final reporterArgs = [ if (Platform.environment['GITHUB_ACTIONS'] != null) '--reporter=github', - ...testUris, - ]); + ]; + + if (testUris.isNotEmpty) { + await _runProcess('dart', [ + 'test', + if (collectCoverage) '--coverage=./coverage', + ...reporterArgs, + ...testUris, + ]); + } + + for (final package in packagesWithHook) { + if (!Directory.fromUri( + repositoryRoot.resolve('$package/test/'), + ).existsSync()) { + continue; + } + final coveragePath = repositoryRoot + .resolve('coverage/$package') + .toFilePath(); + await _runProcess( + workingDirectory: repositoryRoot.resolve('$package/'), + 'dart', + [ + 'test', + if (collectCoverage) '--coverage=$coveragePath', + ...reporterArgs, + ], + ); + } } } @@ -492,6 +540,16 @@ .toFilePath(), [], ); + + if (Platform.isMacOS) { + await _runProcess( + workingDirectory: repositoryRoot.resolve( + 'pkgs/objective_c/example/command_line/', + ), + 'dart', + ['run', 'lib/main.dart'], + ); + } } }