Skip to content

Commit cb18523

Browse files
committed
[native_assets_cli] Remove CodeAsset os and architecture getters
1 parent cec17a4 commit cb18523

File tree

3 files changed

+40
-25
lines changed

3 files changed

+40
-25
lines changed

pkgs/native_assets_builder/test_data/add_asset_link/hook/link.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ void main(List<String> arguments) async {
1313
package: 'add_asset_link',
1414
name: 'dylib_add_link',
1515
linkMode: builtDylib.linkMode,
16-
os: builtDylib.os,
17-
architecture: builtDylib.architecture,
16+
os: input.config.code.targetOS,
17+
architecture: input.config.code.targetArchitecture,
1818
file: builtDylib.file,
1919
),
2020
)

pkgs/native_assets_cli/lib/src/code_assets/code_asset.dart

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import '../config.dart';
66
import '../encoded_asset.dart';
77
import 'architecture.dart';
8+
import 'config.dart';
89
import 'link_mode.dart';
910
import 'os.dart';
1011
import 'syntax.g.dart' as syntax;
@@ -34,31 +35,30 @@ import 'syntax.g.dart' as syntax;
3435
/// * Assets which designate symbols present in the target system
3536
/// ([DynamicLoadingSystem]), process ([LookupInProcess]), or executable
3637
/// ([LookupInExecutable]). These assets do not have a [file].
37-
/// * Dynamic libraries bundled into the application
38-
/// ([DynamicLoadingBundled]). These assets must provide a [file] to be
39-
/// bundled.
38+
/// * Dynamic libraries bundled into the application ([DynamicLoadingBundled]).
39+
/// These assets must provide a [file] to be bundled.
4040
///
41-
/// An application is compiled to run on a specific target [os] and
42-
/// [architecture]. Different targets require different assets, so the package
43-
/// developer must specify which asset to bundle for which target.
41+
/// An application is compiled to run on a specific target [CodeConfig.targetOS]
42+
/// and [CodeConfig.targetArchitecture]. Different targets require different
43+
/// assets, so the package developer must specify which asset to bundle for
44+
/// which target.
4445
///
4546
/// An asset has different ways of being accessible in the final application. It
4647
/// is either brought in "manually" by having the package developer specify a
4748
/// [file] path of the asset on the current system, it can be part of the Dart
4849
/// or Flutter SDK ([LookupInProcess]), or it can be already present in the
49-
/// target system ([DynamicLoadingSystem]). If the asset is bundled
50-
/// "manually", the Dart or Flutter SDK will take care of copying the asset
51-
/// [file] from its specified location on the current system into the
52-
/// application bundle.
50+
/// target system ([DynamicLoadingSystem]). If the asset is bundled "manually",
51+
/// the Dart or Flutter SDK will take care of copying the asset [file] from its
52+
/// specified location on the current system into the application bundle.
5353
final class CodeAsset {
5454
/// The id of this code asset.
5555
final String id;
5656

5757
/// The operating system this asset can run on.
58-
final OS os;
58+
final OS _os;
5959

6060
/// The architecture this asset can run on.
61-
final Architecture architecture;
61+
final Architecture _architecture;
6262

6363
/// The link mode for this native code.
6464
///
@@ -99,10 +99,11 @@ final class CodeAsset {
9999
CodeAsset._({
100100
required this.id,
101101
required this.linkMode,
102-
required this.os,
102+
required OS os,
103103
required this.file,
104-
required this.architecture,
105-
});
104+
required Architecture architecture,
105+
}) : _architecture = architecture,
106+
_os = os;
106107

107108
factory CodeAsset.fromEncoded(EncodedAsset asset) {
108109
assert(asset.type == CodeAsset.type);
@@ -128,8 +129,8 @@ final class CodeAsset {
128129
}) => CodeAsset._(
129130
id: id ?? this.id,
130131
linkMode: linkMode ?? this.linkMode,
131-
os: os ?? this.os,
132-
architecture: architecture ?? this.architecture,
132+
os: os ?? _os,
133+
architecture: architecture ?? _architecture,
133134
file: file ?? this.file,
134135
);
135136

@@ -140,28 +141,36 @@ final class CodeAsset {
140141
}
141142
return other.id == id &&
142143
other.linkMode == linkMode &&
143-
other.architecture == architecture &&
144-
other.os == os &&
144+
other._architecture == _architecture &&
145+
other._os == _os &&
145146
other.file == file;
146147
}
147148

148149
@override
149-
int get hashCode => Object.hash(id, linkMode, architecture, os, file);
150+
int get hashCode => Object.hash(id, linkMode, _architecture, _os, file);
150151

151152
EncodedAsset encode() {
152153
final encoding = syntax.NativeCodeAssetEncoding(
153-
architecture: architecture.toSyntax(),
154+
architecture: _architecture.toSyntax(),
154155
file: file,
155156
id: id,
156157
linkMode: linkMode.toSyntax(),
157-
os: os.toSyntax(),
158+
159+
os: _os.toSyntax(),
158160
);
159161
return EncodedAsset(CodeAsset.type, encoding.json);
160162
}
161163

162164
static const String type = 'native_code';
163165
}
164166

167+
// These field will be removed in the future, prevent anyone from reading them.
168+
extension ForValidationOnly on CodeAsset {
169+
OS get os => _os;
170+
171+
Architecture get architecture => _architecture;
172+
}
173+
165174
extension OSLibraryNaming on OS {
166175
/// The default dynamic library file name on this os.
167176
String dylibFileName(String name) {

pkgs/native_assets_cli/lib/src/code_assets/validation.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44

55
import 'dart:io';
66

7-
import '../../code_assets_builder.dart';
7+
import '../config.dart';
8+
import '../encoded_asset.dart';
9+
import '../validation.dart';
10+
import 'code_asset.dart';
11+
import 'config.dart';
812
import 'link_mode.dart';
13+
import 'link_mode_preference.dart';
14+
import 'os.dart';
915
import 'syntax.g.dart' as syntax;
1016

1117
Future<ValidationErrors> validateCodeAssetBuildInput(BuildInput input) async =>

0 commit comments

Comments
 (0)