diff --git a/.github/workflows/io_file.yml b/.github/workflows/io_file.yml index 4288b57e..9fe0639e 100644 --- a/.github/workflows/io_file.yml +++ b/.github/workflows/io_file.yml @@ -47,10 +47,7 @@ jobs: with: sdk: dev - run: dart pub get - - run: dart run ffigen --config ffigen.yaml - - run: dart run ffigen --config constants-ffigen.yaml - - run: dart --enable-experiment=native-assets run tool/build_constants.dart - - run: dart format lib/src/*.dart + - run: dart --enable-experiment=native-assets run tool/generate.dart - run: git diff --exit-code desktop-vm-test: diff --git a/pkgs/io_file/constants-ffigen.yaml b/pkgs/io_file/constants-ffigen.yaml index becb49e9..1ab76307 100644 --- a/pkgs/io_file/constants-ffigen.yaml +++ b/pkgs/io_file/constants-ffigen.yaml @@ -3,7 +3,7 @@ name: NativeAddBindings description: | Bindings for `constants.g.h`. - Regenerate bindings with `dart run ffigen --config constants-ffigen.yaml`. + Regenerate bindings with `dart run tool/generate.dart`. output: 'lib/src/constant_bindings.g.dart' headers: entry-points: diff --git a/pkgs/io_file/ffigen.yaml b/pkgs/io_file/ffigen.yaml index 8b98b7f9..2d83623c 100644 --- a/pkgs/io_file/ffigen.yaml +++ b/pkgs/io_file/ffigen.yaml @@ -3,7 +3,7 @@ name: NativeAddBindings description: | Bindings for `src/libc_shim.h`. - Regenerate bindings with `dart run ffigen --config ffigen.yaml`. + Regenerate bindings with `dart run tool/generate.dart`. output: 'lib/src/libc_bindings.g.dart' headers: entry-points: diff --git a/pkgs/io_file/tool/generate.dart b/pkgs/io_file/tool/generate.dart new file mode 100755 index 00000000..370136d6 --- /dev/null +++ b/pkgs/io_file/tool/generate.dart @@ -0,0 +1,38 @@ +// 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. + +// Run all code generation and formatting steps. + +import 'dart:convert'; +import 'dart:io'; + +import 'package:ffigen/src/executables/ffigen.dart' as ffigen; +import 'build_constants.dart' as build_constants; + +void _formatFile(String path) { + final result = Process.runSync(Platform.executable, [ + 'format', + path, + ], stderrEncoding: utf8); + if (result.exitCode != 0) { + throw Exception('failed to format $path:\n${result.stderr}'); + } +} + +void main() async { + build_constants.main(); + + await ffigen.main(['--no-format', '-v', 'severe', '--config', 'ffigen.yaml']); + await ffigen.main([ + '--no-format', + '-v', + 'severe', + '--config', + 'constants-ffigen.yaml', + ]); + + _formatFile('lib/src/constant_bindings.g.dart'); + _formatFile('lib/src/constants.g.dart'); + _formatFile('lib/src/libc_bindings.g.dart'); +}