Skip to content

Commit

Permalink
Try again
Browse files Browse the repository at this point in the history
  • Loading branch information
liamappelbe committed Dec 19, 2024
1 parent 04cf6d4 commit e10f412
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 154 deletions.
218 changes: 108 additions & 110 deletions .github/workflows/ffigen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,52 @@ env:

jobs:
# Check code formatting and static analysis on a single OS (macos).
analyze:
runs-on: macos-latest
defaults:
run:
working-directory: pkgs/ffigen/
strategy:
fail-fast: false
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: subosito/flutter-action@74af56c5ed2697ba4621264652728e8d217e53d3
with:
channel: 'stable'
- id: install
name: Install dependencies
run: flutter pub get && flutter pub get --directory="example/shared_bindings" && flutter pub get --directory="../objective_c"
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Build test dylib and bindings
run: dart test/setup.dart
- name: Analyze code
run: flutter analyze --fatal-infos
# analyze:
# runs-on: macos-latest
# defaults:
# run:
# working-directory: pkgs/ffigen/
# strategy:
# fail-fast: false
# steps:
# - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
# - uses: subosito/flutter-action@74af56c5ed2697ba4621264652728e8d217e53d3
# with:
# channel: 'stable'
# - id: install
# name: Install dependencies
# run: flutter pub get && flutter pub get --directory="example/shared_bindings" && flutter pub get --directory="../objective_c"
# - name: Check formatting
# run: dart format --output=none --set-exit-if-changed .
# if: always() && steps.install.outcome == 'success'
# - name: Build test dylib and bindings
# run: dart test/setup.dart
# - name: Analyze code
# run: flutter analyze --fatal-infos

test-linux:
needs: analyze
runs-on: ubuntu-22.04
defaults:
run:
working-directory: pkgs/ffigen/
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: subosito/flutter-action@74af56c5ed2697ba4621264652728e8d217e53d3
with:
channel: 'stable'
- name: Install dependencies
run: flutter pub get
- name: Install libclang-14-dev
run: sudo apt-get install libclang-14-dev
- name: Build test dylib and bindings
run: dart test/setup.dart
- name: Run VM tests
run: dart test
# test-linux:
# needs: analyze
# runs-on: ubuntu-22.04
# defaults:
# run:
# working-directory: pkgs/ffigen/
# steps:
# - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
# - uses: subosito/flutter-action@74af56c5ed2697ba4621264652728e8d217e53d3
# with:
# channel: 'stable'
# - name: Install dependencies
# run: flutter pub get
# - name: Install libclang-14-dev
# run: sudo apt-get install libclang-14-dev
# - name: Build test dylib and bindings
# run: dart test/setup.dart
# - name: Run VM tests
# run: dart test

# Keep in sync with ffigen_weekly.yaml:test-mac-arm64
test-mac:
needs: analyze
# needs: analyze
runs-on: 'macos-latest'
defaults:
run:
Expand All @@ -80,59 +80,57 @@ jobs:
channel: 'stable'
- name: Install dependencies
run: flutter pub get && flutter pub get --directory="../objective_c"
- name: Build test dylib and bindings
run: dart test/setup.dart
- name: Run VM tests and collect coverage
run: dart run coverage:test_with_coverage --scope-output=ffigen --scope-output=objective_c
- name: Upload coverage
uses: coverallsapp/github-action@cfd0633edbd2411b532b808ba7a8b5e04f76d2c8
with:
flag-name: ffigen
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel: true
path-to-lcov: pkgs/ffigen/coverage/lcov.info
- name: Upload coverage
uses: coverallsapp/github-action@cfd0633edbd2411b532b808ba7a8b5e04f76d2c8
with:
carryforward: "ffigen,jni,jnigen,native_assets_builder_macos,native_assets_builder_ubuntu,native_assets_builder_windows,native_assets_cli_macos,native_assets_cli_ubuntu,native_assets_cli_windows,native_toolchain_c_macos,native_toolchain_c_ubuntu,native_toolchain_c_windows,objective_c,swift2objc"
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
- name: Run VM tests
run: fail_count=0; for i in {1..10}; do (dart test/setup.dart && dart test) || ((fail_count++)); done; if ((fail_count > 0)); then echo "There were $fail_count failures"; exit 1; fi
# - name: Upload coverage
# uses: coverallsapp/github-action@643bc377ffa44ace6394b2b5d0d3950076de9f63
# with:
# flag-name: ffigen
# github-token: ${{ secrets.GITHUB_TOKEN }}
# parallel: true
# path-to-lcov: pkgs/ffigen/coverage/lcov.info
# - name: Upload coverage
# uses: coverallsapp/github-action@643bc377ffa44ace6394b2b5d0d3950076de9f63
# with:
# carryforward: "ffigen,jni,jnigen,native_assets_builder_macos,native_assets_builder_ubuntu,native_assets_builder_windows,native_assets_cli_macos,native_assets_cli_ubuntu,native_assets_cli_windows,native_toolchain_c_macos,native_toolchain_c_ubuntu,native_toolchain_c_windows,objective_c,swift2objc"
# github-token: ${{ secrets.GITHUB_TOKEN }}
# parallel-finished: true

test-mac-flutter:
needs: analyze
runs-on: 'macos-latest'
defaults:
run:
working-directory: pkgs/ffigen/
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: subosito/flutter-action@74af56c5ed2697ba4621264652728e8d217e53d3
with:
channel: 'stable'
- name: Install dependencies
run: flutter pub get && flutter pub get --directory="../objective_c"
- name: Build test dylib and bindings
run: dart test/setup.dart --main-thread-dispatcher
- name: Run Flutter tests
run: flutter test
# test-mac-flutter:
# needs: analyze
# runs-on: 'macos-latest'
# defaults:
# run:
# working-directory: pkgs/ffigen/
# steps:
# - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
# - uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
# with:
# channel: 'stable'
# - name: Install dependencies
# run: flutter pub get && flutter pub get --directory="../objective_c"
# - name: Build test dylib and bindings
# run: dart test/setup.dart --main-thread-dispatcher
# - name: Run Flutter tests
# run: flutter test

test-windows:
needs: analyze
runs-on: windows-latest
defaults:
run:
working-directory: pkgs/ffigen/
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: subosito/flutter-action@74af56c5ed2697ba4621264652728e8d217e53d3
with:
channel: 'stable'
- name: Install dependencies
run: flutter pub get
- name: Build test dylib and bindings
run: dart test/setup.dart
- name: Run VM tests
run: dart test
# test-windows:
# needs: analyze
# runs-on: windows-latest
# defaults:
# run:
# working-directory: pkgs/ffigen/
# steps:
# - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
# - uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
# with:
# channel: 'stable'
# - name: Install dependencies
# run: flutter pub get
# - name: Build test dylib and bindings
# run: dart test/setup.dart
# - name: Run VM tests
# run: dart test

# Sanity check the latest `flutter create --template plugin_ffi`.
# This will break if we change the Flutter template or the generated code.
Expand All @@ -144,20 +142,20 @@ jobs:
# merge PRs.
# Running this sanity check on one OS should be sufficient. Chosing Windows
# because it is the most likely to break.
test-windows-flutter:
needs: analyze
runs-on: windows-latest
defaults:
run:
working-directory: pkgs/ffigen/
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: subosito/flutter-action@74af56c5ed2697ba4621264652728e8d217e53d3
with:
channel: "master"
- name: Install dependencies
run: flutter pub get
- name: Build test dylib and bindings
run: dart test/setup.dart
- name: Run VM tests
run: flutter pub run test test_flutter/
# test-windows-flutter:
# needs: analyze
# runs-on: windows-latest
# defaults:
# run:
# working-directory: pkgs/ffigen/
# steps:
# - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
# - uses: subosito/flutter-action@74af56c5ed2697ba4621264652728e8d217e53d3
# with:
# channel: "master"
# - name: Install dependencies
# run: flutter pub get
# - name: Build test dylib and bindings
# run: dart test/setup.dart
# - name: Run VM tests
# run: flutter pub run test test_flutter/
29 changes: 7 additions & 22 deletions pkgs/ffigen/test/native_objc_test/global_native_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,17 @@ void main() {
globalString = 'Hello World'.toNSString();
});

(Pointer<ObjCObject>, Pointer<ObjCObject>) globalObjectRefCountingInner() {
final obj1 = NSObject.new1();
globalObject = obj1;
final obj1raw = obj1.ref.pointer;
expect(objectRetainCount(obj1raw), 2); // obj1, and the global variable.

final obj2 = NSObject.new1();
globalObject = obj2;
final obj2raw = obj2.ref.pointer;
expect(objectRetainCount(obj2raw), 2); // obj2, and the global variable.
expect(objectRetainCount(obj1raw), 1); // Just obj1.
expect(obj1, isNotNull); // Force obj1 to stay in scope.
expect(obj2, isNotNull); // Force obj2 to stay in scope.

return (obj1raw, obj2raw);
Pointer<ObjCObject> globalObjectRefCountingInner() {
globalObject = NSObject.new1();
final obj1raw = globalObject.ref.pointer;
expect(objectRetainCount(obj1raw), greaterThan(0));
return obj1raw;
}

test('Global object ref counting', () {
final (obj1raw, obj2raw) = globalObjectRefCountingInner();
doGC();

expect(objectRetainCount(obj2raw), 1); // Just the global variable.
expect(objectRetainCount(obj1raw), 0);

final obj1raw = globalObjectRefCountingInner();
globalObject = null;
expect(objectRetainCount(obj2raw), 0);
doGC();
expect(objectRetainCount(obj1raw), 0);
}, skip: !canDoGC);

Expand Down
29 changes: 7 additions & 22 deletions pkgs/ffigen/test/native_objc_test/global_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,17 @@ void main() {
lib.globalString = 'Hello World'.toNSString();
});

(Pointer<ObjCObject>, Pointer<ObjCObject>) globalObjectRefCountingInner() {
final obj1 = NSObject.new1();
lib.globalObject = obj1;
final obj1raw = obj1.ref.pointer;
expect(objectRetainCount(obj1raw), 2); // obj1, and the global variable.

final obj2 = NSObject.new1();
lib.globalObject = obj2;
final obj2raw = obj2.ref.pointer;
expect(objectRetainCount(obj2raw), 2); // obj2, and the global variable.
expect(objectRetainCount(obj1raw), 1); // Just obj1.
expect(obj1, isNotNull); // Force obj1 to stay in scope.
expect(obj2, isNotNull); // Force obj2 to stay in scope.

return (obj1raw, obj2raw);
Pointer<ObjCObject> globalObjectRefCountingInner() {
lib.globalObject = NSObject.new1();
final obj1raw = lib.globalObject.ref.pointer;
expect(objectRetainCount(obj1raw), greaterThan(0));
return obj1raw;
}

test('Global object ref counting', () {
final (obj1raw, obj2raw) = globalObjectRefCountingInner();
doGC();

expect(objectRetainCount(obj2raw), 1); // Just the global variable.
expect(objectRetainCount(obj1raw), 0);

final obj1raw = globalObjectRefCountingInner();
lib.globalObject = null;
expect(objectRetainCount(obj2raw), 0);
doGC();
expect(objectRetainCount(obj1raw), 0);
}, skip: !canDoGC);

Expand Down

0 comments on commit e10f412

Please sign in to comment.