Skip to content

Package name spacing #101

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 5 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkgs/native_assets_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Use an `out/` sub directory for building native assets
([#98](https://github.com/dart-lang/native/issues/98)).
- Check asset ids on having having a package uri with the owning package
([#96](https://github.com/dart-lang/native/issues/96)).

## 0.1.0

Expand Down
18 changes: 16 additions & 2 deletions pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class NativeAssetsBuildRunner {
targetMetadata: _metadata[target],
);
final config = await _cliConfig(
packageName: package.name,
packageRoot: packageLayout.packageRoot(package.name),
target: target,
buildMode: buildMode,
Expand All @@ -81,6 +80,7 @@ class NativeAssetsBuildRunner {
workingDirectory,
includeParentEnvironment,
);
validateAssetsPackage(assets, package.name);
assetList.addAll(assets);
}
return assetList;
Expand Down Expand Up @@ -214,7 +214,6 @@ class NativeAssetsBuildRunner {
}

static Future<BuildConfig> _cliConfig({
required String packageName,
required Uri packageRoot,
required Target target,
IOSSdk? targetIOSSdk,
Expand Down Expand Up @@ -291,6 +290,21 @@ class NativeAssetsBuildRunner {
if (dependencies.contains(entry.key)) entry.key: entry.value,
};
}

void validateAssetsPackage(List<Asset> assets, String packageName) {
final invalidAssetIds = assets
.map((a) => a.name)
.where((n) => !n.startsWith('package:$packageName/'))
.toSet()
.toList()
..sort();
if (invalidAssetIds.isNotEmpty) {
throw FormatException(
'`package:$packageName` declares the following assets which do not '
'start with `package:$packageName/`: ${invalidAssetIds.join(', ')}.',
);
}
}
}

extension on DateTime {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2023, 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 'package:native_assets_cli/native_assets_cli.dart';
import 'package:test/test.dart';

import '../helpers.dart';
import 'helpers.dart';

const Timeout longTimeout = Timeout(Duration(minutes: 5));

void main() async {
test('wrong asset id', timeout: longTimeout, () async {
await inTempDir((tempUri) async {
await copyTestProjects(targetUri: tempUri);
final packageUri = tempUri.resolve('wrong_namespace_asset/');

await runPubGet(
workingDirectory: packageUri,
logger: logger,
);

{
var buildFailed = false;
final assets = await build(packageUri, logger, dartExecutable)
.onError((error, stackTrace) {
buildFailed = true;
return [];
});
expect(buildFailed, true);
expect(assets, <Asset>[]);
}
});
});
}
2 changes: 2 additions & 0 deletions pkgs/native_assets_builder/test/data/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@
- package_reading_metadata/pubspec.yaml
- package_with_metadata/build.dart
- package_with_metadata/pubspec.yaml
- wrong_namespace_asset/build.dart
- wrong_namespace_asset/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import 'package:native_assets_cli/native_assets_cli.dart';

const packageName = 'native_add';

void main(List<String> args) async {
final buildConfig = await BuildConfig.fromArgs(args);
final buildOutput = BuildOutput(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2023, 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 'package:native_assets_cli/native_assets_cli.dart';

void main(List<String> args) async {
final buildConfig = await BuildConfig.fromArgs(args);
final buildOutput = BuildOutput(
assets: [
Asset(
name: 'package:other_package/foo',
linkMode: LinkMode.dynamic,
target: Target.current,
path: AssetAbsolutePath(
buildConfig.outDir.resolve(
Target.current.os.dylibFileName('foo'),
),
),
),
],
);
await buildOutput.writeToFile(outDir: buildConfig.outDir);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: wrong_namespace_asset
description: Package that tries to add an asset with an id not prefixed by its package name.
version: 0.1.0

publish_to: none

environment:
sdk: '>=3.0.0 <4.0.0'

dependencies:
cli_config: ^0.1.1
native_assets_cli: ^0.1.0
yaml: ^3.1.1
yaml_edit: ^2.1.0

dev_dependencies:
lints: ^2.0.0