From d155a7b4130e2edf6f025495a07199d46a8e00e2 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Mon, 26 May 2025 11:57:31 +1000 Subject: [PATCH 01/15] Update coverage --- .github/workflows/ffigen.yml | 4 +++- .github/workflows/objective_c.yaml | 4 +++- .github/workflows/swift2objc.yaml | 4 +++- pkgs/ffigen/pubspec.yaml | 1 - pkgs/objective_c/pubspec.yaml | 1 - 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ffigen.yml b/.github/workflows/ffigen.yml index 1a454202eb..930d2ea7f3 100644 --- a/.github/workflows/ffigen.yml +++ b/.github/workflows/ffigen.yml @@ -89,8 +89,10 @@ jobs: brew: clang-format - name: Build test dylib and bindings run: dart test/setup.dart + - name: Install coverage + run: dart pub global activate coverage - name: Run VM tests and collect coverage - run: dart run coverage:test_with_coverage --scope-output=ffigen --scope-output=objective_c + run: dart pub global run coverage:test_with_coverage --scope-output=ffigen --scope-output=objective_c - name: Generate package:jni bindings run: dart run tool/generate_ffi_bindings.dart working-directory: pkgs/jni/ diff --git a/.github/workflows/objective_c.yaml b/.github/workflows/objective_c.yaml index 303dff6c32..834fcc5286 100644 --- a/.github/workflows/objective_c.yaml +++ b/.github/workflows/objective_c.yaml @@ -60,8 +60,10 @@ jobs: - name: Build test dylib # TODO(https://github.com/dart-lang/native/issues/1068): Remove this. run: dart test/setup.dart + - name: Install coverage + run: dart pub global activate coverage - name: Run VM tests and collect coverage - run: dart run coverage:test_with_coverage --scope-output=ffigen --scope-output=objective_c + 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. diff --git a/.github/workflows/swift2objc.yaml b/.github/workflows/swift2objc.yaml index 7e16e35966..bf73ebae08 100644 --- a/.github/workflows/swift2objc.yaml +++ b/.github/workflows/swift2objc.yaml @@ -55,8 +55,10 @@ jobs: 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 run coverage:test_with_coverage --scope-output=swift2objc + run: dart pub global run coverage:test_with_coverage --scope-output=swift2objc - name: Upload coverage uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b with: diff --git a/pkgs/ffigen/pubspec.yaml b/pkgs/ffigen/pubspec.yaml index e30ccf7e79..6c99ba8d17 100644 --- a/pkgs/ffigen/pubspec.yaml +++ b/pkgs/ffigen/pubspec.yaml @@ -37,7 +37,6 @@ dependencies: dev_dependencies: async: ^2.11.0 - coverage: ^1.11.0 dart_flutter_team_lints: ^2.0.0 json_schema: ^5.1.1 leak_tracker: ^10.0.7 diff --git a/pkgs/objective_c/pubspec.yaml b/pkgs/objective_c/pubspec.yaml index 169e8c0144..af7a750c31 100644 --- a/pkgs/objective_c/pubspec.yaml +++ b/pkgs/objective_c/pubspec.yaml @@ -26,7 +26,6 @@ dependencies: dev_dependencies: args: ^2.6.0 - coverage: ^1.11.0 dart_flutter_team_lints: ^2.0.0 ffigen: ^18.2.0 flutter_lints: ^3.0.0 From 35cc149fca94e00c9f49fb428c78a6c0dd332d94 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Mon, 26 May 2025 14:56:28 +1000 Subject: [PATCH 02/15] Fix pubspec --- pkgs/objective_c/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/objective_c/pubspec.yaml b/pkgs/objective_c/pubspec.yaml index af7a750c31..965c346c9a 100644 --- a/pkgs/objective_c/pubspec.yaml +++ b/pkgs/objective_c/pubspec.yaml @@ -27,7 +27,7 @@ dependencies: dev_dependencies: args: ^2.6.0 dart_flutter_team_lints: ^2.0.0 - ffigen: ^18.2.0 + ffigen: ^19.0.0 flutter_lints: ^3.0.0 flutter_test: sdk: flutter From 96f1a0f0c82ea0add36a50a1f23a317988a6e8cd Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Mon, 26 May 2025 14:57:04 +1000 Subject: [PATCH 03/15] Fix pubspec --- pkgs/ffigen/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/ffigen/pubspec.yaml b/pkgs/ffigen/pubspec.yaml index 6c99ba8d17..0501a72984 100644 --- a/pkgs/ffigen/pubspec.yaml +++ b/pkgs/ffigen/pubspec.yaml @@ -40,7 +40,7 @@ dev_dependencies: dart_flutter_team_lints: ^2.0.0 json_schema: ^5.1.1 leak_tracker: ^10.0.7 - objective_c: ^7.2.0 + objective_c: ^8.0.0 test: ^1.16.2 dependency_overrides: From 10b42fb4ca010de928ff9a9f8374b17f2be78336 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Mon, 26 May 2025 13:53:50 +1000 Subject: [PATCH 04/15] migrate --- pkgs/objective_c/pubspec.yaml | 2 +- pkgs/swift2objc/pubspec.yaml | 5 +++-- .../test/integration/integration_test.dart | 4 +++- pkgs/swift2objc/test/unit/filter_test.dart | 4 ++-- pkgs/swift2objc/test/utils.dart | 22 +++++++++++++++++++ pkgs/swift2objc/test/utils/utils.dart | 8 ------- pubspec.yaml | 1 + 7 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 pkgs/swift2objc/test/utils.dart delete mode 100644 pkgs/swift2objc/test/utils/utils.dart diff --git a/pkgs/objective_c/pubspec.yaml b/pkgs/objective_c/pubspec.yaml index 169e8c0144..7ec7ae8256 100644 --- a/pkgs/objective_c/pubspec.yaml +++ b/pkgs/objective_c/pubspec.yaml @@ -28,7 +28,7 @@ dev_dependencies: args: ^2.6.0 coverage: ^1.11.0 dart_flutter_team_lints: ^2.0.0 - ffigen: ^18.2.0 + ffigen: ^19.0.0 flutter_lints: ^3.0.0 flutter_test: sdk: flutter diff --git a/pkgs/swift2objc/pubspec.yaml b/pkgs/swift2objc/pubspec.yaml index 32bd20a245..34061ec06e 100644 --- a/pkgs/swift2objc/pubspec.yaml +++ b/pkgs/swift2objc/pubspec.yaml @@ -7,6 +7,7 @@ description: 'A tool for generating bindings that allow interop between Dart and version: 0.0.1-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/swiftgen/swift2objc issue_tracker: https://github.com/dart-lang/native/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aswift2objc +resolution: workspace topics: - interop @@ -21,9 +22,9 @@ dependencies: path: ^1.9.0 environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.6.0 <4.0.0' dev_dependencies: args: ^2.6.0 - dart_flutter_team_lints: ^2.0.0 + dart_flutter_team_lints: ^3.5.1 test: ^1.21.1 diff --git a/pkgs/swift2objc/test/integration/integration_test.dart b/pkgs/swift2objc/test/integration/integration_test.dart index b32e01ad6d..7db86918d8 100644 --- a/pkgs/swift2objc/test/integration/integration_test.dart +++ b/pkgs/swift2objc/test/integration/integration_test.dart @@ -20,11 +20,13 @@ import 'package:path/path.dart' as path; import 'package:swift2objc/swift2objc.dart'; import 'package:test/test.dart'; +import '../utils.dart'; + void main([List? args]) { const inputSuffix = '_input.swift'; const outputSuffix = '_output.swift'; - final thisDir = path.join(Directory.current.path, 'test/integration'); + final thisDir = path.join(testDir, 'integration'); final tempDir = path.join(thisDir, 'temp'); var regen = false; diff --git a/pkgs/swift2objc/test/unit/filter_test.dart b/pkgs/swift2objc/test/unit/filter_test.dart index 3b7828c147..6b47994b46 100644 --- a/pkgs/swift2objc/test/unit/filter_test.dart +++ b/pkgs/swift2objc/test/unit/filter_test.dart @@ -9,11 +9,11 @@ import 'package:swift2objc/src/ast/declarations/compounds/class_declaration.dart import 'package:swift2objc/swift2objc.dart'; import 'package:test/test.dart'; -import '../utils/utils.dart'; +import '../utils.dart'; void main() { group('Unit test for filter', () { - final thisDir = p.join(Directory.current.path, 'test/unit'); + final thisDir = p.join(testDir, 'unit'); final file = p.join(thisDir, 'filter_test_input.swift'); test('A: Specific Files', () async { diff --git a/pkgs/swift2objc/test/utils.dart b/pkgs/swift2objc/test/utils.dart new file mode 100644 index 0000000000..f195242e1c --- /dev/null +++ b/pkgs/swift2objc/test/utils.dart @@ -0,0 +1,22 @@ +import 'dart:isolate'; +import 'dart:io'; + +import 'package:path/path.dart' as p; +import 'package:test/test.dart'; + +final _whitespace = RegExp(r'\s+'); + +void expectString(String a, String b) { + final trimmedA = a.replaceAll(_whitespace, ''); + final trimmedB = b.replaceAll(_whitespace, ''); + + expect(trimmedA, trimmedB); +} + +String testDir = p.normalize(p.join( + Isolate.resolvePackageUriSync( + Uri.parse('package:swift2objc/swift2objc.dart'))! + .toFilePath(), + '..', + '..', + 'test')); diff --git a/pkgs/swift2objc/test/utils/utils.dart b/pkgs/swift2objc/test/utils/utils.dart deleted file mode 100644 index 27ea25ad4f..0000000000 --- a/pkgs/swift2objc/test/utils/utils.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'package:test/test.dart'; - -void expectString(String a, String b) { - final trimmedA = a.replaceAll(RegExp(r'\s+'), ''); - final trimmedB = b.replaceAll(RegExp(r'\s+'), ''); - - expect(trimmedA, trimmedB); -} diff --git a/pubspec.yaml b/pubspec.yaml index d2e324ea35..7bd60f2601 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,6 +57,7 @@ workspace: - pkgs/hooks/example/link/package_with_assets - pkgs/json_syntax_generator - pkgs/native_toolchain_c + - pkgs/swift2objc - pkgs/repo_lint_rules # Hook user-defines are specified in the pub workspace. From 1d8d63a9ffa5281c62dfecdf177395c619d409a5 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Mon, 26 May 2025 15:19:07 +1000 Subject: [PATCH 05/15] migrate package:objective_c --- pkgs/objective_c/pubspec.yaml | 7 ++-- pkgs/objective_c/test/cf_string_test.dart | 4 +- pkgs/objective_c/test/converter_test.dart | 4 +- .../test/interface_lists_test.dart | 39 ++++++++++--------- .../test/ns_input_stream_test.dart | 2 +- .../test/ns_mutable_data_test.dart | 4 +- pkgs/objective_c/test/nsarray_test.dart | 4 +- pkgs/objective_c/test/nsdata_test.dart | 4 +- pkgs/objective_c/test/nsdate_test.dart | 4 +- pkgs/objective_c/test/nsdictionary_test.dart | 4 +- .../objective_c/test/nsmutablearray_test.dart | 4 +- .../test/nsmutabledictionary_test.dart | 4 +- pkgs/objective_c/test/nsmutableset_test.dart | 4 +- pkgs/objective_c/test/nsnumber_test.dart | 4 +- pkgs/objective_c/test/nsset_test.dart | 4 +- pkgs/objective_c/test/nsstring_test.dart | 4 +- pkgs/objective_c/test/os_version_test.dart | 4 +- pkgs/objective_c/test/selector_test.dart | 4 +- pkgs/objective_c/test/util.dart | 12 ++++++ pubspec.yaml | 1 + 20 files changed, 83 insertions(+), 38 deletions(-) diff --git a/pkgs/objective_c/pubspec.yaml b/pkgs/objective_c/pubspec.yaml index 7ec7ae8256..d7d6d239f6 100644 --- a/pkgs/objective_c/pubspec.yaml +++ b/pkgs/objective_c/pubspec.yaml @@ -7,6 +7,7 @@ description: 'A library to access Objective C from Flutter that acts as a suppor version: 8.0.0 repository: https://github.com/dart-lang/native/tree/main/pkgs/objective_c issue_tracker: https://github.com/dart-lang/native/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aobjective_c +resolution: workspace topics: - interop @@ -15,7 +16,7 @@ topics: - codegen environment: - sdk: '>=3.4.0 <4.0.0' + sdk: '>=3.6.0 <4.0.0' flutter: '>=3.22.0' dependencies: @@ -27,9 +28,9 @@ dependencies: dev_dependencies: args: ^2.6.0 coverage: ^1.11.0 - dart_flutter_team_lints: ^2.0.0 + dart_flutter_team_lints: ^3.5.1 ffigen: ^19.0.0 - flutter_lints: ^3.0.0 + flutter_lints: ^5.0.0 flutter_test: sdk: flutter test: ^1.21.1 diff --git a/pkgs/objective_c/test/cf_string_test.dart b/pkgs/objective_c/test/cf_string_test.dart index d91c559f4a..bffc373280 100644 --- a/pkgs/objective_c/test/cf_string_test.dart +++ b/pkgs/objective_c/test/cf_string_test.dart @@ -11,11 +11,13 @@ import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('CFString', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); for (final s in ['Hello', '🇵🇬', 'Embedded\u0000Null']) { diff --git a/pkgs/objective_c/test/converter_test.dart b/pkgs/objective_c/test/converter_test.dart index ed2c51b285..a458fa26e2 100644 --- a/pkgs/objective_c/test/converter_test.dart +++ b/pkgs/objective_c/test/converter_test.dart @@ -11,11 +11,13 @@ import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('converter', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); test('basics', () { diff --git a/pkgs/objective_c/test/interface_lists_test.dart b/pkgs/objective_c/test/interface_lists_test.dart index acb42c6bd4..ea38507575 100644 --- a/pkgs/objective_c/test/interface_lists_test.dart +++ b/pkgs/objective_c/test/interface_lists_test.dart @@ -10,8 +10,11 @@ import 'dart:io'; import 'package:ffigen/src/code_generator/objc_built_in_functions.dart'; import 'package:test/test.dart'; +import 'package:path/path.dart' as p; import 'package:yaml/yaml.dart'; +import 'util.dart'; + const privateObjectiveCClasses = ['DartInputStreamAdapter']; void main() { @@ -21,10 +24,13 @@ void main() { late List yamlEnums; late List yamlProtocols; late List yamlCategories; + late String exportFile; + late List bindings; setUpAll(() { final yaml = - loadYaml(File('ffigen_objc.yaml').readAsStringSync()) as YamlMap; + loadYaml(File(p.join(pkgDir, 'ffigen_objc.yaml')).readAsStringSync()) + as YamlMap; final interfaceRenames = (yaml['objc-interfaces'] as YamlMap)['rename'] as YamlMap; @@ -61,6 +67,13 @@ void main() { .map((dynamic i) => i as String) .toList() ..sort(); + + exportFile = + File(p.join(pkgDir, 'lib', 'objective_c.dart')).readAsStringSync(); + bindings = File(p.join( + pkgDir, 'lib', 'src', 'objective_c_bindings_generated.dart')) + .readAsLinesSync() + .toList(); }); test('ObjCBuiltInFunctions.builtInInterfaces', () { @@ -84,7 +97,6 @@ void main() { }); test('package:objective_c exports all the interfaces', () { - final exportFile = File('lib/objective_c.dart').readAsStringSync(); for (final intf in yamlInterfaces) { if (!privateObjectiveCClasses.contains(intf)) { expect(exportFile, contains(RegExp('\\W$intf\\W'))); @@ -93,28 +105,24 @@ void main() { }); test('package:objective_c exports all the structs', () { - final exportFile = File('lib/objective_c.dart').readAsStringSync(); for (final struct in yamlStructs) { expect(exportFile, contains(RegExp('\\W$struct\\W'))); } }); test('package:objective_c exports all the enums', () { - final exportFile = File('lib/objective_c.dart').readAsStringSync(); for (final enum_ in yamlEnums) { expect(exportFile, contains(RegExp('\\W$enum_\\W'))); } }); test('package:objective_c exports all the protocols', () { - final exportFile = File('lib/objective_c.dart').readAsStringSync(); for (final protocol in yamlProtocols) { expect(exportFile, contains(RegExp('\\W$protocol\\W'))); } }); test('package:objective_c exports all the categories', () { - final exportFile = File('lib/objective_c.dart').readAsStringSync(); for (final category in yamlCategories) { expect(exportFile, contains(RegExp('\\W$category\\W'))); } @@ -123,8 +131,7 @@ void main() { test('All code genned interfaces are included in the list', () { final classNameRegExp = RegExp(r'^class ([^_]\w*) '); final allClassNames = []; - for (final line in File('lib/src/objective_c_bindings_generated.dart') - .readAsLinesSync()) { + for (final line in bindings) { final match = classNameRegExp.firstMatch(line); if (match != null) { allClassNames.add(match[1]!); @@ -138,8 +145,7 @@ void main() { final structNameRegExp = RegExp(r'^final class (\w+) extends ffi\.(Struct|Opaque)'); final allStructNames = []; - for (final line in File('lib/src/objective_c_bindings_generated.dart') - .readAsLinesSync()) { + for (final line in bindings) { final match = structNameRegExp.firstMatch(line); if (match != null) { allStructNames.add(match[1]!); @@ -152,8 +158,7 @@ void main() { test('All code genned enums are included in the list', () { final enumNameRegExp = RegExp(r'^enum (\w+) {'); final allEnumNames = []; - for (final line in File('lib/src/objective_c_bindings_generated.dart') - .readAsLinesSync()) { + for (final line in bindings) { final match = enumNameRegExp.firstMatch(line); if (match != null) { allEnumNames.add(match[1]!); @@ -165,8 +170,7 @@ void main() { test('All code genned protocols are included in the list', () { final protocolNameRegExp = RegExp(r'^interface class (\w+) '); final allProtocolNames = []; - for (final line in File('lib/src/objective_c_bindings_generated.dart') - .readAsLinesSync()) { + for (final line in bindings) { final match = protocolNameRegExp.firstMatch(line); if (match != null) { allProtocolNames.add(match[1]!); @@ -178,8 +182,7 @@ void main() { test('All code genned categories are included in the list', () { final categoryNameRegExp = RegExp(r'^extension (\w+) on \w+ {'); final allCategoryNames = []; - for (final line in File('lib/src/objective_c_bindings_generated.dart') - .readAsLinesSync()) { + for (final line in bindings) { final match = categoryNameRegExp.firstMatch(line); if (match != null) { allCategoryNames.add(match[1]!); @@ -189,9 +192,7 @@ void main() { }); test('No stubs', () { - final bindings = File('lib/src/objective_c_bindings_generated.dart') - .readAsStringSync(); - expect(bindings, isNot(contains(RegExp(r'\Wstub\W')))); + expect(bindings.join('\n'), isNot(contains(RegExp(r'\Wstub\W')))); }); }); } diff --git a/pkgs/objective_c/test/ns_input_stream_test.dart b/pkgs/objective_c/test/ns_input_stream_test.dart index 698d66799d..006dde9192 100644 --- a/pkgs/objective_c/test/ns_input_stream_test.dart +++ b/pkgs/objective_c/test/ns_input_stream_test.dart @@ -40,7 +40,7 @@ void main() { group('NSInputStream', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); group('toNSInputStream', () { diff --git a/pkgs/objective_c/test/ns_mutable_data_test.dart b/pkgs/objective_c/test/ns_mutable_data_test.dart index 4606f6702e..57e1448427 100644 --- a/pkgs/objective_c/test/ns_mutable_data_test.dart +++ b/pkgs/objective_c/test/ns_mutable_data_test.dart @@ -12,11 +12,13 @@ import 'package:ffi/ffi.dart'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('NSData', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); group('toNSData', () { diff --git a/pkgs/objective_c/test/nsarray_test.dart b/pkgs/objective_c/test/nsarray_test.dart index ba1721ef23..c366401bba 100644 --- a/pkgs/objective_c/test/nsarray_test.dart +++ b/pkgs/objective_c/test/nsarray_test.dart @@ -11,11 +11,13 @@ import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('NSArray', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); test('filled', () { diff --git a/pkgs/objective_c/test/nsdata_test.dart b/pkgs/objective_c/test/nsdata_test.dart index 35f357a42b..6c6250480b 100644 --- a/pkgs/objective_c/test/nsdata_test.dart +++ b/pkgs/objective_c/test/nsdata_test.dart @@ -12,11 +12,13 @@ import 'package:ffi/ffi.dart'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('NSData', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); group('toNSData', () { diff --git a/pkgs/objective_c/test/nsdate_test.dart b/pkgs/objective_c/test/nsdate_test.dart index 7c9b3954fc..db629bb1ec 100644 --- a/pkgs/objective_c/test/nsdate_test.dart +++ b/pkgs/objective_c/test/nsdate_test.dart @@ -11,11 +11,13 @@ import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('NSDate', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); test('from DateTime', () { diff --git a/pkgs/objective_c/test/nsdictionary_test.dart b/pkgs/objective_c/test/nsdictionary_test.dart index 8215dbef75..9d9d6bea59 100644 --- a/pkgs/objective_c/test/nsdictionary_test.dart +++ b/pkgs/objective_c/test/nsdictionary_test.dart @@ -11,11 +11,13 @@ import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('NSDictionary', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); test('of', () { diff --git a/pkgs/objective_c/test/nsmutablearray_test.dart b/pkgs/objective_c/test/nsmutablearray_test.dart index f095930b69..d01b21571b 100644 --- a/pkgs/objective_c/test/nsmutablearray_test.dart +++ b/pkgs/objective_c/test/nsmutablearray_test.dart @@ -11,11 +11,13 @@ import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('NSMutableArray', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); test('filled', () { diff --git a/pkgs/objective_c/test/nsmutabledictionary_test.dart b/pkgs/objective_c/test/nsmutabledictionary_test.dart index 11892f38cc..101867c629 100644 --- a/pkgs/objective_c/test/nsmutabledictionary_test.dart +++ b/pkgs/objective_c/test/nsmutabledictionary_test.dart @@ -11,11 +11,13 @@ import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('NSMutableDictionary', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); test('of', () { diff --git a/pkgs/objective_c/test/nsmutableset_test.dart b/pkgs/objective_c/test/nsmutableset_test.dart index bf610b86a8..e294cfb43c 100644 --- a/pkgs/objective_c/test/nsmutableset_test.dart +++ b/pkgs/objective_c/test/nsmutableset_test.dart @@ -11,11 +11,13 @@ import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('NSMutableSet', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); test('of', () { diff --git a/pkgs/objective_c/test/nsnumber_test.dart b/pkgs/objective_c/test/nsnumber_test.dart index 61356d0d2f..bcecd1e937 100644 --- a/pkgs/objective_c/test/nsnumber_test.dart +++ b/pkgs/objective_c/test/nsnumber_test.dart @@ -11,11 +11,13 @@ import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('NSNumber', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); test('from double', () { diff --git a/pkgs/objective_c/test/nsset_test.dart b/pkgs/objective_c/test/nsset_test.dart index daf0807b8e..29e9127885 100644 --- a/pkgs/objective_c/test/nsset_test.dart +++ b/pkgs/objective_c/test/nsset_test.dart @@ -11,11 +11,13 @@ import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('NSSet', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); test('of', () { diff --git a/pkgs/objective_c/test/nsstring_test.dart b/pkgs/objective_c/test/nsstring_test.dart index cf5131f60b..c58ab33bab 100644 --- a/pkgs/objective_c/test/nsstring_test.dart +++ b/pkgs/objective_c/test/nsstring_test.dart @@ -11,11 +11,13 @@ import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('NSString', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); for (final s in ['Hello', '🇵🇬', 'Embedded\u0000Null']) { diff --git a/pkgs/objective_c/test/os_version_test.dart b/pkgs/objective_c/test/os_version_test.dart index 03e186416a..925a76b027 100644 --- a/pkgs/objective_c/test/os_version_test.dart +++ b/pkgs/objective_c/test/os_version_test.dart @@ -11,11 +11,13 @@ import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('osVersion', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); test('getter', () { diff --git a/pkgs/objective_c/test/selector_test.dart b/pkgs/objective_c/test/selector_test.dart index 456e13e970..cf2d68d79f 100644 --- a/pkgs/objective_c/test/selector_test.dart +++ b/pkgs/objective_c/test/selector_test.dart @@ -11,11 +11,13 @@ import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'package:test/test.dart'; +import 'util.dart'; + void main() { group('Selector', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('test/objective_c.dylib'); + DynamicLibrary.open(testDylib); }); test('from String and back', () { diff --git a/pkgs/objective_c/test/util.dart b/pkgs/objective_c/test/util.dart index 7db7e1e0a8..1c0fabbad9 100644 --- a/pkgs/objective_c/test/util.dart +++ b/pkgs/objective_c/test/util.dart @@ -8,11 +8,13 @@ // ignore_for_file: avoid_catching_errors import 'dart:ffi'; +import 'dart:isolate'; import 'package:ffi/ffi.dart'; import 'package:objective_c/objective_c.dart'; import 'package:objective_c/src/internal.dart' as internal_for_testing show isValidClass; +import 'package:path/path.dart' as p; final _executeInternalCommand = () { try { @@ -63,3 +65,13 @@ int objectRetainCount(Pointer object) { if (!internal_for_testing.isValidClass(clazz)) return 0; return _getObjectRetainCount(object.cast()); } + +String pkgDir = p.normalize(p.join( + Isolate.resolvePackageUriSync( + Uri.parse('package:objective_c/objective_c.dart'))! + .toFilePath(), + '..', + '..')); + +// TODO(https://github.com/dart-lang/native/issues/1068): Remove this. +String testDylib = p.join(pkgDir, 'test', 'objective_c.dylib'); diff --git a/pubspec.yaml b/pubspec.yaml index 7bd60f2601..910902ccd9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,6 +57,7 @@ workspace: - pkgs/hooks/example/link/package_with_assets - pkgs/json_syntax_generator - pkgs/native_toolchain_c + - pkgs/objective_c - pkgs/swift2objc - pkgs/repo_lint_rules From d071eae48ae09e491ea21bc4337f74dc3d9ee287 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Tue, 27 May 2025 11:26:27 +1000 Subject: [PATCH 06/15] migrate swiftgen --- pkgs/swiftgen/pubspec.yaml | 5 +++-- pubspec.yaml | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkgs/swiftgen/pubspec.yaml b/pkgs/swiftgen/pubspec.yaml index 664fd220ca..9bb397a875 100644 --- a/pkgs/swiftgen/pubspec.yaml +++ b/pkgs/swiftgen/pubspec.yaml @@ -7,6 +7,7 @@ description: 'A tool for generating bindings that allow interop between Dart and version: 0.0.1-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/swiftgen issue_tracker: https://github.com/dart-lang/native/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aswiftgen +resolution: workspace topics: - interop @@ -15,13 +16,13 @@ topics: - codegen environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.6.0 <4.0.0' dependencies: ffi: ^2.1.0 dev_dependencies: - dart_flutter_team_lints: ^2.0.0 + dart_flutter_team_lints: ^3.5.1 ffigen: ^11.0.0 test: ^1.21.1 diff --git a/pubspec.yaml b/pubspec.yaml index 910902ccd9..4b223d1eac 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -59,6 +59,7 @@ workspace: - pkgs/native_toolchain_c - pkgs/objective_c - pkgs/swift2objc + - pkgs/swiftgen - pkgs/repo_lint_rules # Hook user-defines are specified in the pub workspace. From 89266360af8736457c6b2de37e5b3a31e8dc413f Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Tue, 27 May 2025 11:30:26 +1000 Subject: [PATCH 07/15] fix swiftgen --- pkgs/swiftgen/pubspec.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pkgs/swiftgen/pubspec.yaml b/pkgs/swiftgen/pubspec.yaml index 9bb397a875..6fcbe32050 100644 --- a/pkgs/swiftgen/pubspec.yaml +++ b/pkgs/swiftgen/pubspec.yaml @@ -23,9 +23,5 @@ dependencies: dev_dependencies: dart_flutter_team_lints: ^3.5.1 - ffigen: ^11.0.0 + ffigen: ^19.0.0 test: ^1.21.1 - -dependency_overrides: - ffigen: - path: ../ffigen/ From 180972a7645763c82a319fcdfdd06f40c19e8c17 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Tue, 27 May 2025 13:25:21 +1000 Subject: [PATCH 08/15] Poke native workflow --- .github/workflows/native.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/native.yaml b/.github/workflows/native.yaml index 33ad42f5e1..2ff3d8c375 100644 --- a/.github/workflows/native.yaml +++ b/.github/workflows/native.yaml @@ -2,6 +2,7 @@ # # Combined into a single workflow so that deps are configured and installed once. + name: native permissions: read-all From f5258bd313840374ca72211d9f1a99b70c0685de Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Tue, 27 May 2025 13:39:18 +1000 Subject: [PATCH 09/15] Remove packages from the workspace --- .github/workflows/native.yaml | 2 -- pkgs/objective_c/pubspec.yaml | 1 - pkgs/swift2objc/pubspec.yaml | 1 - pkgs/swiftgen/pubspec.yaml | 1 - pubspec.yaml | 3 --- 5 files changed, 8 deletions(-) diff --git a/.github/workflows/native.yaml b/.github/workflows/native.yaml index 2ff3d8c375..65f01cbb15 100644 --- a/.github/workflows/native.yaml +++ b/.github/workflows/native.yaml @@ -1,8 +1,6 @@ # CI for the native_* packages. # # Combined into a single workflow so that deps are configured and installed once. - - name: native permissions: read-all diff --git a/pkgs/objective_c/pubspec.yaml b/pkgs/objective_c/pubspec.yaml index 09656ec668..c586832760 100644 --- a/pkgs/objective_c/pubspec.yaml +++ b/pkgs/objective_c/pubspec.yaml @@ -7,7 +7,6 @@ description: 'A library to access Objective C from Flutter that acts as a suppor version: 8.0.0 repository: https://github.com/dart-lang/native/tree/main/pkgs/objective_c issue_tracker: https://github.com/dart-lang/native/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aobjective_c -resolution: workspace topics: - interop diff --git a/pkgs/swift2objc/pubspec.yaml b/pkgs/swift2objc/pubspec.yaml index 34061ec06e..b615519607 100644 --- a/pkgs/swift2objc/pubspec.yaml +++ b/pkgs/swift2objc/pubspec.yaml @@ -7,7 +7,6 @@ description: 'A tool for generating bindings that allow interop between Dart and version: 0.0.1-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/swiftgen/swift2objc issue_tracker: https://github.com/dart-lang/native/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aswift2objc -resolution: workspace topics: - interop diff --git a/pkgs/swiftgen/pubspec.yaml b/pkgs/swiftgen/pubspec.yaml index 6fcbe32050..deb17a7737 100644 --- a/pkgs/swiftgen/pubspec.yaml +++ b/pkgs/swiftgen/pubspec.yaml @@ -7,7 +7,6 @@ description: 'A tool for generating bindings that allow interop between Dart and version: 0.0.1-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/swiftgen issue_tracker: https://github.com/dart-lang/native/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aswiftgen -resolution: workspace topics: - interop diff --git a/pubspec.yaml b/pubspec.yaml index 4b223d1eac..d2e324ea35 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,9 +57,6 @@ workspace: - pkgs/hooks/example/link/package_with_assets - pkgs/json_syntax_generator - pkgs/native_toolchain_c - - pkgs/objective_c - - pkgs/swift2objc - - pkgs/swiftgen - pkgs/repo_lint_rules # Hook user-defines are specified in the pub workspace. From 945ca98ba36a27c17a8b8d98c2d96f989c4bf78d Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Tue, 27 May 2025 14:33:31 +1000 Subject: [PATCH 10/15] Fix analysis --- pkgs/objective_c/pubspec.yaml | 1 + pkgs/objective_c/test/interface_lists_test.dart | 2 +- pkgs/swift2objc/lib/src/config.dart | 2 +- pkgs/swift2objc/test/utils.dart | 1 - 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/objective_c/pubspec.yaml b/pkgs/objective_c/pubspec.yaml index c586832760..c73a25071f 100644 --- a/pkgs/objective_c/pubspec.yaml +++ b/pkgs/objective_c/pubspec.yaml @@ -31,6 +31,7 @@ dev_dependencies: flutter_lints: ^5.0.0 flutter_test: sdk: flutter + path: ^1.9.0 test: ^1.21.1 yaml: ^3.1.0 diff --git a/pkgs/objective_c/test/interface_lists_test.dart b/pkgs/objective_c/test/interface_lists_test.dart index ea38507575..5b03607d05 100644 --- a/pkgs/objective_c/test/interface_lists_test.dart +++ b/pkgs/objective_c/test/interface_lists_test.dart @@ -9,8 +9,8 @@ library; import 'dart:io'; import 'package:ffigen/src/code_generator/objc_built_in_functions.dart'; -import 'package:test/test.dart'; import 'package:path/path.dart' as p; +import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; import 'util.dart'; diff --git a/pkgs/swift2objc/lib/src/config.dart b/pkgs/swift2objc/lib/src/config.dart index 30847e7458..ef0bb26159 100644 --- a/pkgs/swift2objc/lib/src/config.dart +++ b/pkgs/swift2objc/lib/src/config.dart @@ -41,7 +41,7 @@ class Config { /// Includes all declarations by default final bool Function(Declaration declaration) include; - static bool _defaultInclude(_) => true; + static bool _defaultInclude(Declaration _) => true; const Config( {required this.input, diff --git a/pkgs/swift2objc/test/utils.dart b/pkgs/swift2objc/test/utils.dart index f195242e1c..f18f25e2db 100644 --- a/pkgs/swift2objc/test/utils.dart +++ b/pkgs/swift2objc/test/utils.dart @@ -1,5 +1,4 @@ import 'dart:isolate'; -import 'dart:io'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; From 8b05af0d5e6118c71f414c0579b688d7c99f7368 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Tue, 27 May 2025 15:44:37 +1000 Subject: [PATCH 11/15] migrate ffigen --- .../lib/src/config_provider/config_spec.dart | 4 +- .../config_provider/overrideable_utils.dart | 7 +- .../reserved_keyword_collision_test.dart | 8 +- .../test/config_tests/json_schema_test.dart | 24 +++- .../example_tests/cjson_example_test.dart | 8 +- .../example_tests/ffinative_example_test.dart | 8 +- .../example_tests/libclang_example_test.dart | 9 +- .../objective_c_example_test.dart | 8 +- .../shared_bindings_example_test.dart | 2 + .../example_tests/simple_example_test.dart | 1 + .../example_tests/swift_example_test.dart | 3 +- .../header_parser_tests/globals_test.dart | 7 +- .../test/header_parser_tests/macros_test.dart | 7 +- .../test/header_parser_tests/sort_test.dart | 10 +- .../large_objc_test.dart | 26 ++++- .../large_integration_tests/large_test.dart | 37 +++++- .../test/native_objc_test/arc_test.dart | 16 ++- .../native_objc_test/bad_method_test.dart | 16 ++- .../native_objc_test/bad_override_test.dart | 16 ++- .../block_annotation_test.dart | 16 ++- .../native_objc_test/block_inherit_test.dart | 16 ++- .../test/native_objc_test/block_test.dart | 24 +++- .../test/native_objc_test/cast_test.dart | 16 ++- .../test/native_objc_test/category_test.dart | 24 +++- .../native_objc_test/deprecated_test.dart | 25 +++- .../native_objc_test/forward_decl_test.dart | 16 ++- .../native_objc_test/global_native_test.dart | 16 ++- .../test/native_objc_test/global_test.dart | 16 ++- .../inherited_instancetype_test.dart | 16 ++- .../native_objc_test/is_instance_test.dart | 16 ++- .../test/native_objc_test/isolate_test.dart | 16 ++- .../test/native_objc_test/log_test.dart | 16 ++- .../method_filtering_test.dart | 9 +- .../test/native_objc_test/method_test.dart | 16 ++- .../native_objc_test/native_objc_test.dart | 16 ++- .../test/native_objc_test/ns_range_test.dart | 25 +++- .../nullable_inheritance_test.dart | 16 ++- .../test/native_objc_test/nullable_test.dart | 16 ++- .../test/native_objc_test/property_test.dart | 16 ++- .../test/native_objc_test/protocol_test.dart | 24 +++- .../test/native_objc_test/ref_count_test.dart | 16 ++- .../test/native_objc_test/rename_test.dart | 16 ++- .../runtime_version_test.dart | 16 ++- .../native_objc_test/sdk_variable_test.dart | 24 +++- .../static_func_native_test.dart | 16 ++- .../native_objc_test/static_func_test.dart | 16 ++- .../test/native_objc_test/string_test.dart | 16 ++- .../native_objc_test/swift_class_test.dart | 16 ++- .../native_objc_test/transitive_test.dart | 25 +++- .../test/native_objc_test/typedef_test.dart | 16 ++- pkgs/ffigen/test/native_objc_test/util.dart | 7 +- pkgs/ffigen/test/native_test/native_test.dart | 16 ++- pkgs/ffigen/test/regen.dart | 7 +- pkgs/ffigen/test/test_utils.dart | 2 + pkgs/swift2objc/lib/src/config.dart | 66 ++++++----- .../test/integration/integration_test.dart | 24 ++-- pkgs/swift2objc/test/unit/filter_test.dart | 107 ++++++++++-------- pkgs/swift2objc/test/utils.dart | 11 +- 58 files changed, 786 insertions(+), 219 deletions(-) diff --git a/pkgs/ffigen/lib/src/config_provider/config_spec.dart b/pkgs/ffigen/lib/src/config_provider/config_spec.dart index 9f79d211a2..62ee4d2378 100644 --- a/pkgs/ffigen/lib/src/config_provider/config_spec.dart +++ b/pkgs/ffigen/lib/src/config_provider/config_spec.dart @@ -141,9 +141,9 @@ class ConfigValue { ) { ConfigValue returnValue; if (transform != null) { - returnValue = this.withValue(transform.call(this), rawValue); + returnValue = withValue(transform.call(this), rawValue); } else { - returnValue = this.withValue(this.value as RE, rawValue); + returnValue = withValue(value as RE, rawValue); } resultCallback?.call(returnValue); return returnValue; diff --git a/pkgs/ffigen/lib/src/config_provider/overrideable_utils.dart b/pkgs/ffigen/lib/src/config_provider/overrideable_utils.dart index 17233ec77d..26b5a511d3 100644 --- a/pkgs/ffigen/lib/src/config_provider/overrideable_utils.dart +++ b/pkgs/ffigen/lib/src/config_provider/overrideable_utils.dart @@ -11,6 +11,7 @@ library; import 'dart:io'; +import 'dart:isolate'; import 'package:path/path.dart' as p; @@ -41,7 +42,11 @@ final libclangOverridePaths = const []; /// Returns the root path of the package, for use during tests. /// /// Note that `dart test` sets the current directory to the package root. -final packagePathForTests = p.current; +final packagePathForTests = p.normalize(p.join( + Isolate.resolvePackageUriSync(Uri.parse('package:ffigen/ffigen.dart'))! + .toFilePath(), + '..', + '..')); /// Returns a path to a config yaml in a unit test. String configPathForTest(String directory, String file) => diff --git a/pkgs/ffigen/test/collision_tests/reserved_keyword_collision_test.dart b/pkgs/ffigen/test/collision_tests/reserved_keyword_collision_test.dart index b7cdc5da7a..7489d8724c 100644 --- a/pkgs/ffigen/test/collision_tests/reserved_keyword_collision_test.dart +++ b/pkgs/ffigen/test/collision_tests/reserved_keyword_collision_test.dart @@ -5,6 +5,7 @@ import 'package:ffigen/src/config_provider.dart'; import 'package:ffigen/src/header_parser.dart' as parser; import 'package:logging/logging.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -18,7 +19,12 @@ void main() { final library = parser.parse(Config( output: Uri.file('unused'), entryPoints: [ - Uri.file('test/collision_tests/reserved_keyword_collision.h') + Uri.file(path.join( + packagePathForTests, + 'test', + 'collision_tests', + 'reserved_keyword_collision.h', + )) ], structDecl: DeclarationFilters.includeAll, unionDecl: DeclarationFilters.includeAll, diff --git a/pkgs/ffigen/test/config_tests/json_schema_test.dart b/pkgs/ffigen/test/config_tests/json_schema_test.dart index b33d8e86d1..65f69a5180 100644 --- a/pkgs/ffigen/test/config_tests/json_schema_test.dart +++ b/pkgs/ffigen/test/config_tests/json_schema_test.dart @@ -10,9 +10,12 @@ import 'package:ffigen/src/strings.dart' as strings; import 'package:file/local.dart'; import 'package:glob/glob.dart'; import 'package:json_schema/json_schema.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; +import '../test_utils.dart'; + void main() { group('json_schema_test', () { final schema = YamlConfig.getsRootConfigSpec() @@ -24,9 +27,10 @@ void main() { YamlConfig.getsRootConfigSpec() .generateJsonSchema(strings.ffigenJsonSchemaId), ); - final expectedJsonSchema = File(strings.ffigenJsonSchemaFileName) - .readAsStringSync() - .replaceAll('\r\n', '\n'); + final expectedJsonSchema = File(path.join( + packagePathForTests, + strings.ffigenJsonSchemaFileName, + )).readAsStringSync().replaceAll('\r\n', '\n'); expect(actualJsonSchema, expectedJsonSchema); }); @@ -36,15 +40,23 @@ void main() { }); // Find all ffigen config files in the repo. - final configYamlGlob = Glob('**config.yaml'); + final configYamlGlob = Glob(path.join( + packagePathForTests, + '**config.yaml', + )); final configYamlFiles = configYamlGlob.listFileSystemSync(const LocalFileSystem()); test('$configYamlGlob files not empty', () { expect(configYamlFiles.isNotEmpty, true); }); - final sharedBindingsConfigYamlGlob = - Glob('example/shared_bindings/ffigen_configs/**.yaml'); + final sharedBindingsConfigYamlGlob = Glob(path.join( + packagePathForTests, + 'example', + 'shared_bindings', + 'ffigen_configs', + '**.yaml', + )); final sharedBindingsConfigYamlFiles = sharedBindingsConfigYamlGlob .listFileSystemSync(const LocalFileSystem()); test('$sharedBindingsConfigYamlGlob files not emty', () { diff --git a/pkgs/ffigen/test/example_tests/cjson_example_test.dart b/pkgs/ffigen/test/example_tests/cjson_example_test.dart index 7a8dd1d4a6..e0c688a6b5 100644 --- a/pkgs/ffigen/test/example_tests/cjson_example_test.dart +++ b/pkgs/ffigen/test/example_tests/cjson_example_test.dart @@ -15,8 +15,12 @@ void main() { logWarnings(Level.SEVERE); }); test('c_json', () { - final config = - testConfigFromPath(path.join('example', 'c_json', 'config.yaml')); + final config = testConfigFromPath(path.join( + packagePathForTests, + 'example', + 'c_json', + 'config.yaml', + )); final library = parse(config); matchLibraryWithExpected( diff --git a/pkgs/ffigen/test/example_tests/ffinative_example_test.dart b/pkgs/ffigen/test/example_tests/ffinative_example_test.dart index 91438cf6dc..d68d0894c6 100644 --- a/pkgs/ffigen/test/example_tests/ffinative_example_test.dart +++ b/pkgs/ffigen/test/example_tests/ffinative_example_test.dart @@ -16,8 +16,12 @@ void main() { }); test('ffinative', () { - final config = - testConfigFromPath(path.join('example', 'ffinative', 'config.yaml')); + final config = testConfigFromPath(path.join( + packagePathForTests, + 'example', + 'ffinative', + 'config.yaml', + )); final library = parse(config); matchLibraryWithExpected( diff --git a/pkgs/ffigen/test/example_tests/libclang_example_test.dart b/pkgs/ffigen/test/example_tests/libclang_example_test.dart index 441ea919ef..6dcd448897 100644 --- a/pkgs/ffigen/test/example_tests/libclang_example_test.dart +++ b/pkgs/ffigen/test/example_tests/libclang_example_test.dart @@ -19,9 +19,12 @@ void main() { logWarnings(Level.SEVERE); }); test('libclang-example', () { - final configYaml = - File(path.join('example', 'libclang-example', 'config.yaml')) - .absolute; + final configYaml = File(path.join( + packagePathForTests, + 'example', + 'libclang-example', + 'config.yaml', + )).absolute; late Config config; late Library library; withChDir(configYaml.path, () { diff --git a/pkgs/ffigen/test/example_tests/objective_c_example_test.dart b/pkgs/ffigen/test/example_tests/objective_c_example_test.dart index 349868c068..82b3beb774 100644 --- a/pkgs/ffigen/test/example_tests/objective_c_example_test.dart +++ b/pkgs/ffigen/test/example_tests/objective_c_example_test.dart @@ -20,8 +20,12 @@ void main() { }); test('objective_c', () { - final config = testConfigFromPath( - path.join('example', 'objective_c', 'config.yaml')); + final config = testConfigFromPath(path.join( + packagePathForTests, + 'example', + 'objective_c', + 'config.yaml', + )); final output = parse(config).generate(); // Verify that the output contains all the methods and classes that the diff --git a/pkgs/ffigen/test/example_tests/shared_bindings_example_test.dart b/pkgs/ffigen/test/example_tests/shared_bindings_example_test.dart index d6470a4f5f..03c47f4eb5 100644 --- a/pkgs/ffigen/test/example_tests/shared_bindings_example_test.dart +++ b/pkgs/ffigen/test/example_tests/shared_bindings_example_test.dart @@ -17,6 +17,7 @@ void main() { test('a_shared_base bindings', () { final config = testConfigFromPath(path.join( + packagePathForTests, 'example', 'shared_bindings', 'ffigen_configs', @@ -33,6 +34,7 @@ void main() { test('base symbol file output', () { final config = testConfigFromPath(path.join( + packagePathForTests, 'example', 'shared_bindings', 'ffigen_configs', diff --git a/pkgs/ffigen/test/example_tests/simple_example_test.dart b/pkgs/ffigen/test/example_tests/simple_example_test.dart index d151bdcac7..dfebd1a53f 100644 --- a/pkgs/ffigen/test/example_tests/simple_example_test.dart +++ b/pkgs/ffigen/test/example_tests/simple_example_test.dart @@ -17,6 +17,7 @@ void main() { test('simple', () { final config = testConfigFromPath(path.join( + packagePathForTests, 'example', 'simple', 'config.yaml', diff --git a/pkgs/ffigen/test/example_tests/swift_example_test.dart b/pkgs/ffigen/test/example_tests/swift_example_test.dart index c9a52036f7..0f76be5460 100644 --- a/pkgs/ffigen/test/example_tests/swift_example_test.dart +++ b/pkgs/ffigen/test/example_tests/swift_example_test.dart @@ -37,13 +37,14 @@ void main() { '-o', 'libswiftapi.dylib', ], - workingDirectory: path.join(Directory.current.path, 'example/swift')); + workingDirectory: path.join(packagePathForTests, 'example/swift')); unawaited(stdout.addStream(process.stdout)); unawaited(stderr.addStream(process.stderr)); final result = await process.exitCode; expect(result, 0); final config = testConfigFromPath(path.join( + packagePathForTests, 'example', 'swift', 'config.yaml', diff --git a/pkgs/ffigen/test/header_parser_tests/globals_test.dart b/pkgs/ffigen/test/header_parser_tests/globals_test.dart index 6a319a7951..17f7d8fc80 100644 --- a/pkgs/ffigen/test/header_parser_tests/globals_test.dart +++ b/pkgs/ffigen/test/header_parser_tests/globals_test.dart @@ -18,7 +18,12 @@ void main() { expected = expectedLibrary(); actual = parser.parse( testConfigFromPath(configPath( - path.join('test', 'header_parser_tests'), 'globals_config.yaml')), + path.join( + packagePathForTests, + 'test', + 'header_parser_tests', + ), + 'globals_config.yaml')), ); }); diff --git a/pkgs/ffigen/test/header_parser_tests/macros_test.dart b/pkgs/ffigen/test/header_parser_tests/macros_test.dart index 17bb6cea4a..da9a8cdff0 100644 --- a/pkgs/ffigen/test/header_parser_tests/macros_test.dart +++ b/pkgs/ffigen/test/header_parser_tests/macros_test.dart @@ -20,7 +20,12 @@ void main() { expected = expectedLibrary(); actual = parser.parse( testConfigFromPath(configPath( - path.join('test', 'header_parser_tests'), 'macros_config.yaml')), + path.join( + packagePathForTests, + 'test', + 'header_parser_tests', + ), + 'macros_config.yaml')), ); }); test('Total bindings count', () { diff --git a/pkgs/ffigen/test/header_parser_tests/sort_test.dart b/pkgs/ffigen/test/header_parser_tests/sort_test.dart index 933103624a..6ec3541e59 100644 --- a/pkgs/ffigen/test/header_parser_tests/sort_test.dart +++ b/pkgs/ffigen/test/header_parser_tests/sort_test.dart @@ -5,6 +5,7 @@ import 'package:ffigen/src/code_generator.dart'; import 'package:ffigen/src/config_provider.dart'; import 'package:ffigen/src/header_parser.dart' as parser; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -17,7 +18,14 @@ void main() { logWarnings(); actual = parser.parse(Config( output: Uri.file('unused'), - entryPoints: [Uri.file('test/header_parser_tests/sort.h')], + entryPoints: [ + Uri.file(path.join( + packagePathForTests, + 'test', + 'header_parser_tests', + 'sort.h', + )) + ], structDecl: DeclarationFilters.includeAll, unionDecl: DeclarationFilters.includeAll, typedefs: DeclarationFilters.includeAll, diff --git a/pkgs/ffigen/test/large_integration_tests/large_objc_test.dart b/pkgs/ffigen/test/large_integration_tests/large_objc_test.dart index 58f919c543..092eb553d9 100644 --- a/pkgs/ffigen/test/large_integration_tests/large_objc_test.dart +++ b/pkgs/ffigen/test/large_integration_tests/large_objc_test.dart @@ -16,9 +16,12 @@ import 'package:ffigen/ffigen.dart'; import 'package:ffigen/src/code_generator/utils.dart'; import 'package:ffigen/src/config_provider/config_types.dart'; import 'package:logging/logging.dart'; +import 'package:path/path.dart' as path; import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; +import '../test_utils.dart'; + Future run(String exe, List args) async { final process = await Process.start(exe, args, mode: ProcessStartMode.inheritStdio); @@ -41,14 +44,31 @@ void main() { randInclude('$kind.memb', clazz, method), ); - const outFile = 'test/large_integration_tests/large_objc_bindings.dart'; - const outObjCFile = 'test/large_integration_tests/large_objc_bindings.m'; + final outFile = path.join( + packagePathForTests, + 'test', + 'large_integration_tests', + 'large_objc_bindings.dart', + ); + final outObjCFile = path.join( + packagePathForTests, + 'test', + 'large_integration_tests', + 'large_objc_bindings.m', + ); final config = Config( wrapperName: 'LargeObjCLibrary', language: Language.objc, output: Uri.file(outFile), outputObjC: Uri.file(outObjCFile), - entryPoints: [Uri.file('test/large_integration_tests/large_objc_test.h')], + entryPoints: [ + Uri.file(path.join( + packagePathForTests, + 'test', + 'large_integration_tests', + 'large_objc_test.h', + )) + ], formatOutput: false, includeTransitiveObjCInterfaces: false, includeTransitiveObjCProtocols: false, diff --git a/pkgs/ffigen/test/large_integration_tests/large_test.dart b/pkgs/ffigen/test/large_integration_tests/large_test.dart index b4ae370abd..0bf291ad85 100644 --- a/pkgs/ffigen/test/large_integration_tests/large_test.dart +++ b/pkgs/ffigen/test/large_integration_tests/large_test.dart @@ -7,6 +7,7 @@ import 'package:ffigen/src/config_provider/config.dart'; import 'package:ffigen/src/config_provider/config_types.dart'; import 'package:ffigen/src/header_parser.dart'; import 'package:logging/logging.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -23,13 +24,27 @@ void main() { output: Uri.file('unused'), compilerOpts: [ ...defaultCompilerOpts(), - '-Ithird_party/libclang/include', + '-I${path.join( + packagePathForTests, + 'third_party', + 'libclang', + 'include', + )}', ], commentType: CommentType( CommentStyle.doxygen, CommentLength.brief, ), - entryPoints: [Uri.file('third_party/libclang/include/clang-c/Index.h')], + entryPoints: [ + Uri.file(path.join( + packagePathForTests, + 'third_party', + 'libclang', + 'include', + 'clang-c', + 'Index.h', + )) + ], shouldIncludeHeaderFunc: (Uri header) => [ 'BuildSystem.h', 'CXCompilationDatabase.h', @@ -69,7 +84,14 @@ void main() { wrapperName: 'CJson', wrapperDocComment: 'Bindings to Cjson.', output: Uri.file('unused'), - entryPoints: [Uri.file('third_party/cjson_library/cJSON.h')], + entryPoints: [ + Uri.file(path.join( + packagePathForTests, + 'third_party', + 'cjson_library', + 'cJSON.h', + )) + ], shouldIncludeHeaderFunc: (Uri header) => header.pathSegments.last == 'cJSON.h', functionDecl: DeclarationFilters.includeAll, @@ -100,7 +122,14 @@ void main() { CommentStyle.any, CommentLength.full, ), - entryPoints: [Uri.file('third_party/sqlite/sqlite3.h')], + entryPoints: [ + Uri.file(path.join( + packagePathForTests, + 'third_party', + 'sqlite', + 'sqlite3.h', + )) + ], shouldIncludeHeaderFunc: (Uri header) => header.pathSegments.last == 'sqlite3.h', functionDecl: DeclarationFilters( diff --git a/pkgs/ffigen/test/native_objc_test/arc_test.dart b/pkgs/ffigen/test/native_objc_test/arc_test.dart index f851896d19..27ed791043 100644 --- a/pkgs/ffigen/test/native_objc_test/arc_test.dart +++ b/pkgs/ffigen/test/native_objc_test/arc_test.dart @@ -12,6 +12,7 @@ import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'arc_bindings.dart'; @@ -23,8 +24,19 @@ void main() { group('ARC', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); lib = ArcTestObjCLibrary(DynamicLibrary.open(dylib.absolute.path)); diff --git a/pkgs/ffigen/test/native_objc_test/bad_method_test.dart b/pkgs/ffigen/test/native_objc_test/bad_method_test.dart index 90b7940f83..33db48fbd8 100644 --- a/pkgs/ffigen/test/native_objc_test/bad_method_test.dart +++ b/pkgs/ffigen/test/native_objc_test/bad_method_test.dart @@ -11,14 +11,26 @@ import 'dart:io'; import 'package:test/test.dart'; import '../test_utils.dart'; import 'bad_method_test_bindings.dart'; +import 'package:path/path.dart' as path; import 'util.dart'; void main() { group('bad_method_test', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('bad_method'); diff --git a/pkgs/ffigen/test/native_objc_test/bad_override_test.dart b/pkgs/ffigen/test/native_objc_test/bad_override_test.dart index eb5aed1cc1..d595cfa895 100644 --- a/pkgs/ffigen/test/native_objc_test/bad_override_test.dart +++ b/pkgs/ffigen/test/native_objc_test/bad_override_test.dart @@ -10,6 +10,7 @@ import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'bad_override_bindings.dart'; @@ -19,8 +20,19 @@ void main() { group('bad overrides', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('bad_override'); diff --git a/pkgs/ffigen/test/native_objc_test/block_annotation_test.dart b/pkgs/ffigen/test/native_objc_test/block_annotation_test.dart index bd15c9b588..f7289c0808 100644 --- a/pkgs/ffigen/test/native_objc_test/block_annotation_test.dart +++ b/pkgs/ffigen/test/native_objc_test/block_annotation_test.dart @@ -15,6 +15,7 @@ import 'package:ffi/ffi.dart'; import 'package:objective_c/objective_c.dart'; import 'package:objective_c/src/internal.dart' as internal_for_testing show blockHasRegisteredClosure; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -37,8 +38,19 @@ void main() { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); lib = BlockAnnotationTestLibrary(DynamicLibrary.open(dylib.absolute.path)); diff --git a/pkgs/ffigen/test/native_objc_test/block_inherit_test.dart b/pkgs/ffigen/test/native_objc_test/block_inherit_test.dart index 41708f9d8b..3bc7520e35 100644 --- a/pkgs/ffigen/test/native_objc_test/block_inherit_test.dart +++ b/pkgs/ffigen/test/native_objc_test/block_inherit_test.dart @@ -12,6 +12,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -22,8 +23,19 @@ void main() { group('Block inheritance', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); diff --git a/pkgs/ffigen/test/native_objc_test/block_test.dart b/pkgs/ffigen/test/native_objc_test/block_test.dart index c43ae66a41..1d9df361b9 100644 --- a/pkgs/ffigen/test/native_objc_test/block_test.dart +++ b/pkgs/ffigen/test/native_objc_test/block_test.dart @@ -16,6 +16,7 @@ import 'package:ffi/ffi.dart'; import 'package:objective_c/objective_c.dart'; import 'package:objective_c/src/internal.dart' as internal_for_testing show blockHasRegisteredClosure; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -53,8 +54,19 @@ void main() { group('Blocks', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); lib = BlockTestObjCLibrary(DynamicLibrary.open(dylib.absolute.path)); @@ -818,8 +830,12 @@ void main() { }); test('Block trampoline args converted to id', () { - final objCBindings = - File('test/native_objc_test/block_bindings.m').readAsStringSync(); + final objCBindings = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'block_bindings.m', + )).readAsStringSync(); // Objects are converted to id. expect(objCBindings, isNot(contains('NSObject'))); diff --git a/pkgs/ffigen/test/native_objc_test/cast_test.dart b/pkgs/ffigen/test/native_objc_test/cast_test.dart index ab0411e251..d45da0369b 100644 --- a/pkgs/ffigen/test/native_objc_test/cast_test.dart +++ b/pkgs/ffigen/test/native_objc_test/cast_test.dart @@ -10,6 +10,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'cast_bindings.dart'; @@ -21,8 +22,19 @@ void main() { group('cast', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); testInstance = Castaway(); diff --git a/pkgs/ffigen/test/native_objc_test/category_test.dart b/pkgs/ffigen/test/native_objc_test/category_test.dart index 04343c16cf..5d80c768ef 100644 --- a/pkgs/ffigen/test/native_objc_test/category_test.dart +++ b/pkgs/ffigen/test/native_objc_test/category_test.dart @@ -9,6 +9,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -19,8 +20,19 @@ void main() { group('categories', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('category'); @@ -81,8 +93,12 @@ void main() { // Don't include transitive category of built-in type that hasn't been // explicitly included. - final bindings = File('test/native_objc_test/category_bindings.dart') - .readAsStringSync(); + final bindings = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'category_bindings.dart', + )).readAsStringSync(); expect(bindings, isNot(contains('excludedExtensionMethod'))); // This method is from an NSObject extension, which shouldn't be included. diff --git a/pkgs/ffigen/test/native_objc_test/deprecated_test.dart b/pkgs/ffigen/test/native_objc_test/deprecated_test.dart index 516e53fcf5..e21b55deb0 100644 --- a/pkgs/ffigen/test/native_objc_test/deprecated_test.dart +++ b/pkgs/ffigen/test/native_objc_test/deprecated_test.dart @@ -13,6 +13,7 @@ import 'package:ffigen/ffigen.dart'; import 'package:ffigen/src/config_provider/config.dart'; import 'package:ffigen/src/config_provider/config_types.dart'; import 'package:logging/logging.dart'; +import 'package:path/path.dart' as path; import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -23,8 +24,20 @@ String bindingsForVersion({Versions? iosVers, Versions? macosVers}) { wrapperName: 'DeprecatedTestObjCLibrary', wrapperDocComment: 'Tests API deprecation', language: Language.objc, - output: Uri.file('test/native_objc_test/deprecated_bindings.dart'), - entryPoints: [Uri.file('test/native_objc_test/deprecated_test.m')], + output: Uri.file(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'deprecated_bindings.dart', + )), + entryPoints: [ + Uri.file(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'deprecated_test.m', + )) + ], formatOutput: false, includeTransitiveObjCCategories: false, objcInterfaces: DeclarationFilters.include( @@ -44,8 +57,12 @@ String bindingsForVersion({Versions? iosVers, Versions? macosVers}) { externalVersions: ExternalVersions(ios: iosVers, macos: macosVers), ); FfiGen(logLevel: Level.SEVERE).run(config); - return File('test/native_objc_test/deprecated_bindings.dart') - .readAsStringSync(); + return File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'deprecated_bindings.dart', + )).readAsStringSync(); } void main() { diff --git a/pkgs/ffigen/test/native_objc_test/forward_decl_test.dart b/pkgs/ffigen/test/native_objc_test/forward_decl_test.dart index 92e55e8ae8..235a1affdd 100644 --- a/pkgs/ffigen/test/native_objc_test/forward_decl_test.dart +++ b/pkgs/ffigen/test/native_objc_test/forward_decl_test.dart @@ -8,6 +8,7 @@ import 'dart:ffi'; import 'dart:io'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'forward_decl_bindings.dart'; @@ -17,8 +18,19 @@ void main() { group('forward decl', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('forward_decl'); diff --git a/pkgs/ffigen/test/native_objc_test/global_native_test.dart b/pkgs/ffigen/test/native_objc_test/global_native_test.dart index 7d90ebd323..76f8e246c5 100644 --- a/pkgs/ffigen/test/native_objc_test/global_native_test.dart +++ b/pkgs/ffigen/test/native_objc_test/global_native_test.dart @@ -9,6 +9,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -19,8 +20,19 @@ void main() { group('global using @Native', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('global'); diff --git a/pkgs/ffigen/test/native_objc_test/global_test.dart b/pkgs/ffigen/test/native_objc_test/global_test.dart index f91f82f4bf..9c996605eb 100644 --- a/pkgs/ffigen/test/native_objc_test/global_test.dart +++ b/pkgs/ffigen/test/native_objc_test/global_test.dart @@ -9,6 +9,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -21,8 +22,19 @@ void main() { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); lib = GlobalTestObjCLibrary(DynamicLibrary.open(dylib.absolute.path)); generateBindingsForCoverage('global'); diff --git a/pkgs/ffigen/test/native_objc_test/inherited_instancetype_test.dart b/pkgs/ffigen/test/native_objc_test/inherited_instancetype_test.dart index cfc3670d53..5326b5ec96 100644 --- a/pkgs/ffigen/test/native_objc_test/inherited_instancetype_test.dart +++ b/pkgs/ffigen/test/native_objc_test/inherited_instancetype_test.dart @@ -10,6 +10,7 @@ import 'dart:ffi'; import 'dart:io'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'inherited_instancetype_bindings.dart'; @@ -19,8 +20,19 @@ void main() { group('inheritedInstancetype', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('inherited_instancetype'); diff --git a/pkgs/ffigen/test/native_objc_test/is_instance_test.dart b/pkgs/ffigen/test/native_objc_test/is_instance_test.dart index d63c6fa51b..ae782f966a 100644 --- a/pkgs/ffigen/test/native_objc_test/is_instance_test.dart +++ b/pkgs/ffigen/test/native_objc_test/is_instance_test.dart @@ -9,6 +9,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -19,8 +20,19 @@ void main() { group('isInstance', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('is_instance'); diff --git a/pkgs/ffigen/test/native_objc_test/isolate_test.dart b/pkgs/ffigen/test/native_objc_test/isolate_test.dart index 26b54d697d..c70942bcd5 100644 --- a/pkgs/ffigen/test/native_objc_test/isolate_test.dart +++ b/pkgs/ffigen/test/native_objc_test/isolate_test.dart @@ -12,6 +12,7 @@ import 'dart:isolate'; import 'package:async/async.dart'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'isolate_bindings.dart'; @@ -21,8 +22,19 @@ void main() { group('isolate', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('isolate'); diff --git a/pkgs/ffigen/test/native_objc_test/log_test.dart b/pkgs/ffigen/test/native_objc_test/log_test.dart index 3411396a36..8495cc123e 100644 --- a/pkgs/ffigen/test/native_objc_test/log_test.dart +++ b/pkgs/ffigen/test/native_objc_test/log_test.dart @@ -9,6 +9,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:logging/logging.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -19,8 +20,19 @@ void main() { group('log_test', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('log'); diff --git a/pkgs/ffigen/test/native_objc_test/method_filtering_test.dart b/pkgs/ffigen/test/native_objc_test/method_filtering_test.dart index 509d81221d..a441bfa6f1 100644 --- a/pkgs/ffigen/test/native_objc_test/method_filtering_test.dart +++ b/pkgs/ffigen/test/native_objc_test/method_filtering_test.dart @@ -13,6 +13,7 @@ import 'package:ffigen/ffigen.dart'; import 'package:ffigen/src/config_provider/config.dart'; import 'package:ffigen/src/config_provider/config_types.dart'; import 'package:logging/logging.dart'; +import 'package:path/path.dart' as path; import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -26,8 +27,12 @@ void main() { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. generateBindingsForCoverage('method_filtering'); - bindings = File('test/native_objc_test/method_filtering_bindings.dart') - .readAsStringSync(); + bindings = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'method_filtering_bindings.dart', + )).readAsStringSync(); }); test('interfaces', () { diff --git a/pkgs/ffigen/test/native_objc_test/method_test.dart b/pkgs/ffigen/test/native_objc_test/method_test.dart index 99dd292f9c..67afb0ccf9 100644 --- a/pkgs/ffigen/test/native_objc_test/method_test.dart +++ b/pkgs/ffigen/test/native_objc_test/method_test.dart @@ -9,6 +9,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:ffi/ffi.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'method_bindings.dart'; @@ -20,8 +21,19 @@ void main() { group('method calls', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); testInstance = MethodInterface(); diff --git a/pkgs/ffigen/test/native_objc_test/native_objc_test.dart b/pkgs/ffigen/test/native_objc_test/native_objc_test.dart index 8a10f4f95d..83e089d601 100644 --- a/pkgs/ffigen/test/native_objc_test/native_objc_test.dart +++ b/pkgs/ffigen/test/native_objc_test/native_objc_test.dart @@ -9,6 +9,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'native_objc_test_bindings.dart'; @@ -18,8 +19,19 @@ void main() { group('native_objc_test', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('native_objc'); diff --git a/pkgs/ffigen/test/native_objc_test/ns_range_test.dart b/pkgs/ffigen/test/native_objc_test/ns_range_test.dart index 64dd0af195..7cc86284af 100644 --- a/pkgs/ffigen/test/native_objc_test/ns_range_test.dart +++ b/pkgs/ffigen/test/native_objc_test/ns_range_test.dart @@ -13,6 +13,7 @@ import 'package:ffigen/ffigen.dart'; import 'package:ffigen/src/config_provider/config.dart'; import 'package:ffigen/src/config_provider/config_types.dart'; import 'package:logging/logging.dart'; +import 'package:path/path.dart' as path; import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -25,14 +26,30 @@ void main() { final config = Config( wrapperName: 'NSRangeTestObjCLibrary', language: Language.objc, - output: Uri.file('test/native_objc_test/ns_range_bindings.dart'), - entryPoints: [Uri.file('test/native_objc_test/ns_range_test.m')], + output: Uri.file(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'ns_range_bindings.dart', + )), + entryPoints: [ + Uri.file(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'ns_range_test.m', + )) + ], formatOutput: false, objcInterfaces: DeclarationFilters.include({'SFTranscriptionSegment'}), ); FfiGen(logLevel: Level.SEVERE).run(config); - bindings = File('test/native_objc_test/ns_range_bindings.dart') - .readAsStringSync(); + bindings = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'ns_range_bindings.dart', + )).readAsStringSync(); }); test('interfaces', () { diff --git a/pkgs/ffigen/test/native_objc_test/nullable_inheritance_test.dart b/pkgs/ffigen/test/native_objc_test/nullable_inheritance_test.dart index c31e30255f..5fa673abaf 100644 --- a/pkgs/ffigen/test/native_objc_test/nullable_inheritance_test.dart +++ b/pkgs/ffigen/test/native_objc_test/nullable_inheritance_test.dart @@ -9,6 +9,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -22,8 +23,19 @@ void main() { group('Nullable inheritance', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); nullableBase = NullableBase(); diff --git a/pkgs/ffigen/test/native_objc_test/nullable_test.dart b/pkgs/ffigen/test/native_objc_test/nullable_test.dart index 10cb91303f..bdda911e86 100644 --- a/pkgs/ffigen/test/native_objc_test/nullable_test.dart +++ b/pkgs/ffigen/test/native_objc_test/nullable_test.dart @@ -9,6 +9,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -21,8 +22,19 @@ void main() { group('Nullability', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); nullableInterface = NullableInterface(); diff --git a/pkgs/ffigen/test/native_objc_test/property_test.dart b/pkgs/ffigen/test/native_objc_test/property_test.dart index 8001d44106..56b654e432 100644 --- a/pkgs/ffigen/test/native_objc_test/property_test.dart +++ b/pkgs/ffigen/test/native_objc_test/property_test.dart @@ -10,6 +10,7 @@ import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'property_bindings.dart'; @@ -21,8 +22,19 @@ void main() { group('properties', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); testInstance = PropertyInterface(); diff --git a/pkgs/ffigen/test/native_objc_test/protocol_test.dart b/pkgs/ffigen/test/native_objc_test/protocol_test.dart index 3cd132b6ff..808c0e4d90 100644 --- a/pkgs/ffigen/test/native_objc_test/protocol_test.dart +++ b/pkgs/ffigen/test/native_objc_test/protocol_test.dart @@ -13,6 +13,7 @@ import 'dart:isolate'; import 'package:ffi/ffi.dart'; import 'package:objective_c/objective_c.dart'; import 'package:objective_c/src/internal.dart' show getProtocol; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -30,8 +31,19 @@ void main() { group('protocol', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); lib = ProtocolTestObjCLibrary(DynamicLibrary.open(dylib.absolute.path)); generateBindingsForCoverage('protocol'); @@ -372,8 +384,12 @@ void main() { // bindings, but there should only be stub bindings for the protocols // themselves, because they're not included by the config. // FilteredUnusedProtocol shouldn't appear at all. - final bindings = File('test/native_objc_test/protocol_bindings.dart') - .readAsStringSync(); + final bindings = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'protocol_bindings.dart', + )).readAsStringSync(); expect(bindings, contains('instanceMethod_withDouble_')); expect(bindings, contains('fooMethod')); diff --git a/pkgs/ffigen/test/native_objc_test/ref_count_test.dart b/pkgs/ffigen/test/native_objc_test/ref_count_test.dart index f2e7dce807..ad78db6d4d 100644 --- a/pkgs/ffigen/test/native_objc_test/ref_count_test.dart +++ b/pkgs/ffigen/test/native_objc_test/ref_count_test.dart @@ -12,6 +12,7 @@ import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'ref_count_bindings.dart'; @@ -23,8 +24,19 @@ void main() { group('Reference counting', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); lib = RefCountTestObjCLibrary(DynamicLibrary.open(dylib.absolute.path)); diff --git a/pkgs/ffigen/test/native_objc_test/rename_test.dart b/pkgs/ffigen/test/native_objc_test/rename_test.dart index 3e777f0767..52a6fc29ab 100644 --- a/pkgs/ffigen/test/native_objc_test/rename_test.dart +++ b/pkgs/ffigen/test/native_objc_test/rename_test.dart @@ -9,6 +9,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'rename_bindings.dart'; @@ -18,8 +19,19 @@ void main() { group('rename_test', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('rename'); diff --git a/pkgs/ffigen/test/native_objc_test/runtime_version_test.dart b/pkgs/ffigen/test/native_objc_test/runtime_version_test.dart index d66e894ada..a89efc4972 100644 --- a/pkgs/ffigen/test/native_objc_test/runtime_version_test.dart +++ b/pkgs/ffigen/test/native_objc_test/runtime_version_test.dart @@ -9,6 +9,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -19,8 +20,19 @@ void main() { group('runtime version check', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('runtime_version'); diff --git a/pkgs/ffigen/test/native_objc_test/sdk_variable_test.dart b/pkgs/ffigen/test/native_objc_test/sdk_variable_test.dart index 32c98d2c1b..70e2451e1d 100644 --- a/pkgs/ffigen/test/native_objc_test/sdk_variable_test.dart +++ b/pkgs/ffigen/test/native_objc_test/sdk_variable_test.dart @@ -8,6 +8,7 @@ import 'dart:ffi'; import 'dart:io'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'util.dart'; @@ -18,13 +19,28 @@ void main() { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('rename'); - bindings = File('test/native_objc_test/sdk_variable_bindings.dart') - .readAsStringSync(); + bindings = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'sdk_variable_bindings.dart', + )).readAsStringSync(); }); test('XCODE', () { diff --git a/pkgs/ffigen/test/native_objc_test/static_func_native_test.dart b/pkgs/ffigen/test/native_objc_test/static_func_native_test.dart index bab81d5cf6..d97ce738b2 100644 --- a/pkgs/ffigen/test/native_objc_test/static_func_native_test.dart +++ b/pkgs/ffigen/test/native_objc_test/static_func_native_test.dart @@ -15,6 +15,7 @@ import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -27,8 +28,19 @@ void main() { group('static functions', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); diff --git a/pkgs/ffigen/test/native_objc_test/static_func_test.dart b/pkgs/ffigen/test/native_objc_test/static_func_test.dart index f4e8e94ab1..8797fbb9bb 100644 --- a/pkgs/ffigen/test/native_objc_test/static_func_test.dart +++ b/pkgs/ffigen/test/native_objc_test/static_func_test.dart @@ -15,6 +15,7 @@ import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -29,8 +30,19 @@ void main() { group('static functions', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); lib = StaticFuncTestObjCLibrary(DynamicLibrary.open(dylib.absolute.path)); diff --git a/pkgs/ffigen/test/native_objc_test/string_test.dart b/pkgs/ffigen/test/native_objc_test/string_test.dart index 002f8511b3..b692e51be5 100644 --- a/pkgs/ffigen/test/native_objc_test/string_test.dart +++ b/pkgs/ffigen/test/native_objc_test/string_test.dart @@ -9,6 +9,7 @@ import 'dart:ffi'; import 'dart:io'; import 'package:objective_c/objective_c.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -19,8 +20,19 @@ void main() { group('string', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('string'); diff --git a/pkgs/ffigen/test/native_objc_test/swift_class_test.dart b/pkgs/ffigen/test/native_objc_test/swift_class_test.dart index 0a7c3180af..8a96a20ab1 100644 --- a/pkgs/ffigen/test/native_objc_test/swift_class_test.dart +++ b/pkgs/ffigen/test/native_objc_test/swift_class_test.dart @@ -8,6 +8,7 @@ import 'dart:ffi'; import 'dart:io'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'swift_class_bindings.dart'; @@ -17,8 +18,19 @@ void main() { group('swift_class_test', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/swift_class_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'swift_class_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('swift_class'); diff --git a/pkgs/ffigen/test/native_objc_test/transitive_test.dart b/pkgs/ffigen/test/native_objc_test/transitive_test.dart index 62f7738ce5..5a19b124da 100644 --- a/pkgs/ffigen/test/native_objc_test/transitive_test.dart +++ b/pkgs/ffigen/test/native_objc_test/transitive_test.dart @@ -13,6 +13,7 @@ import 'package:ffigen/ffigen.dart'; import 'package:ffigen/src/config_provider/config.dart'; import 'package:ffigen/src/config_provider/config_types.dart'; import 'package:logging/logging.dart'; +import 'package:path/path.dart' as path; import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; import '../test_utils.dart'; @@ -27,8 +28,20 @@ String generate({ wrapperName: 'TransitiveTestObjCLibrary', wrapperDocComment: 'Tests transitive inclusion', language: Language.objc, - output: Uri.file('test/native_objc_test/transitive_bindings.dart'), - entryPoints: [Uri.file('test/native_objc_test/transitive_test.h')], + output: Uri.file(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'transitive_bindings.dart', + )), + entryPoints: [ + Uri.file(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'transitive_test.h', + )) + ], formatOutput: false, objcInterfaces: DeclarationFilters.include({ 'DirectlyIncluded', @@ -42,8 +55,12 @@ String generate({ includeTransitiveObjCCategories: includeTransitiveObjCCategories, ); FfiGen(logLevel: Level.SEVERE).run(config); - return File('test/native_objc_test/transitive_bindings.dart') - .readAsStringSync(); + return File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'transitive_bindings.dart', + )).readAsStringSync(); } enum Inclusion { omitted, stubbed, included } diff --git a/pkgs/ffigen/test/native_objc_test/typedef_test.dart b/pkgs/ffigen/test/native_objc_test/typedef_test.dart index 9268329130..2c48af9c12 100644 --- a/pkgs/ffigen/test/native_objc_test/typedef_test.dart +++ b/pkgs/ffigen/test/native_objc_test/typedef_test.dart @@ -8,6 +8,7 @@ import 'dart:ffi'; import 'dart:io'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../test_utils.dart'; import 'typedef_bindings.dart'; @@ -17,8 +18,19 @@ void main() { group('typedef', () { setUpAll(() { // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. - DynamicLibrary.open('../objective_c/test/objective_c.dylib'); - final dylib = File('test/native_objc_test/objc_test.dylib'); + DynamicLibrary.open(path.join( + packagePathForTests, + '..', + 'objective_c', + 'test', + 'objective_c.dylib', + )); + final dylib = File(path.join( + packagePathForTests, + 'test', + 'native_objc_test', + 'objc_test.dylib', + )); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); generateBindingsForCoverage('typedef'); diff --git a/pkgs/ffigen/test/native_objc_test/util.dart b/pkgs/ffigen/test/native_objc_test/util.dart index 4fef206b35..58d8d3b45a 100644 --- a/pkgs/ffigen/test/native_objc_test/util.dart +++ b/pkgs/ffigen/test/native_objc_test/util.dart @@ -21,7 +21,12 @@ void generateBindingsForCoverage(String testName) { // that the ObjC related bits of ffigen are missed by test coverage. So this // function just regenerates those bindings. It doesn't test anything except // that the generation succeeded, by asserting the file exists. - final path = p.join('test', 'native_objc_test', '${testName}_config.yaml'); + final path = p.join( + packagePathForTests, + 'test', + 'native_objc_test', + '${testName}_config.yaml', + ); final config = testConfig(File(path).readAsStringSync(), filename: path); FfiGen(logLevel: Level.SEVERE).run(config); } diff --git a/pkgs/ffigen/test/native_test/native_test.dart b/pkgs/ffigen/test/native_test/native_test.dart index db282408a5..8a9d104fe7 100644 --- a/pkgs/ffigen/test/native_test/native_test.dart +++ b/pkgs/ffigen/test/native_test/native_test.dart @@ -24,17 +24,25 @@ void main() { } else if (Platform.isWindows) { dylibName = r'test\native_test\native_test.dll'; } - final dylib = File(dylibName); + final dylib = File(path.join(packagePathForTests, dylibName)); verifySetupFile(dylib); bindings = NativeLibrary(DynamicLibrary.open(dylib.absolute.path)); }); test('generate_bindings', () { - final configFile = - File(path.join('test', 'native_test', 'config.yaml')).absolute; + final configFile = File(path.join( + packagePathForTests, + 'test', + 'native_test', + 'config.yaml', + )).absolute; final outFile = File( path.join( - 'test', 'debug_generated', '_expected_native_test_bindings.dart'), + packagePathForTests, + 'test', + 'debug_generated', + '_expected_native_test_bindings.dart', + ), ).absolute; late Config config; diff --git a/pkgs/ffigen/test/regen.dart b/pkgs/ffigen/test/regen.dart index a25e68a6c3..868a3d71aa 100644 --- a/pkgs/ffigen/test/regen.dart +++ b/pkgs/ffigen/test/regen.dart @@ -8,6 +8,7 @@ import 'dart:io'; import 'package:args/args.dart'; import 'package:ffigen/ffigen.dart'; import 'package:logging/logging.dart'; +import 'package:path/path.dart' as p; import 'test_utils.dart'; const usage = r'''Regenerates the Dart FFI bindings used in tests and examples. @@ -19,9 +20,9 @@ $ dart run test/setup.dart && dart run test/regen.dart && dart test '''; void _regenConfig(FfiGen ffigen, String yamlConfigPath) { - final yamlConfig = File(yamlConfigPath).absolute; - withChDir(yamlConfig.path, () { - final config = testConfigFromPath(yamlConfig.path); + final path = p.join(packagePathForTests, yamlConfigPath); + withChDir(path, () { + final config = testConfigFromPath(path); ffigen.run(config); }); } diff --git a/pkgs/ffigen/test/test_utils.dart b/pkgs/ffigen/test/test_utils.dart index 1616f95cd1..ac88d08985 100644 --- a/pkgs/ffigen/test/test_utils.dart +++ b/pkgs/ffigen/test/test_utils.dart @@ -15,6 +15,8 @@ import 'package:path/path.dart' as path; import 'package:test/test.dart'; import 'package:yaml/yaml.dart' as yaml; +export 'package:ffigen/src/config_provider/utils.dart'; + extension LibraryTestExt on Library { /// Get a [Binding]'s generated string with a given name. String getBindingAsString(String name) => diff --git a/pkgs/swift2objc/lib/src/config.dart b/pkgs/swift2objc/lib/src/config.dart index ef0bb26159..c873e7386f 100644 --- a/pkgs/swift2objc/lib/src/config.dart +++ b/pkgs/swift2objc/lib/src/config.dart @@ -9,10 +9,7 @@ class Command { final String executable; final List args; - Command({ - required this.executable, - required this.args, - }); + Command({required this.executable, required this.args}); } /// Used to configure Swift2ObjC wrapper generation. @@ -43,12 +40,13 @@ class Config { static bool _defaultInclude(Declaration _) => true; - const Config( - {required this.input, - required this.outputFile, - this.tempDir, - this.preamble, - this.include = Config._defaultInclude}); + const Config({ + required this.input, + required this.outputFile, + this.tempDir, + this.preamble, + this.include = Config._defaultInclude, + }); } /// Used to specify the inputs in the `config` object. @@ -72,17 +70,17 @@ class FilesInputConfig implements InputConfig { @override Command? get symbolgraphCommand => Command( - executable: 'swiftc', - args: [ - ...files.map((uri) => path.absolute(uri.path)), - '-emit-module', - '-emit-symbol-graph', - '-emit-symbol-graph-dir', - '.', - '-module-name', - generatedModuleName - ], - ); + executable: 'swiftc', + args: [ + ...files.map((uri) => path.absolute(uri.path)), + '-emit-module', + '-emit-symbol-graph', + '-emit-symbol-graph-dir', + '.', + '-module-name', + generatedModuleName, + ], + ); } /// Used to generate a objc wrapper for a built-in swift module. @@ -107,19 +105,19 @@ class ModuleInputConfig implements InputConfig { @override Command? get symbolgraphCommand => Command( - executable: 'swift', - args: [ - 'symbolgraph-extract', - '-module-name', - module, - '-target', - target, - '-sdk', - path.absolute(sdk.path), - '-output-dir', - '.', - ], - ); + executable: 'swift', + args: [ + 'symbolgraph-extract', + '-module-name', + module, + '-target', + target, + '-sdk', + path.absolute(sdk.path), + '-output-dir', + '.', + ], + ); } /// Used to generate wrappers directly from a JSON symbolgraph, for debugging. diff --git a/pkgs/swift2objc/test/integration/integration_test.dart b/pkgs/swift2objc/test/integration/integration_test.dart index 7db86918d8..7e95a3d386 100644 --- a/pkgs/swift2objc/test/integration/integration_test.dart +++ b/pkgs/swift2objc/test/integration/integration_test.dart @@ -39,8 +39,9 @@ void main([List? args]) { for (final entity in Directory(thisDir).listSync()) { final filename = path.basename(entity.path); if (filename.endsWith(inputSuffix)) { - testNames - .add(filename.substring(0, filename.length - inputSuffix.length)); + testNames.add( + filename.substring(0, filename.length - inputSuffix.length), + ); } } } @@ -61,14 +62,14 @@ void main([List? args]) { ? expectedOutputFile : path.join(tempDir, '$name$outputSuffix'); - await generateWrapper(Config( - input: FilesInputConfig( - files: [Uri.file(inputFile)], + await generateWrapper( + Config( + input: FilesInputConfig(files: [Uri.file(inputFile)]), + outputFile: Uri.file(actualOutputFile), + tempDir: Directory(tempDir).uri, + preamble: '// Test preamble text', ), - outputFile: Uri.file(actualOutputFile), - tempDir: Directory(tempDir).uri, - preamble: '// Test preamble text', - )); + ); final actualOutput = await File(actualOutputFile).readAsString(); final expectedOutput = File(expectedOutputFile).readAsStringSync(); @@ -80,10 +81,7 @@ void main([List? args]) { // to make sure the result compiles. Input file must be included cause // it contains the definition of the entities the output code wraps. final symbolgraphCommand = FilesInputConfig( - files: [ - Uri.file(inputFile), - Uri.file(actualOutputFile), - ], + files: [Uri.file(inputFile), Uri.file(actualOutputFile)], generatedModuleName: 'output_file_symbolgraph', ).symbolgraphCommand!; diff --git a/pkgs/swift2objc/test/unit/filter_test.dart b/pkgs/swift2objc/test/unit/filter_test.dart index 6b47994b46..5fc4b06371 100644 --- a/pkgs/swift2objc/test/unit/filter_test.dart +++ b/pkgs/swift2objc/test/unit/filter_test.dart @@ -18,18 +18,20 @@ void main() { final file = p.join(thisDir, 'filter_test_input.swift'); test('A: Specific Files', () async { final output = p.join(thisDir, 'filter_test_output_a.swift'); - final actualOutputFile = p.join(thisDir, - '${p.basenameWithoutExtension(output)}.test${p.extension(output)}'); - - await generateWrapper(Config( - input: FilesInputConfig( - files: [Uri.file(file)], + final actualOutputFile = p.join( + thisDir, + '${p.basenameWithoutExtension(output)}.test${p.extension(output)}', + ); + + await generateWrapper( + Config( + input: FilesInputConfig(files: [Uri.file(file)]), + outputFile: Uri.file(actualOutputFile), + tempDir: Directory(thisDir).uri, + preamble: '// Test preamble text', + include: (declaration) => declaration.name == 'Engine', ), - outputFile: Uri.file(actualOutputFile), - tempDir: Directory(thisDir).uri, - preamble: '// Test preamble text', - include: (declaration) => declaration.name == 'Engine', - )); + ); final actualOutput = await File(actualOutputFile).readAsString(); final expectedOutput = File(output).readAsStringSync(); @@ -39,18 +41,20 @@ void main() { test('B: Declarations of a specific type', () async { final output = p.join(thisDir, 'filter_test_output_b.swift'); - final actualOutputFile = p.join(thisDir, - '${p.basenameWithoutExtension(output)}.test${p.extension(output)}'); - - await generateWrapper(Config( - input: FilesInputConfig( - files: [Uri.file(file)], + final actualOutputFile = p.join( + thisDir, + '${p.basenameWithoutExtension(output)}.test${p.extension(output)}', + ); + + await generateWrapper( + Config( + input: FilesInputConfig(files: [Uri.file(file)]), + outputFile: Uri.file(actualOutputFile), + tempDir: Directory(thisDir).uri, + preamble: '// Test preamble text', + include: (declaration) => declaration is ClassDeclaration, ), - outputFile: Uri.file(actualOutputFile), - tempDir: Directory(thisDir).uri, - preamble: '// Test preamble text', - include: (declaration) => declaration is ClassDeclaration, - )); + ); final actualOutput = await File(actualOutputFile).readAsString(); final expectedOutput = File(output).readAsStringSync(); @@ -60,20 +64,22 @@ void main() { test('C: Nonexistent declaration', () async { final output = p.join(thisDir, 'filter_test_output_c.swift'); - final actualOutputFile = p.join(thisDir, - '${p.basenameWithoutExtension(output)}.test${p.extension(output)}'); - - await generateWrapper(Config( - input: FilesInputConfig( - files: [Uri.file(file)], + final actualOutputFile = p.join( + thisDir, + '${p.basenameWithoutExtension(output)}.test${p.extension(output)}', + ); + + await generateWrapper( + Config( + input: FilesInputConfig(files: [Uri.file(file)]), + outputFile: Uri.file(actualOutputFile), + tempDir: Directory(thisDir).uri, + preamble: '// Test preamble text', + // The following declaration does not exist, + // so none are produced in output + include: (declaration) => declaration.name == 'Ship', ), - outputFile: Uri.file(actualOutputFile), - tempDir: Directory(thisDir).uri, - preamble: '// Test preamble text', - // The following declaration does not exist, - // so none are produced in output - include: (declaration) => declaration.name == 'Ship', - )); + ); final actualOutput = await File(actualOutputFile).readAsString(); final expectedOutput = File(output).readAsStringSync(); @@ -88,27 +94,32 @@ void main() { if (File(p.join(thisDir, 'symbolgraph_module.swiftdoc')).existsSync()) { File(p.join(thisDir, 'symbolgraph_module.swiftdoc')).deleteSync(); } - if (File(p.join(thisDir, 'symbolgraph_module.swiftmodule')) - .existsSync()) { + if (File( + p.join(thisDir, 'symbolgraph_module.swiftmodule'), + ).existsSync()) { File(p.join(thisDir, 'symbolgraph_module.swiftmodule')).deleteSync(); } - if (File(p.join(thisDir, 'symbolgraph_module.swiftsource')) - .existsSync()) { + if (File( + p.join(thisDir, 'symbolgraph_module.swiftsource'), + ).existsSync()) { File(p.join(thisDir, 'symbolgraph_module.swiftsource')).deleteSync(); } - if (File(p.join(thisDir, 'symbolgraph_module.symbols.json')) - .existsSync()) { + if (File( + p.join(thisDir, 'symbolgraph_module.symbols.json'), + ).existsSync()) { File(p.join(thisDir, 'symbolgraph_module.symbols.json')).deleteSync(); } - if (File(p.join(thisDir, 'symbolgraph_module.swiftsourceinfo')) - .existsSync()) { - File(p.join(thisDir, 'symbolgraph_module.swiftsourceinfo')) - .deleteSync(); + if (File( + p.join(thisDir, 'symbolgraph_module.swiftsourceinfo'), + ).existsSync()) { + File( + p.join(thisDir, 'symbolgraph_module.swiftsourceinfo'), + ).deleteSync(); } - for (final file in Directory(thisDir) - .listSync() - .where((t) => p.extension(t.path, 2) == '.test.swift')) { + for (final file in Directory( + thisDir, + ).listSync().where((t) => p.extension(t.path, 2) == '.test.swift')) { if (file is File) file.deleteSync(); } }); diff --git a/pkgs/swift2objc/test/utils.dart b/pkgs/swift2objc/test/utils.dart index f18f25e2db..a4ed998109 100644 --- a/pkgs/swift2objc/test/utils.dart +++ b/pkgs/swift2objc/test/utils.dart @@ -12,10 +12,13 @@ void expectString(String a, String b) { expect(trimmedA, trimmedB); } -String testDir = p.normalize(p.join( +String testDir = p.normalize( + p.join( Isolate.resolvePackageUriSync( - Uri.parse('package:swift2objc/swift2objc.dart'))! - .toFilePath(), + Uri.parse('package:swift2objc/swift2objc.dart'), + )!.toFilePath(), '..', '..', - 'test')); + 'test', + ), +); From 1794397245b4a4feb2db378862a9a3c8f79f7e91 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Wed, 28 May 2025 10:53:51 +1000 Subject: [PATCH 12/15] fmt --- pkgs/swift2objc/lib/src/config.dart | 66 +++++++++++++++-------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/pkgs/swift2objc/lib/src/config.dart b/pkgs/swift2objc/lib/src/config.dart index c873e7386f..ef0bb26159 100644 --- a/pkgs/swift2objc/lib/src/config.dart +++ b/pkgs/swift2objc/lib/src/config.dart @@ -9,7 +9,10 @@ class Command { final String executable; final List args; - Command({required this.executable, required this.args}); + Command({ + required this.executable, + required this.args, + }); } /// Used to configure Swift2ObjC wrapper generation. @@ -40,13 +43,12 @@ class Config { static bool _defaultInclude(Declaration _) => true; - const Config({ - required this.input, - required this.outputFile, - this.tempDir, - this.preamble, - this.include = Config._defaultInclude, - }); + const Config( + {required this.input, + required this.outputFile, + this.tempDir, + this.preamble, + this.include = Config._defaultInclude}); } /// Used to specify the inputs in the `config` object. @@ -70,17 +72,17 @@ class FilesInputConfig implements InputConfig { @override Command? get symbolgraphCommand => Command( - executable: 'swiftc', - args: [ - ...files.map((uri) => path.absolute(uri.path)), - '-emit-module', - '-emit-symbol-graph', - '-emit-symbol-graph-dir', - '.', - '-module-name', - generatedModuleName, - ], - ); + executable: 'swiftc', + args: [ + ...files.map((uri) => path.absolute(uri.path)), + '-emit-module', + '-emit-symbol-graph', + '-emit-symbol-graph-dir', + '.', + '-module-name', + generatedModuleName + ], + ); } /// Used to generate a objc wrapper for a built-in swift module. @@ -105,19 +107,19 @@ class ModuleInputConfig implements InputConfig { @override Command? get symbolgraphCommand => Command( - executable: 'swift', - args: [ - 'symbolgraph-extract', - '-module-name', - module, - '-target', - target, - '-sdk', - path.absolute(sdk.path), - '-output-dir', - '.', - ], - ); + executable: 'swift', + args: [ + 'symbolgraph-extract', + '-module-name', + module, + '-target', + target, + '-sdk', + path.absolute(sdk.path), + '-output-dir', + '.', + ], + ); } /// Used to generate wrappers directly from a JSON symbolgraph, for debugging. From 13737ef7f04fde15e8a71c017c8a41dab37e4715 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Wed, 28 May 2025 11:19:41 +1000 Subject: [PATCH 13/15] Avoid Isolate.resolvePackageUriSync as it's not available in flutter --- .../config_provider/overrideable_utils.dart | 56 +++++++++++++++-- pkgs/objective_c/test/util.dart | 59 +++++++++++++++--- pkgs/swift2objc/test/utils.dart | 62 +++++++++++++++++-- 3 files changed, 159 insertions(+), 18 deletions(-) diff --git a/pkgs/ffigen/lib/src/config_provider/overrideable_utils.dart b/pkgs/ffigen/lib/src/config_provider/overrideable_utils.dart index 26b5a511d3..8d94de037d 100644 --- a/pkgs/ffigen/lib/src/config_provider/overrideable_utils.dart +++ b/pkgs/ffigen/lib/src/config_provider/overrideable_utils.dart @@ -42,12 +42,58 @@ final libclangOverridePaths = const []; /// Returns the root path of the package, for use during tests. /// /// Note that `dart test` sets the current directory to the package root. -final packagePathForTests = p.normalize(p.join( - Isolate.resolvePackageUriSync(Uri.parse('package:ffigen/ffigen.dart'))! - .toFilePath(), - '..', - '..')); +final packagePathForTests = _findPackageRoot('ffigen').toFilePath(); /// Returns a path to a config yaml in a unit test. String configPathForTest(String directory, String file) => p.join(directory, file); + +/// Test files are run in a variety of ways, find this package root in all. +/// +/// Test files can be run from source from any working directory. The Dart SDK +/// `tools/test.py` runs them from the root of the SDK for example. +/// +/// Test files can be run from dill from the root of package. `package:test` +/// does this. +/// +/// https://github.com/dart-lang/test/issues/110 +Uri _findPackageRoot(String packageName) { + final script = Platform.script; + final fileName = script.name; + if (fileName.endsWith('.dart')) { + // We're likely running from source in the package somewhere. + var directory = script.resolve('.'); + while (true) { + final dirName = directory.name; + if (dirName == packageName) { + return directory; + } + final parent = directory.resolve('..'); + if (parent == directory) break; + directory = parent; + } + } else if (fileName.endsWith('.dill')) { + // Probably from the package root. + final cwd = Directory.current.uri; + final dirName = cwd.name; + if (dirName == packageName) { + return cwd; + } + } + // Or the workspace root. + final cwd = Directory.current.uri; + final candidate = cwd.resolve('pkgs/$packageName/'); + if (Directory.fromUri(candidate).existsSync()) { + return candidate; + } + throw StateError( + "Could not find package root for package '$packageName'. " + 'Tried finding the package root via Platform.script ' + "'${Platform.script.toFilePath()}' and Directory.current " + "'${Directory.current.uri.toFilePath()}'.", + ); +} + +extension on Uri { + String get name => pathSegments.where((e) => e != '').last; +} diff --git a/pkgs/objective_c/test/util.dart b/pkgs/objective_c/test/util.dart index 1c0fabbad9..884c44a0de 100644 --- a/pkgs/objective_c/test/util.dart +++ b/pkgs/objective_c/test/util.dart @@ -8,7 +8,7 @@ // ignore_for_file: avoid_catching_errors import 'dart:ffi'; -import 'dart:isolate'; +import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:objective_c/objective_c.dart'; @@ -66,12 +66,57 @@ int objectRetainCount(Pointer object) { return _getObjectRetainCount(object.cast()); } -String pkgDir = p.normalize(p.join( - Isolate.resolvePackageUriSync( - Uri.parse('package:objective_c/objective_c.dart'))! - .toFilePath(), - '..', - '..')); +String pkgDir = findPackageRoot('objective_c').toFilePath(); // TODO(https://github.com/dart-lang/native/issues/1068): Remove this. String testDylib = p.join(pkgDir, 'test', 'objective_c.dylib'); + +/// Test files are run in a variety of ways, find this package root in all. +/// +/// Test files can be run from source from any working directory. The Dart SDK +/// `tools/test.py` runs them from the root of the SDK for example. +/// +/// Test files can be run from dill from the root of package. `package:test` +/// does this. +/// +/// https://github.com/dart-lang/test/issues/110 +Uri findPackageRoot(String packageName) { + final script = Platform.script; + final fileName = script.name; + if (fileName.endsWith('.dart')) { + // We're likely running from source in the package somewhere. + var directory = script.resolve('.'); + while (true) { + final dirName = directory.name; + if (dirName == packageName) { + return directory; + } + final parent = directory.resolve('..'); + if (parent == directory) break; + directory = parent; + } + } else if (fileName.endsWith('.dill')) { + // Probably from the package root. + final cwd = Directory.current.uri; + final dirName = cwd.name; + if (dirName == packageName) { + return cwd; + } + } + // Or the workspace root. + final cwd = Directory.current.uri; + final candidate = cwd.resolve('pkgs/$packageName/'); + if (Directory.fromUri(candidate).existsSync()) { + return candidate; + } + throw StateError( + "Could not find package root for package '$packageName'. " + 'Tried finding the package root via Platform.script ' + "'${Platform.script.toFilePath()}' and Directory.current " + "'${Directory.current.uri.toFilePath()}'.", + ); +} + +extension on Uri { + String get name => pathSegments.where((e) => e != '').last; +} diff --git a/pkgs/swift2objc/test/utils.dart b/pkgs/swift2objc/test/utils.dart index a4ed998109..50e58c45f4 100644 --- a/pkgs/swift2objc/test/utils.dart +++ b/pkgs/swift2objc/test/utils.dart @@ -1,4 +1,8 @@ -import 'dart:isolate'; +// 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:path/path.dart' as p; import 'package:test/test.dart'; @@ -14,11 +18,57 @@ void expectString(String a, String b) { String testDir = p.normalize( p.join( - Isolate.resolvePackageUriSync( - Uri.parse('package:swift2objc/swift2objc.dart'), - )!.toFilePath(), - '..', - '..', + findPackageRoot('swift2objc').toFilePath(), 'test', ), ); + +/// Test files are run in a variety of ways, find this package root in all. +/// +/// Test files can be run from source from any working directory. The Dart SDK +/// `tools/test.py` runs them from the root of the SDK for example. +/// +/// Test files can be run from dill from the root of package. `package:test` +/// does this. +/// +/// https://github.com/dart-lang/test/issues/110 +Uri findPackageRoot(String packageName) { + final script = Platform.script; + final fileName = script.name; + if (fileName.endsWith('.dart')) { + // We're likely running from source in the package somewhere. + var directory = script.resolve('.'); + while (true) { + final dirName = directory.name; + if (dirName == packageName) { + return directory; + } + final parent = directory.resolve('..'); + if (parent == directory) break; + directory = parent; + } + } else if (fileName.endsWith('.dill')) { + // Probably from the package root. + final cwd = Directory.current.uri; + final dirName = cwd.name; + if (dirName == packageName) { + return cwd; + } + } + // Or the workspace root. + final cwd = Directory.current.uri; + final candidate = cwd.resolve('pkgs/$packageName/'); + if (Directory.fromUri(candidate).existsSync()) { + return candidate; + } + throw StateError( + "Could not find package root for package '$packageName'. " + 'Tried finding the package root via Platform.script ' + "'${Platform.script.toFilePath()}' and Directory.current " + "'${Directory.current.uri.toFilePath()}'.", + ); +} + +extension on Uri { + String get name => pathSegments.where((e) => e != '').last; +} From 56e08cd6bb788ad21dcab549b42a4ca3fb5d4f31 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Wed, 28 May 2025 11:28:35 +1000 Subject: [PATCH 14/15] Fix analysis --- .github/workflows/native.yaml | 1 + pkgs/ffigen/lib/src/config_provider/overrideable_utils.dart | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/native.yaml b/.github/workflows/native.yaml index 65f01cbb15..33ad42f5e1 100644 --- a/.github/workflows/native.yaml +++ b/.github/workflows/native.yaml @@ -1,6 +1,7 @@ # CI for the native_* packages. # # Combined into a single workflow so that deps are configured and installed once. + name: native permissions: read-all diff --git a/pkgs/ffigen/lib/src/config_provider/overrideable_utils.dart b/pkgs/ffigen/lib/src/config_provider/overrideable_utils.dart index 8d94de037d..8ff091e7fc 100644 --- a/pkgs/ffigen/lib/src/config_provider/overrideable_utils.dart +++ b/pkgs/ffigen/lib/src/config_provider/overrideable_utils.dart @@ -11,7 +11,6 @@ library; import 'dart:io'; -import 'dart:isolate'; import 'package:path/path.dart' as p; From 922ef6702ec92a69cb0457f0880ee5ec00980070 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Wed, 28 May 2025 13:20:50 +1000 Subject: [PATCH 15/15] Fix json_schema_test --- .../test/config_tests/json_schema_test.dart | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/pkgs/ffigen/test/config_tests/json_schema_test.dart b/pkgs/ffigen/test/config_tests/json_schema_test.dart index 65f69a5180..7111703670 100644 --- a/pkgs/ffigen/test/config_tests/json_schema_test.dart +++ b/pkgs/ffigen/test/config_tests/json_schema_test.dart @@ -40,25 +40,17 @@ void main() { }); // Find all ffigen config files in the repo. - final configYamlGlob = Glob(path.join( - packagePathForTests, - '**config.yaml', - )); - final configYamlFiles = - configYamlGlob.listFileSystemSync(const LocalFileSystem()); + final configYamlGlob = Glob('**config.yaml'); + final configYamlFiles = configYamlGlob + .listFileSystemSync(const LocalFileSystem(), root: packagePathForTests); test('$configYamlGlob files not empty', () { expect(configYamlFiles.isNotEmpty, true); }); - final sharedBindingsConfigYamlGlob = Glob(path.join( - packagePathForTests, - 'example', - 'shared_bindings', - 'ffigen_configs', - '**.yaml', - )); + final sharedBindingsConfigYamlGlob = + Glob('example/shared_bindings/ffigen_configs/**.yaml'); final sharedBindingsConfigYamlFiles = sharedBindingsConfigYamlGlob - .listFileSystemSync(const LocalFileSystem()); + .listFileSystemSync(const LocalFileSystem(), root: packagePathForTests); test('$sharedBindingsConfigYamlGlob files not emty', () { expect(sharedBindingsConfigYamlFiles.isNotEmpty, true); });