Skip to content

Commit

Permalink
[native_assets_cli] Separate out public API (#885)
Browse files Browse the repository at this point in the history
This does not change any of the public API yet, but it slims down the API surface of `package:native_assets_cli` to the bare minimum.

Internal details may be accessed in `package:native_assets_builder` via:

```dart
import 'package:native_assets_cli/native_assets_cli_internal.dart';
```

This enables the yaml serialization/deserialization to live in one place and be unit tested as one.

One hack is that we also access `package:native_assets_cli/native_assets_cli_internal.dart` in `package:native_toolchain_c` in the unit tests to depend on the C compilers provided on the Dart CI.
  • Loading branch information
dcharkes authored Jan 12, 2024
1 parent a1d2bb6 commit 053a0f3
Show file tree
Hide file tree
Showing 62 changed files with 1,078 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'dart:async';
import 'dart:io';

import 'package:logging/logging.dart';
import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart';
import 'package:package_config/package_config.dart';

import '../package_layout/package_layout.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_assets_builder/lib/src/model/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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:native_assets_cli/native_assets_cli.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart';

import '../utils/yaml.dart';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_assets_builder/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:
dependencies:
graphs: ^2.3.1
logging: ^1.2.0
native_assets_cli: ^0.3.2
native_assets_cli: ^0.4.0
package_config: ^2.1.0
yaml: ^3.1.2
yaml_edit: ^2.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'dart:io';

import 'package:file_testing/file_testing.dart';
import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart';
import 'package:test/test.dart';

import '../helpers.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:native_assets_builder/src/build_runner/build_runner.dart';
import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart';
import 'package:test/test.dart';

import '../helpers.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'dart:io';

import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart';
import 'package:test/test.dart';

import '../helpers.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_assets_builder/test/build_runner/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'dart:io';
import 'package:file_testing/file_testing.dart';
import 'package:logging/logging.dart';
import 'package:native_assets_builder/native_assets_builder.dart';
import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart';
import 'package:test/test.dart';

import '../helpers.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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:native_assets_cli/native_assets_cli.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart';
import 'package:test/test.dart';

import '../helpers.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
cli_config: ^0.1.1
cyclic_package_2:
path: ../cyclic_package_2
native_assets_cli: ^0.3.2
native_assets_cli: ^0.4.0
yaml: ^3.1.1
yaml_edit: ^2.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
cli_config: ^0.1.1
cyclic_package_1:
path: ../cyclic_package_1
native_assets_cli: ^0.3.2
native_assets_cli: ^0.4.0
yaml: ^3.1.1
yaml_edit: ^2.1.0

Expand Down
4 changes: 2 additions & 2 deletions pkgs/native_assets_builder/test/data/native_add/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ environment:
dependencies:
cli_config: ^0.1.1
logging: ^1.1.1
native_assets_cli: ^0.3.2
native_toolchain_c: ^0.3.2
native_assets_cli: ^0.4.0
native_toolchain_c: ^0.3.4

dev_dependencies:
ffigen: ^8.0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ environment:
dependencies:
cli_config: ^0.1.1
logging: ^1.1.1
native_assets_cli: ^0.3.2
native_toolchain_c: ^0.3.2
native_assets_cli: ^0.4.0
native_toolchain_c: ^0.3.4

dev_dependencies:
ffigen: ^8.0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ environment:
dependencies:
cli_config: ^0.1.1
logging: ^1.1.1
native_assets_cli: ^0.3.2
native_toolchain_c: ^0.3.2
native_assets_cli: ^0.4.0
native_toolchain_c: ^0.3.4

dev_dependencies:
ffigen: ^8.0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:

dependencies:
cli_config: ^0.1.1
native_assets_cli: ^0.3.2
native_assets_cli: ^0.4.0
package_with_metadata:
path: ../package_with_metadata/
yaml: ^3.1.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:

dependencies:
cli_config: ^0.1.1
native_assets_cli: ^0.3.2
native_assets_cli: ^0.4.0
yaml: ^3.1.1
yaml_edit: ^2.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'dart:io';

import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart';

void main(List<String> args) async {
final buildConfig = await BuildConfig.fromArgs(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:

dependencies:
cli_config: ^0.1.1
native_assets_cli: ^0.3.2
native_assets_cli: ^0.4.0
yaml: ^3.1.1
yaml_edit: ^2.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'dart:io';

import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart';

void main(List<String> args) async {
final buildConfig = await BuildConfig.fromArgs(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:

dependencies:
cli_config: ^0.1.1
native_assets_cli: ^0.3.2
native_assets_cli: ^0.4.0
yaml: ^3.1.1
yaml_edit: ^2.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'dart:io';

import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart';

void main(List<String> args) async {
final buildConfig = await BuildConfig.fromArgs(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:

dependencies:
cli_config: ^0.1.1
native_assets_cli: ^0.3.2
native_assets_cli: ^0.4.0
yaml: ^3.1.1
yaml_edit: ^2.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:

dependencies:
cli_config: ^0.1.1
native_assets_cli: ^0.3.2
native_assets_cli: ^0.4.0
yaml: ^3.1.1
yaml_edit: ^2.1.0

Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_assets_builder/test/model/asset_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// ignore_for_file: undefined_hidden_name

import 'package:native_assets_builder/src/model/asset.dart';
import 'package:native_assets_cli/native_assets_cli.dart'
import 'package:native_assets_cli/native_assets_cli_internal.dart'
hide AssetIterable, AssetRelativePath;
import 'package:test/test.dart';

Expand Down
5 changes: 5 additions & 0 deletions pkgs/native_assets_cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.4.1-wip

- **Breaking change** Removed all code not used in `build.dart` scripts out of
the public API.

## 0.4.0

- Added [example/use_dart_api/](example/use_dart_api/) detailing how to use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ environment:
dependencies:
cli_config: ^0.1.1
logging: ^1.1.1
native_assets_cli: ^0.3.2
native_toolchain_c: ^0.3.2
native_assets_cli: ^0.4.0
native_toolchain_c: ^0.3.4

dev_dependencies:
ffigen: ^8.0.2
Expand Down
6 changes: 3 additions & 3 deletions pkgs/native_assets_cli/example/use_dart_api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ version: 0.1.0
publish_to: none

environment:
sdk: ">=3.0.0 <4.0.0"
sdk: '>=3.0.0 <4.0.0'

dependencies:
cli_config: ^0.1.1
logging: ^1.1.1
native_assets_cli: ^0.3.2
native_toolchain_c: ^0.3.2
native_assets_cli: ^0.4.0
native_toolchain_c: ^0.3.4

dev_dependencies:
ffigen: ^10.0.0
Expand Down
20 changes: 10 additions & 10 deletions pkgs/native_assets_cli/lib/native_assets_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
/// native assets CLI, e.g. a `build.dart` script.
library native_assets_cli;

export 'src/model/asset.dart';
export 'src/model/build_config.dart';
export 'src/model/build_mode.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/target.dart';
export 'src/api/asset.dart';
export 'src/api/build_config.dart';
export 'src/api/build_mode.dart';
export 'src/api/build_output.dart';
export 'src/api/dependencies.dart';
export 'src/api/ios_sdk.dart';
export 'src/api/link_mode.dart';
export 'src/api/link_mode_preference.dart';
export 'src/api/metadata.dart';
export 'src/api/target.dart';
59 changes: 59 additions & 0 deletions pkgs/native_assets_cli/lib/src/api/asset.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2024, 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.

import '../model/asset.dart' as model;
import '../model/link_mode.dart' as model;
import '../model/target.dart' as model;
import 'link_mode.dart';
import 'target.dart';

abstract class AssetPath {}

/// Asset at absolute path [uri].
abstract class AssetAbsolutePath implements AssetPath {
Uri get uri;

factory AssetAbsolutePath(Uri uri) = model.AssetAbsolutePath;
}

/// Asset is avaliable on the system `PATH`.
///
/// [uri] only contains a file name.
abstract class AssetSystemPath implements AssetPath {
Uri get uri;

factory AssetSystemPath(Uri uri) = model.AssetSystemPath;
}

/// Asset is loaded in the process and symbols are available through
/// `DynamicLibrary.process()`.
abstract class AssetInProcess implements AssetPath {
factory AssetInProcess() = model.AssetInProcess;
}

/// Asset is embedded in executable and symbols are available through
/// `DynamicLibrary.executable()`.
abstract class AssetInExecutable implements AssetPath {
factory AssetInExecutable() = model.AssetInExecutable;
}

abstract class Asset {
LinkMode get linkMode;
String get id;
Target get target;
AssetPath get path;

factory Asset({
required String id,
required LinkMode linkMode,
required Target target,
required AssetPath path,
}) =>
model.Asset(
id: id,
linkMode: linkMode as model.LinkMode,
target: target as model.Target,
path: path as model.AssetPath,
);
}
Loading

0 comments on commit 053a0f3

Please sign in to comment.