Skip to content

Commit 7adf6bf

Browse files
authored
[native_assets_cli] Add version skew regression test back in (#1839)
Closes: #1838 We need to support previous parsable versions until we release new package versions, this issue is going to arise every time in between us changing the protocol while developing and getting to a point where we publish these changes on pub. I've added back in the regression test that got removed by the previous refactorings to prevent this from happening on the next change.
1 parent 2a4d563 commit 7adf6bf

File tree

16 files changed

+212
-9
lines changed

16 files changed

+212
-9
lines changed

.github/workflows/native.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ jobs:
6969
- run: dart pub get -C test_data/native_add_add_source/
7070
if: ${{ matrix.package == 'native_assets_builder' }}
7171

72+
- run: dart pub get -C test_data/native_add_version_skew/
73+
if: ${{ matrix.package == 'native_assets_builder' }}
74+
7275
- run: dart pub get -C test_data/native_subtract/
7376
if: ${{ matrix.package == 'native_assets_builder' }}
7477

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:test/test.dart';
6+
7+
import '../helpers.dart';
8+
import 'helpers.dart';
9+
10+
const Timeout longTimeout = Timeout(Duration(minutes: 5));
11+
12+
void main() async {
13+
test('Test hook using an older version of native_assets_cli',
14+
timeout: longTimeout, () async {
15+
await inTempDir((tempUri) async {
16+
await copyTestProjects(targetUri: tempUri);
17+
final packageUri = tempUri.resolve('native_add_version_skew/');
18+
19+
// First, run `pub get`, we need pub to resolve our dependencies.
20+
await runPubGet(
21+
workingDirectory: packageUri,
22+
logger: logger,
23+
);
24+
25+
{
26+
final result = await build(
27+
packageUri,
28+
logger,
29+
dartExecutable,
30+
configValidator: validateCodeAssetBuildConfig,
31+
buildAssetTypes: [CodeAsset.type],
32+
buildValidator: validateCodeAssetBuildOutput,
33+
applicationAssetValidator: validateCodeAssetInApplication,
34+
);
35+
expect(result?.encodedAssets.length, 1);
36+
}
37+
});
38+
});
39+
}

pkgs/native_assets_builder/test_data/manifest.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@
6060
- native_add_duplicate/pubspec.yaml
6161
- native_add_duplicate/src/native_add.c
6262
- native_add_duplicate/src/native_add.h
63+
- native_add_version_skew/ffigen.yaml
64+
- native_add_version_skew/hook/build.dart
65+
- native_add_version_skew/lib/native_add.dart
66+
- native_add_version_skew/lib/src/native_add_bindings_generated.dart
67+
- native_add_version_skew/lib/src/native_add.dart
68+
- native_add_version_skew/pubspec.yaml
69+
- native_add_version_skew/src/native_add.c
70+
- native_add_version_skew/src/native_add.h
71+
- native_add_version_skew/test/native_add_test.dart
6372
- native_add/ffigen.yaml
6473
- native_add/hook/build.dart
6574
- native_add/lib/native_add.dart
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Run with `flutter pub run ffigen --config ffigen.yaml`.
2+
name: NativeAddBindings
3+
description: |
4+
Bindings for `src/native_add.h`.
5+
6+
Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
7+
output: 'lib/src/native_add_bindings_generated.dart'
8+
headers:
9+
entry-points:
10+
- 'src/native_add.h'
11+
include-directives:
12+
- 'src/native_add.h'
13+
preamble: |
14+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
15+
// for details. All rights reserved. Use of this source code is governed by a
16+
// BSD-style license that can be found in the LICENSE file.
17+
comments:
18+
style: any
19+
length: full
20+
ffi-native:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:logging/logging.dart';
6+
import 'package:native_assets_cli/native_assets_cli.dart';
7+
import 'package:native_toolchain_c/native_toolchain_c.dart';
8+
9+
void main(List<String> arguments) async {
10+
await build(arguments, (config, output) async {
11+
final packageName = config.packageName;
12+
final cbuilder = CBuilder.library(
13+
name: packageName,
14+
assetName: 'src/${packageName}_bindings_generated.dart',
15+
sources: [
16+
'src/$packageName.c',
17+
],
18+
);
19+
await cbuilder.run(
20+
config: config,
21+
output: output,
22+
logger: Logger('')
23+
..level = Level.ALL
24+
..onRecord.listen((record) {
25+
print('${record.level.name}: ${record.time}: ${record.message}');
26+
}),
27+
);
28+
});
29+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
export 'src/native_add.dart';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'native_add_bindings_generated.dart' as bindings;
6+
7+
int add(int a, int b) => bindings.add(a, b);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// AUTO GENERATED FILE, DO NOT EDIT.
6+
//
7+
// Generated by `package:ffigen`.
8+
// ignore_for_file: type=lint
9+
import 'dart:ffi' as ffi;
10+
11+
@ffi.Native<ffi.Int32 Function(ffi.Int32, ffi.Int32)>(symbol: 'add')
12+
external int add(
13+
int a,
14+
int b,
15+
);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- ffigen.yaml
2+
- hook/build.dart
3+
- lib/native_add.dart
4+
- lib/src/native_add_bindings_generated.dart
5+
- lib/src/native_add.dart
6+
- pubspec.yaml
7+
- src/native_add.c
8+
- src/native_add.h
9+
- test/native_add_test.dart
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: native_add
2+
description: Sums two numbers with native code.
3+
version: 0.1.0
4+
5+
publish_to: none
6+
7+
environment:
8+
sdk: '>=3.3.0 <4.0.0'
9+
10+
dependencies:
11+
logging: ^1.1.1
12+
native_assets_cli: ^0.9.0
13+
native_toolchain_c: ^0.6.0
14+
15+
dev_dependencies:
16+
ffigen: ^8.0.2
17+
lints: ^3.0.0
18+
some_dev_dep:
19+
path: ../some_dev_dep/
20+
test: ^1.23.1

0 commit comments

Comments
 (0)