diff --git a/pkgs/code_assets/CHANGELOG.md b/pkgs/code_assets/CHANGELOG.md index e67e3b88a..45b482537 100644 --- a/pkgs/code_assets/CHANGELOG.md +++ b/pkgs/code_assets/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.19.9 + +- Document that asset file paths must be absolute. + ## 0.19.8 - Polished README.md, Dartdocs, and examples. diff --git a/pkgs/code_assets/lib/src/code_assets/code_asset.dart b/pkgs/code_assets/lib/src/code_assets/code_asset.dart index 1aec76d8c..04c893dcd 100644 --- a/pkgs/code_assets/lib/src/code_assets/code_asset.dart +++ b/pkgs/code_assets/lib/src/code_assets/code_asset.dart @@ -60,10 +60,11 @@ final class CodeAsset { /// Either dynamic loading or static linking. final LinkMode linkMode; - /// The file to be bundled with the Dart or Flutter application. + /// The native library to be bundled with the Dart or Flutter application. /// /// If the [linkMode] is [DynamicLoadingBundled], the file must be provided - /// and exist. + /// and exist. The path must be an absolute path. Prefer constructing the path + /// via [HookInput.outputDirectoryShared] or [HookInput.outputDirectory]. /// /// If the [linkMode] is [DynamicLoadingSystem], the file must be provided, /// and not exist. diff --git a/pkgs/code_assets/lib/src/code_assets/config.dart b/pkgs/code_assets/lib/src/code_assets/config.dart index 1d7a15624..78772cf83 100644 --- a/pkgs/code_assets/lib/src/code_assets/config.dart +++ b/pkgs/code_assets/lib/src/code_assets/config.dart @@ -165,10 +165,18 @@ final class BuildOutputCodeAssetBuilder { BuildOutputCodeAssetBuilder._(this._output); /// Adds the given [asset] to the hook output with [routing]. + /// + /// The [CodeAsset.file], if provided, must be an absolute path. Prefer + /// constructing the path via [HookInput.outputDirectoryShared] or + /// [HookInput.outputDirectory]. void add(CodeAsset asset, {AssetRouting routing = const ToAppBundle()}) => _output.addEncodedAsset(asset.encode(), routing: routing); /// Adds the given [assets] to the hook output with [routing]. + /// + /// The [CodeAsset.file]s, if provided, must be absolute paths. Prefer + /// constructing the paths via [HookInput.outputDirectoryShared] or + /// [HookInput.outputDirectory]. void addAll( Iterable assets, { AssetRouting routing = const ToAppBundle(), diff --git a/pkgs/code_assets/lib/src/code_assets/validation.dart b/pkgs/code_assets/lib/src/code_assets/validation.dart index 86b6d3d12..432b2ae45 100644 --- a/pkgs/code_assets/lib/src/code_assets/validation.dart +++ b/pkgs/code_assets/lib/src/code_assets/validation.dart @@ -301,7 +301,10 @@ ValidationErrors _validateFile( }) { final errors = []; if (mustBeAbsolute && !uri.isAbsolute) { - errors.add('$name (${uri.toFilePath()}) must be an absolute path.'); + errors.add( + '$name (${uri.toFilePath()}) must be an absolute path. ' + 'Prefer constructing it via `input.outputDirectoryShared`.', + ); } if (mustExist && !File.fromUri(uri).existsSync()) { errors.add('$name (${uri.toFilePath()}) does not exist as a file.'); diff --git a/pkgs/code_assets/pubspec.yaml b/pkgs/code_assets/pubspec.yaml index 4b04c8cad..ac7cab11e 100644 --- a/pkgs/code_assets/pubspec.yaml +++ b/pkgs/code_assets/pubspec.yaml @@ -3,7 +3,7 @@ description: >- This library contains the hook protocol specification for bundling native code with Dart packages. -version: 0.19.8 +version: 0.19.9 repository: https://github.com/dart-lang/native/tree/main/pkgs/code_assets diff --git a/pkgs/data_assets/CHANGELOG.md b/pkgs/data_assets/CHANGELOG.md index 564be0099..1b999e6b2 100644 --- a/pkgs/data_assets/CHANGELOG.md +++ b/pkgs/data_assets/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.19.4 + +- Document that asset file paths must be absolute. + ## 0.19.3 - Added a library comment detailing how to use the package. diff --git a/pkgs/data_assets/lib/src/data_assets/config.dart b/pkgs/data_assets/lib/src/data_assets/config.dart index a4ac3d319..8d691328d 100644 --- a/pkgs/data_assets/lib/src/data_assets/config.dart +++ b/pkgs/data_assets/lib/src/data_assets/config.dart @@ -119,10 +119,20 @@ final class BuildOutputDataAssetsBuilder { BuildOutputDataAssetsBuilder._(this._output); /// Adds the given [asset] to the hook output with [routing]. + /// + /// The [DataAsset.file] must be an absolute path. Prefer constructing the + /// path via [HookInput.outputDirectoryShared] or [HookInput.outputDirectory] + /// for files emitted during a hook, and via [HookInput.packageRoot] for files + /// which are part of the package. void add(DataAsset asset, {AssetRouting routing = const ToAppBundle()}) => _output.addEncodedAsset(asset.encode(), routing: routing); /// Adds the given [assets] to the hook output with [routing]. + /// + /// The [DataAsset.file]s must be absolute paths. Prefer constructing the + /// path via [HookInput.outputDirectoryShared] or [HookInput.outputDirectory] + /// for files emitted during a hook, and via [HookInput.packageRoot] for files + /// which are part of the package. void addAll( Iterable assets, { AssetRouting routing = const ToAppBundle(), diff --git a/pkgs/data_assets/lib/src/data_assets/data_asset.dart b/pkgs/data_assets/lib/src/data_assets/data_asset.dart index 90961df62..df811b82c 100644 --- a/pkgs/data_assets/lib/src/data_assets/data_asset.dart +++ b/pkgs/data_assets/lib/src/data_assets/data_asset.dart @@ -18,9 +18,10 @@ import 'syntax.g.dart'; final class DataAsset { /// The file to be bundled with the Dart or Flutter application. /// - /// The file can also be omitted for asset types which refer to an asset - /// already present on the target system or an asset already present in Dart - /// or Flutter. + /// The path must be an absolute path. Prefer constructing the path via + /// [HookInput.outputDirectoryShared] or [HookInput.outputDirectory] for files + /// emitted during a hook, and via [HookInput.packageRoot] for files which are + /// part of the package. final Uri file; /// The name of this asset, which must be unique for the package. diff --git a/pkgs/data_assets/lib/src/data_assets/validation.dart b/pkgs/data_assets/lib/src/data_assets/validation.dart index 40f6fb4b5..4f46e8bdc 100644 --- a/pkgs/data_assets/lib/src/data_assets/validation.dart +++ b/pkgs/data_assets/lib/src/data_assets/validation.dart @@ -129,7 +129,11 @@ ValidationErrors _validateFile( }) { final errors = []; if (mustBeAbsolute && !uri.isAbsolute) { - errors.add('$name (${uri.toFilePath()}) must be an absolute path.'); + errors.add( + '$name (${uri.toFilePath()}) must be an absolute path. ' + 'Prefer constructing it via `input.outputDirectoryShared` or ' + '`input.packageRoot`.', + ); } if (mustExist && !File.fromUri(uri).existsSync()) { errors.add('$name (${uri.toFilePath()}) does not exist as a file.'); diff --git a/pkgs/data_assets/pubspec.yaml b/pkgs/data_assets/pubspec.yaml index 3885fcc1e..0dd43ccb3 100644 --- a/pkgs/data_assets/pubspec.yaml +++ b/pkgs/data_assets/pubspec.yaml @@ -3,7 +3,7 @@ description: >- This library contains the hook protocol specification for bundling data assets with Dart packages. -version: 0.19.3 +version: 0.19.4 repository: https://github.com/dart-lang/native/tree/main/pkgs/data_assets