Skip to content

Commit 3b3a2f6

Browse files
authored
[code_assets] [data_assets] Document absolute paths (#2712)
1 parent f7c7d52 commit 3b3a2f6

File tree

10 files changed

+44
-9
lines changed

10 files changed

+44
-9
lines changed

pkgs/code_assets/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.19.9
2+
3+
- Document that asset file paths must be absolute.
4+
15
## 0.19.8
26

37
- Polished README.md, Dartdocs, and examples.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ final class CodeAsset {
6060
/// Either dynamic loading or static linking.
6161
final LinkMode linkMode;
6262

63-
/// The file to be bundled with the Dart or Flutter application.
63+
/// The native library to be bundled with the Dart or Flutter application.
6464
///
6565
/// If the [linkMode] is [DynamicLoadingBundled], the file must be provided
66-
/// and exist.
66+
/// and exist. The path must be an absolute path. Prefer constructing the path
67+
/// via [HookInput.outputDirectoryShared] or [HookInput.outputDirectory].
6768
///
6869
/// If the [linkMode] is [DynamicLoadingSystem], the file must be provided,
6970
/// and not exist.

pkgs/code_assets/lib/src/code_assets/config.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,18 @@ final class BuildOutputCodeAssetBuilder {
165165
BuildOutputCodeAssetBuilder._(this._output);
166166

167167
/// Adds the given [asset] to the hook output with [routing].
168+
///
169+
/// The [CodeAsset.file], if provided, must be an absolute path. Prefer
170+
/// constructing the path via [HookInput.outputDirectoryShared] or
171+
/// [HookInput.outputDirectory].
168172
void add(CodeAsset asset, {AssetRouting routing = const ToAppBundle()}) =>
169173
_output.addEncodedAsset(asset.encode(), routing: routing);
170174

171175
/// Adds the given [assets] to the hook output with [routing].
176+
///
177+
/// The [CodeAsset.file]s, if provided, must be absolute paths. Prefer
178+
/// constructing the paths via [HookInput.outputDirectoryShared] or
179+
/// [HookInput.outputDirectory].
172180
void addAll(
173181
Iterable<CodeAsset> assets, {
174182
AssetRouting routing = const ToAppBundle(),

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ ValidationErrors _validateFile(
301301
}) {
302302
final errors = <String>[];
303303
if (mustBeAbsolute && !uri.isAbsolute) {
304-
errors.add('$name (${uri.toFilePath()}) must be an absolute path.');
304+
errors.add(
305+
'$name (${uri.toFilePath()}) must be an absolute path. '
306+
'Prefer constructing it via `input.outputDirectoryShared`.',
307+
);
305308
}
306309
if (mustExist && !File.fromUri(uri).existsSync()) {
307310
errors.add('$name (${uri.toFilePath()}) does not exist as a file.');

pkgs/code_assets/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: >-
33
This library contains the hook protocol specification for bundling native code
44
with Dart packages.
55
6-
version: 0.19.8
6+
version: 0.19.9
77

88
repository: https://github.com/dart-lang/native/tree/main/pkgs/code_assets
99

pkgs/data_assets/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.19.4
2+
3+
- Document that asset file paths must be absolute.
4+
15
## 0.19.3
26

37
- Added a library comment detailing how to use the package.

pkgs/data_assets/lib/src/data_assets/config.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,20 @@ final class BuildOutputDataAssetsBuilder {
119119
BuildOutputDataAssetsBuilder._(this._output);
120120

121121
/// Adds the given [asset] to the hook output with [routing].
122+
///
123+
/// The [DataAsset.file] must be an absolute path. Prefer constructing the
124+
/// path via [HookInput.outputDirectoryShared] or [HookInput.outputDirectory]
125+
/// for files emitted during a hook, and via [HookInput.packageRoot] for files
126+
/// which are part of the package.
122127
void add(DataAsset asset, {AssetRouting routing = const ToAppBundle()}) =>
123128
_output.addEncodedAsset(asset.encode(), routing: routing);
124129

125130
/// Adds the given [assets] to the hook output with [routing].
131+
///
132+
/// The [DataAsset.file]s must be absolute paths. Prefer constructing the
133+
/// path via [HookInput.outputDirectoryShared] or [HookInput.outputDirectory]
134+
/// for files emitted during a hook, and via [HookInput.packageRoot] for files
135+
/// which are part of the package.
126136
void addAll(
127137
Iterable<DataAsset> assets, {
128138
AssetRouting routing = const ToAppBundle(),

pkgs/data_assets/lib/src/data_assets/data_asset.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import 'syntax.g.dart';
1818
final class DataAsset {
1919
/// The file to be bundled with the Dart or Flutter application.
2020
///
21-
/// The file can also be omitted for asset types which refer to an asset
22-
/// already present on the target system or an asset already present in Dart
23-
/// or Flutter.
21+
/// The path must be an absolute path. Prefer constructing the path via
22+
/// [HookInput.outputDirectoryShared] or [HookInput.outputDirectory] for files
23+
/// emitted during a hook, and via [HookInput.packageRoot] for files which are
24+
/// part of the package.
2425
final Uri file;
2526

2627
/// The name of this asset, which must be unique for the package.

pkgs/data_assets/lib/src/data_assets/validation.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ ValidationErrors _validateFile(
129129
}) {
130130
final errors = <String>[];
131131
if (mustBeAbsolute && !uri.isAbsolute) {
132-
errors.add('$name (${uri.toFilePath()}) must be an absolute path.');
132+
errors.add(
133+
'$name (${uri.toFilePath()}) must be an absolute path. '
134+
'Prefer constructing it via `input.outputDirectoryShared` or '
135+
'`input.packageRoot`.',
136+
);
133137
}
134138
if (mustExist && !File.fromUri(uri).existsSync()) {
135139
errors.add('$name (${uri.toFilePath()}) does not exist as a file.');

pkgs/data_assets/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: >-
33
This library contains the hook protocol specification for bundling data assets
44
with Dart packages.
55
6-
version: 0.19.3
6+
version: 0.19.4
77

88
repository: https://github.com/dart-lang/native/tree/main/pkgs/data_assets
99

0 commit comments

Comments
 (0)