Skip to content

Commit

Permalink
[native_assets_builder] Handle non-existing package names (#844)
Browse files Browse the repository at this point in the history
With `dart/flutter run dont_exist`, dartdev or flutter_tools might pass a package name to `runPackageName` that is not in the package graph.
  • Loading branch information
dcharkes authored Dec 1, 2023
1 parent ec9e2b2 commit 5aeab29
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class PackageGraph {
graphs.stronglyConnectedComponents(vertices, neighborsOf);

PackageGraph subGraph(String rootPackageName) {
if (!vertices.contains(rootPackageName)) {
// Some downstream tooling requested a package that doesn't exist.
// This will likely lead to an error, so avoid building native assets.
return PackageGraph({});
}
final subgraphVertices = [
...graphs.transitiveClosure(vertices, neighborsOf)[rootPackageName]!,
rootPackageName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,32 @@ void main() async {
});
});

test('runPackageName', () async {
await inTempDir((tempUri) async {
await copyTestProjects(targetUri: tempUri);
final nativeAddUri = tempUri.resolve('native_add/');
for (final existing in [true, false]) {
final runPackageName = existing ? 'ffigen' : 'does_not_exist';
test('runPackageName $runPackageName', () async {
await inTempDir((tempUri) async {
await copyTestProjects(targetUri: tempUri);
final nativeAddUri = tempUri.resolve('native_add/');

// First, run `pub get`, we need pub to resolve our dependencies.
await runPubGet(workingDirectory: nativeAddUri, logger: logger);
// First, run `pub get`, we need pub to resolve our dependencies.
await runPubGet(workingDirectory: nativeAddUri, logger: logger);

final packageLayout =
await PackageLayout.fromRootPackageRoot(nativeAddUri);
final packagesWithNativeAssets =
await packageLayout.packagesWithNativeAssets;
final nativeAssetsBuildPlanner =
await NativeAssetsBuildPlanner.fromRootPackageRoot(
rootPackageRoot: nativeAddUri,
packagesWithNativeAssets: packagesWithNativeAssets,
dartExecutable: Uri.file(Platform.resolvedExecutable),
logger: logger,
);
final (buildPlan, _) = nativeAssetsBuildPlanner.plan(
runPackageName: 'ffigen',
);
expect(buildPlan.length, 0);
final packageLayout =
await PackageLayout.fromRootPackageRoot(nativeAddUri);
final packagesWithNativeAssets =
await packageLayout.packagesWithNativeAssets;
final nativeAssetsBuildPlanner =
await NativeAssetsBuildPlanner.fromRootPackageRoot(
rootPackageRoot: nativeAddUri,
packagesWithNativeAssets: packagesWithNativeAssets,
dartExecutable: Uri.file(Platform.resolvedExecutable),
logger: logger,
);
final (buildPlan, _) = nativeAssetsBuildPlanner.plan(
runPackageName: runPackageName,
);
expect(buildPlan.length, 0);
});
});
});
}
}

0 comments on commit 5aeab29

Please sign in to comment.