Skip to content

Commit 3c5bb80

Browse files
committed
Revert license header change in test
1 parent ba586af commit 3c5bb80

25 files changed

+79
-71
lines changed

.github/workflows/ffigen.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
5858
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
5959
with:
60-
sdk: dev #3.2.0
60+
sdk: dev #3.3.0
6161
- name: Install dependencies
6262
run: dart pub get
6363
- name: Install libclang-14-dev
@@ -78,7 +78,7 @@ jobs:
7878
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
7979
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
8080
with:
81-
sdk: dev #3.2.0
81+
sdk: dev #3.3.0
8282
- name: Install dependencies
8383
run: dart pub get
8484
- name: Build test dylib and bindings
@@ -111,7 +111,7 @@ jobs:
111111
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
112112
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
113113
with:
114-
sdk: dev #3.2.0
114+
sdk: dev #3.3.0
115115
- name: Install dependencies
116116
run: dart pub get
117117
- name: Build test dylib and bindings

pkgs/ffigen/example/ffinative/lib/generated_bindings.dart

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,56 @@
88
//
99
// Generated by `package:ffigen`.
1010
// ignore_for_file: type=lint
11+
@ffi.DefaultAsset('package:ffinative_example/generated_bindings.dart')
12+
library;
13+
1114
import 'dart:ffi' as ffi;
1215
import '' as self;
1316

1417
/// Adds 2 integers.
15-
@ffi.Native<ffi.Int Function(ffi.Int, ffi.Int)>(
16-
assetId: 'package:ffinative_example/generated_bindings.dart')
18+
@ffi.Native<ffi.Int Function(ffi.Int, ffi.Int)>()
1719
external int sum(
1820
int a,
1921
int b,
2022
);
2123

2224
/// Subtracts 2 integers.
23-
@ffi.Native<ffi.Int Function(ffi.Int, ffi.Int)>(
24-
assetId: 'package:ffinative_example/generated_bindings.dart')
25+
@ffi.Native<ffi.Int Function(ffi.Int, ffi.Int)>()
2526
external int subtract(
2627
int a,
2728
int b,
2829
);
2930

3031
/// Multiplies 2 integers, returns pointer to an integer,.
31-
@ffi.Native<ffi.Pointer<ffi.Int> Function(ffi.Int, ffi.Int)>(
32-
assetId: 'package:ffinative_example/generated_bindings.dart')
32+
@ffi.Native<ffi.Pointer<ffi.Int> Function(ffi.Int, ffi.Int)>()
3333
external ffi.Pointer<ffi.Int> multiply(
3434
int a,
3535
int b,
3636
);
3737

3838
/// Divides 2 integers, returns pointer to a float.
39-
@ffi.Native<ffi.Pointer<ffi.Float> Function(ffi.Int, ffi.Int)>(
40-
assetId: 'package:ffinative_example/generated_bindings.dart')
39+
@ffi.Native<ffi.Pointer<ffi.Float> Function(ffi.Int, ffi.Int)>()
4140
external ffi.Pointer<ffi.Float> divide(
4241
int a,
4342
int b,
4443
);
4544

4645
/// Divides 2 floats, returns a pointer to double.
47-
@ffi.Native<ffi.Pointer<ffi.Double> Function(ffi.Float, ffi.Float)>(
48-
assetId: 'package:ffinative_example/generated_bindings.dart')
46+
@ffi.Native<ffi.Pointer<ffi.Double> Function(ffi.Float, ffi.Float)>()
4947
external ffi.Pointer<ffi.Double> dividePrecision(
5048
double a,
5149
double b,
5250
);
5351

54-
@ffi.Native<ffi.Int>(
55-
assetId: 'package:ffinative_example/generated_bindings.dart')
52+
@ffi.Native<ffi.Int>()
5653
external int log_level;
5754

5855
@ffi.Array.multi([5])
59-
@ffi.Native<ffi.Array<ffi.Int>>(
60-
assetId: 'package:ffinative_example/generated_bindings.dart')
56+
@ffi.Native<ffi.Array<ffi.Int>>()
6157
external ffi.Array<ffi.Int> array;
6258

6359
/// Version of the native C library
64-
@ffi.Native<ffi.Pointer<ffi.Char>>(
65-
assetId: 'package:ffinative_example/generated_bindings.dart')
60+
@ffi.Native<ffi.Pointer<ffi.Char>>()
6661
external final ffi.Pointer<ffi.Char> library_version;
6762

6863
const addresses = _SymbolAddresses();

pkgs/ffigen/lib/src/code_generator/func.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ ${makeNativeAnnotation(
152152
nativeType: cType,
153153
dartName: nativeFuncName,
154154
nativeSymbolName: originalName,
155-
assetId: ffiNativeConfig.assetId,
156155
isLeaf: isLeaf,
157156
)}
158157
external $ffiReturnType $nativeFuncName($ffiArgDeclString);

pkgs/ffigen/lib/src/code_generator/global.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class Global extends LookUpBinding {
5757
..writeln(makeNativeAnnotation(
5858
w,
5959
nativeType: cType,
60-
assetId: nativeConfig.assetId,
6160
dartName: globalVarName,
6261
nativeSymbolName: originalName,
6362
isLeaf: false,

pkgs/ffigen/lib/src/code_generator/library.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,20 @@ class Library {
5656
// Seperate bindings which require lookup.
5757
final lookupBindings = <LookUpBinding>[];
5858
final nativeBindings = <LookUpBinding>[];
59+
FfiNativeConfig? nativeConfig;
5960

6061
for (final binding in this.bindings.whereType<LookUpBinding>()) {
61-
final usesLookup = switch (binding) {
62-
Func() => !binding.ffiNativeConfig.enabled,
63-
Global() => !binding.nativeConfig.enabled,
64-
_ => true,
62+
final nativeConfigForBinding = switch (binding) {
63+
Func() => binding.ffiNativeConfig,
64+
Global() => binding.nativeConfig,
65+
_ => null,
6566
};
6667

68+
// At the moment, all bindings share their native config.
69+
nativeConfig ??= nativeConfigForBinding;
70+
71+
final usesLookup =
72+
nativeConfigForBinding == null || !nativeConfigForBinding.enabled;
6773
(usesLookup ? lookupBindings : nativeBindings).add(binding);
6874
}
6975
final noLookUpBindings =
@@ -72,6 +78,7 @@ class Library {
7278
_writer = Writer(
7379
lookUpBindings: lookupBindings,
7480
ffiNativeBindings: nativeBindings,
81+
nativeAssetId: nativeConfig?.assetId,
7582
noLookUpBindings: noLookUpBindings,
7683
className: name,
7784
classDocComment: description,

pkgs/ffigen/lib/src/code_generator/utils.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,12 @@ String makeNativeAnnotation(
8888
required String? nativeType,
8989
required String dartName,
9090
required String nativeSymbolName,
91-
String? assetId,
9291
bool isLeaf = false,
9392
}) {
9493
final args = <(String, String)>[];
9594
if (dartName != nativeSymbolName) {
9695
args.add(('symbol', '"$nativeSymbolName"'));
9796
}
98-
if (assetId != null) {
99-
args.add(('assetId', "'$assetId'"));
100-
}
10197
if (isLeaf) {
10298
args.add(('isLeaf', 'true'));
10399
}

pkgs/ffigen/lib/src/code_generator/writer.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class Writer {
2323
/// Holds bindings which don't lookup symbols.
2424
final List<Binding> noLookUpBindings;
2525

26+
/// The default asset id to use for [ffiNativeBindings].
27+
final String? nativeAssetId;
28+
2629
/// Manages the `_SymbolAddress` class.
2730
final symbolAddressWriter = SymbolAddressWriter();
2831

@@ -99,6 +102,7 @@ class Writer {
99102
required this.ffiNativeBindings,
100103
required this.noLookUpBindings,
101104
required String className,
105+
required this.nativeAssetId,
102106
Set<LibraryImport>? additionalImports,
103107
this.classDocComment,
104108
this.header,
@@ -224,6 +228,17 @@ class Writer {
224228
result.write(makeDoc('ignore_for_file: type=lint'));
225229
}
226230

231+
// If there are any @Native bindings, the file needs to have an
232+
// `@DefaultAsset` annotation for the symbols to resolve properly. This
233+
// avoids duplicating the asset on every element.
234+
// Since the annotation goes on a `library;` directive, it needs to appear
235+
// before other definitions in the file.
236+
if (ffiNativeBindings.isNotEmpty && nativeAssetId != null) {
237+
result
238+
..writeln("@$ffiLibraryPrefix.DefaultAsset('$nativeAssetId')")
239+
..writeln('library;\n');
240+
}
241+
227242
/// Write [lookUpBindings].
228243
if (lookUpBindings.isNotEmpty) {
229244
// Write doc comment for wrapper class.

pkgs/ffigen/test/code_generator_tests/code_generator_test.dart

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,38 @@ import '../test_utils.dart';
1111

1212
void main() {
1313
const licenseHeader = '''
14-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
14+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
1515
// for details. All rights reserved. Use of this source code is governed by a
1616
// BSD-style license that can be found in the LICENSE file.
1717
''';
1818

1919
group('code_generator: ', () {
2020
@isTestGroup
21-
void withAndWithoutNative(String description, void Function(bool) runTest) {
21+
void withAndWithoutNative(
22+
String description, void Function(FfiNativeConfig) runTest) {
2223
group(description, () {
23-
test('without Native', () => runTest(false));
24-
test('with Native', () => runTest(true));
24+
test('without Native', () => runTest(FfiNativeConfig(enabled: false)));
25+
test('with Native',
26+
() => runTest(FfiNativeConfig(enabled: true, assetId: 'test')));
2527
});
2628
}
2729

2830
withAndWithoutNative('Function Binding (primitives, pointers)',
29-
(enableFfiNative) {
31+
(nativeConfig) {
3032
final library = Library(
3133
name: 'Bindings',
3234
header: licenseHeader,
3335
bindings: [
3436
Func(
35-
ffiNativeConfig: FfiNativeConfig(enabled: enableFfiNative),
37+
ffiNativeConfig: nativeConfig,
3638
name: 'noParam',
3739
dartDoc: 'Just a test function\nheres another line',
3840
returnType: NativeType(
3941
SupportedNativeType.Int32,
4042
),
4143
),
4244
Func(
43-
ffiNativeConfig: FfiNativeConfig(enabled: enableFfiNative),
45+
ffiNativeConfig: nativeConfig,
4446
name: 'withPrimitiveParam',
4547
parameters: [
4648
Parameter(
@@ -61,7 +63,7 @@ void main() {
6163
),
6264
),
6365
Func(
64-
ffiNativeConfig: FfiNativeConfig(enabled: enableFfiNative),
66+
ffiNativeConfig: nativeConfig,
6567
name: 'withPointerParam',
6668
parameters: [
6769
Parameter(
@@ -90,7 +92,7 @@ void main() {
9092
),
9193
),
9294
Func(
93-
ffiNativeConfig: FfiNativeConfig(enabled: enableFfiNative),
95+
ffiNativeConfig: nativeConfig,
9496
isLeaf: true,
9597
name: 'leafFunc',
9698
dartDoc: 'A function with isLeaf: true',
@@ -109,7 +111,8 @@ void main() {
109111
],
110112
);
111113

112-
_matchLib(library, enableFfiNative ? 'function_ffiNative' : 'function');
114+
_matchLib(
115+
library, nativeConfig.enabled ? 'function_ffiNative' : 'function');
113116
});
114117

115118
test('Struct Binding (primitives, pointers)', () {
@@ -254,12 +257,11 @@ void main() {
254257
});
255258

256259
withAndWithoutNative('global (primitives, pointers, pointer to struct)',
257-
(enableNative) {
260+
(nativeConfig) {
258261
final structSome = Struct(
259262
name: 'Some',
260263
);
261264
final emptyGlobalStruct = Struct(name: 'EmptyStruct');
262-
final nativeConfig = FfiNativeConfig(enabled: enableNative);
263265

264266
final library = Library(
265267
name: 'Bindings',
@@ -290,7 +292,7 @@ void main() {
290292
NativeType(
291293
SupportedNativeType.Float,
292294
),
293-
useArrayType: enableNative,
295+
useArrayType: nativeConfig.enabled,
294296
),
295297
constant: true,
296298
),
@@ -310,7 +312,7 @@ void main() {
310312
),
311313
],
312314
);
313-
_matchLib(library, enableNative ? 'global_native' : 'global');
315+
_matchLib(library, nativeConfig.enabled ? 'global_native' : 'global');
314316
});
315317

316318
test('constant', () {

pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_constant_bindings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_bindings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_ffiNative_bindings.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

55
// AUTO GENERATED FILE, DO NOT EDIT.
66
//
77
// Generated by `package:ffigen`.
88
// ignore_for_file: type=lint
9+
@ffi.DefaultAsset('test')
10+
library;
11+
912
import 'dart:ffi' as ffi;
1013

1114
/// Just a test function

pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_n_struct_bindings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_bindings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

55
// AUTO GENERATED FILE, DO NOT EDIT.
66
//
77
// Generated by `package:ffigen`.
88
// ignore_for_file: type=lint
9+
@ffi.DefaultAsset('test')
10+
library;
11+
912
import 'dart:ffi' as ffi;
1013

1114
@ffi.Native<ffi.Int32>()

pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_internal_conflict_resolution_bindings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_native_symbol_bindings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_packed_structs_bindings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_sort_bindings_bindings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

0 commit comments

Comments
 (0)