Skip to content

[native_assets_cli] Refactor API #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 28, 2023
8 changes: 0 additions & 8 deletions pkgs/c_compiler/lib/c_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,3 @@
library;

export 'src/cbuilder/cbuilder.dart';
export 'src/native_toolchain/android_ndk.dart';
export 'src/native_toolchain/apple_clang.dart';
export 'src/native_toolchain/clang.dart';
export 'src/native_toolchain/gcc.dart';
export 'src/tool/tool.dart';
export 'src/tool/tool_instance.dart';
export 'src/tool/tool_requirement.dart';
export 'src/tool/tool_resolver.dart';
10 changes: 5 additions & 5 deletions pkgs/c_compiler/lib/src/cbuilder/cbuilder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class CBuilder implements Builder {
final outDir = buildConfig.outDir;
final packageRoot = buildConfig.packageRoot;
await Directory.fromUri(outDir).create(recursive: true);
final packaging = buildConfig.packaging.preferredPackaging.first;
final linkMode = buildConfig.linkModePreference.preferredLinkMode;
final libUri =
outDir.resolve(buildConfig.target.os.libraryFileName(name, packaging));
outDir.resolve(buildConfig.target.os.libraryFileName(name, linkMode));
final exeUri =
outDir.resolve(buildConfig.target.os.executableFileName(name));
final sources = [
Expand All @@ -92,11 +92,11 @@ class CBuilder implements Builder {
logger: logger,
sources: sources,
dynamicLibrary:
_type == _CBuilderType.library && packaging == Packaging.dynamic
_type == _CBuilderType.library && linkMode == LinkMode.dynamic
? libUri
: null,
staticLibrary:
_type == _CBuilderType.library && packaging == Packaging.static
_type == _CBuilderType.library && linkMode == LinkMode.static
? libUri
: null,
executable: _type == _CBuilderType.executable ? exeUri : null,
Expand All @@ -106,7 +106,7 @@ class CBuilder implements Builder {
if (assetName != null) {
buildOutput.assets.add(Asset(
name: assetName!,
packaging: packaging,
linkMode: linkMode,
target: buildConfig.target,
path: AssetAbsolutePath(libUri),
));
Expand Down
5 changes: 4 additions & 1 deletion pkgs/c_compiler/lib/src/cbuilder/run_cbuilder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import 'package:logging/logging.dart';
import 'package:native_assets_cli/native_assets_cli.dart';

import '../../c_compiler.dart';
import '../native_toolchain/apple_clang.dart';
import '../native_toolchain/clang.dart';
import '../native_toolchain/gcc.dart';
import '../native_toolchain/msvc.dart';
import '../native_toolchain/xcode.dart';
import '../tool/tool_instance.dart';
import '../utils/env_from_bat.dart';
import '../utils/run_process.dart';
import 'compiler_resolver.dart';
Expand Down
12 changes: 6 additions & 6 deletions pkgs/c_compiler/test/cbuilder/cbuilder_cross_android_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ void main() {
Target.androidX64: 'elf64-x86-64',
};

for (final packaging in Packaging.values) {
for (final linkMode in LinkMode.values) {
for (final target in targets) {
test('Cbuilder $packaging library $target', () async {
test('Cbuilder $linkMode library $target', () async {
await inTempDir((tempUri) async {
final addCUri =
packageUri.resolve('test/cbuilder/testfiles/add/src/add.c');
Expand All @@ -45,9 +45,9 @@ void main() {
outDir: tempUri,
packageRoot: tempUri,
target: target,
packaging: packaging == Packaging.dynamic
? PackagingPreference.dynamic
: PackagingPreference.static,
linkModePreference: linkMode == LinkMode.dynamic
? LinkModePreference.dynamic
: LinkModePreference.static,
);
final buildOutput = BuildOutput();

Expand All @@ -63,7 +63,7 @@ void main() {
);

final libUri =
tempUri.resolve(target.os.libraryFileName(name, packaging));
tempUri.resolve(target.os.libraryFileName(name, linkMode));
if (Platform.isLinux) {
final result = await runProcess(
executable: Uri.file('readelf'),
Expand Down
12 changes: 6 additions & 6 deletions pkgs/c_compiler/test/cbuilder/cbuilder_cross_ios_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ void main() {
Target.iOSArm64: 'arm64',
};

for (final packaging in Packaging.values) {
for (final linkMode in LinkMode.values) {
for (final targetIOSSdk in IOSSdk.values) {
for (final target in targets) {
test('Cbuilder $packaging library $targetIOSSdk $target', () async {
test('Cbuilder $linkMode library $targetIOSSdk $target', () async {
await inTempDir((tempUri) async {
final addCUri =
packageUri.resolve('test/cbuilder/testfiles/add/src/add.c');
Expand All @@ -42,9 +42,9 @@ void main() {
outDir: tempUri,
packageRoot: tempUri,
target: target,
packaging: packaging == Packaging.dynamic
? PackagingPreference.dynamic
: PackagingPreference.static,
linkModePreference: linkMode == LinkMode.dynamic
? LinkModePreference.dynamic
: LinkModePreference.static,
targetIOSSdk: targetIOSSdk,
);
final buildOutput = BuildOutput();
Expand All @@ -61,7 +61,7 @@ void main() {
);

final libUri =
tempUri.resolve(target.os.libraryFileName(name, packaging));
tempUri.resolve(target.os.libraryFileName(name, linkMode));
final result = await runProcess(
executable: Uri.file('objdump'),
arguments: ['-t', libUri.path],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void main() {
Target.linuxX64: 'Advanced Micro Devices X86-64',
};

for (final packaging in Packaging.values) {
for (final linkMode in LinkMode.values) {
for (final target in targets) {
test('Cbuilder $packaging library $target', () async {
test('Cbuilder $linkMode library $target', () async {
await inTempDir((tempUri) async {
final addCUri =
packageUri.resolve('test/cbuilder/testfiles/add/src/add.c');
Expand All @@ -46,9 +46,9 @@ void main() {
outDir: tempUri,
packageRoot: tempUri,
target: target,
packaging: packaging == Packaging.dynamic
? PackagingPreference.dynamic
: PackagingPreference.static,
linkModePreference: linkMode == LinkMode.dynamic
? LinkModePreference.dynamic
: LinkModePreference.static,
);
final buildOutput = BuildOutput();

Expand All @@ -64,7 +64,7 @@ void main() {
);

final libUri =
tempUri.resolve(target.os.libraryFileName(name, packaging));
tempUri.resolve(target.os.libraryFileName(name, linkMode));
final result = await runProcess(
executable: Uri.file('readelf'),
arguments: ['-h', libUri.path],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ void main() {
Target.macOSX64: '64-bit x86-64',
};

for (final packaging in Packaging.values) {
for (final linkMode in LinkMode.values) {
for (final target in targets) {
test('Cbuilder $packaging library $target', () async {
test('Cbuilder $linkMode library $target', () async {
await inTempDir((tempUri) async {
final addCUri =
packageUri.resolve('test/cbuilder/testfiles/add/src/add.c');
Expand All @@ -43,9 +43,9 @@ void main() {
outDir: tempUri,
packageRoot: tempUri,
target: target,
packaging: packaging == Packaging.dynamic
? PackagingPreference.dynamic
: PackagingPreference.static,
linkModePreference: linkMode == LinkMode.dynamic
? LinkModePreference.dynamic
: LinkModePreference.static,
);
final buildOutput = BuildOutput();

Expand All @@ -61,7 +61,7 @@ void main() {
);

final libUri =
tempUri.resolve(target.os.libraryFileName(name, packaging));
tempUri.resolve(target.os.libraryFileName(name, linkMode));
final result = await runProcess(
executable: Uri.file('objdump'),
arguments: ['-t', libUri.path],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ void main() {
};

const dumpbinFileType = {
Packaging.dynamic: 'DLL',
Packaging.static: 'LIBRARY',
LinkMode.dynamic: 'DLL',
LinkMode.static: 'LIBRARY',
};

for (final packaging in Packaging.values) {
for (final linkMode in LinkMode.values) {
for (final target in targets) {
test('Cbuilder $packaging library $target', timeout: Timeout.factor(2),
test('Cbuilder $linkMode library $target', timeout: Timeout.factor(2),
() async {
await inTempDir((tempUri) async {
final addCUri =
Expand All @@ -57,9 +57,9 @@ void main() {
outDir: tempUri,
packageRoot: tempUri,
target: target,
packaging: packaging == Packaging.dynamic
? PackagingPreference.dynamic
: PackagingPreference.static,
linkModePreference: linkMode == LinkMode.dynamic
? LinkModePreference.dynamic
: LinkModePreference.static,
);
final buildOutput = BuildOutput();

Expand All @@ -75,7 +75,7 @@ void main() {
);

final libUri =
tempUri.resolve(target.os.libraryFileName(name, packaging));
tempUri.resolve(target.os.libraryFileName(name, linkMode));
expect(await File.fromUri(libUri).exists(), true);
final result = await runProcess(
executable: dumpbinUri,
Expand All @@ -90,7 +90,7 @@ void main() {
final fileType = result.stdout
.split('\n')
.firstWhere((e) => e.contains('File Type'));
expect(fileType, contains(dumpbinFileType[packaging]));
expect(fileType, contains(dumpbinFileType[linkMode]));
});
});
}
Expand Down
5 changes: 3 additions & 2 deletions pkgs/c_compiler/test/cbuilder/cbuilder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ void main() {
outDir: tempUri,
packageRoot: tempUri,
target: Target.current,
packaging: PackagingPreference.dynamic, // Ignored by executables.
linkModePreference:
LinkModePreference.dynamic, // Ignored by executables.
cc: cc,
toolchainEnvScript: toolchainEnvScript,
toolchainEnvScriptArgs: toolchainEnvScriptArgs,
Expand Down Expand Up @@ -70,7 +71,7 @@ void main() {
outDir: tempUri,
packageRoot: tempUri,
target: Target.current,
packaging: PackagingPreference.dynamic,
linkModePreference: LinkModePreference.dynamic,
cc: cc,
toolchainEnvScript: toolchainEnvScript,
toolchainEnvScriptArgs: toolchainEnvScriptArgs,
Expand Down
7 changes: 4 additions & 3 deletions pkgs/c_compiler/test/cbuilder/compiler_resolver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
@OnPlatform({'windows': Timeout.factor(10)})
library;

import 'package:c_compiler/c_compiler.dart';
import 'package:c_compiler/src/cbuilder/compiler_resolver.dart';
import 'package:c_compiler/src/native_toolchain/apple_clang.dart';
import 'package:c_compiler/src/native_toolchain/clang.dart';
import 'package:c_compiler/src/native_toolchain/msvc.dart';
import 'package:c_compiler/src/tool/tool_error.dart';
import 'package:collection/collection.dart';
Expand Down Expand Up @@ -40,7 +41,7 @@ void main() {
outDir: tempUri,
packageRoot: tempUri,
target: Target.current,
packaging: PackagingPreference.dynamic,
linkModePreference: LinkModePreference.dynamic,
ar: ar,
cc: cc,
ld: ld,
Expand All @@ -61,7 +62,7 @@ void main() {
outDir: tempUri,
packageRoot: tempUri,
target: Target.windowsX64,
packaging: PackagingPreference.dynamic,
linkModePreference: LinkModePreference.dynamic,
);
final resolver = CompilerResolver(
buildConfig: buildConfig,
Expand Down
3 changes: 2 additions & 1 deletion pkgs/c_compiler/test/native_toolchain/apple_clang_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ library;

import 'dart:io';

import 'package:c_compiler/c_compiler.dart';
import 'package:c_compiler/src/native_toolchain/apple_clang.dart';
import 'package:c_compiler/src/tool/tool_requirement.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:test/test.dart';

Expand Down
3 changes: 2 additions & 1 deletion pkgs/c_compiler/test/tool/tool_instance_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// 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 'package:c_compiler/c_compiler.dart';
import 'package:c_compiler/src/tool/tool.dart';
import 'package:c_compiler/src/tool/tool_instance.dart';
import 'package:collection/collection.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:test/test.dart';
Expand Down
6 changes: 5 additions & 1 deletion pkgs/c_compiler/test/tool/tool_resolver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

import 'dart:io';

import 'package:c_compiler/c_compiler.dart';
import 'package:c_compiler/src/native_toolchain/apple_clang.dart';
import 'package:c_compiler/src/native_toolchain/clang.dart';
import 'package:c_compiler/src/native_toolchain/msvc.dart';
import 'package:c_compiler/src/tool/tool.dart';
import 'package:c_compiler/src/tool/tool_error.dart';
import 'package:c_compiler/src/tool/tool_instance.dart';
import 'package:c_compiler/src/tool/tool_resolver.dart';
import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:test/test.dart';

Expand Down
4 changes: 2 additions & 2 deletions pkgs/native_assets_cli/lib/native_assets_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export 'src/model/build_config.dart';
export 'src/model/build_output.dart';
export 'src/model/dependencies.dart';
export 'src/model/ios_sdk.dart';
export 'src/model/link_mode.dart';
export 'src/model/link_mode_preference.dart';
export 'src/model/metadata.dart';
export 'src/model/packaging.dart';
export 'src/model/packaging_preference.dart';
export 'src/model/target.dart';
Loading