diff --git a/_test/test/macro_test.dart b/_test/test/macro_test.dart index 3810413f4..3dd8114f4 100644 --- a/_test/test/macro_test.dart +++ b/_test/test/macro_test.dart @@ -2,9 +2,10 @@ // 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:_test/macros/debug_to_string.dart'; + import 'package:test/test.dart'; -import 'package:_test/macros/debug_to_string.dart'; void main() { test('macro stuff is generated', () { diff --git a/build_resolvers/lib/src/analysis_driver.dart b/build_resolvers/lib/src/analysis_driver.dart index 2d5faa033..48e0ade6d 100644 --- a/build_resolvers/lib/src/analysis_driver.dart +++ b/build_resolvers/lib/src/analysis_driver.dart @@ -2,6 +2,7 @@ // 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 'dart:convert'; import 'dart:io'; import 'package:analyzer/file_system/file_system.dart' show ResourceProvider; @@ -23,6 +24,24 @@ Future analysisDriver( String sdkSummaryPath, PackageConfig packageConfig, ) async { + // TODO: Necessary for kernel compilation of macros. Should the analyzer + // provide this implicitly based on its Packages instance? + buildAssetUriResolver.resourceProvider.newFile( + '/.dart_tool/package_config.json', + jsonEncode({ + 'configVersion': 2, + 'packages': [ + for (var package in packageConfig.packages) + { + 'name': package.name, + 'rootUri': 'file:///${package.name}', + 'packageUri': 'lib/', + if (package.languageVersion != null) + 'languageVersion': '${package.languageVersion!.major}.' + '${package.languageVersion!.minor}', + }, + ], + })); return createAnalysisDriver( analysisOptions: analysisOptions, packages: _buildAnalyzerPackages( diff --git a/build_resolvers/lib/src/build_asset_uri_resolver.dart b/build_resolvers/lib/src/build_asset_uri_resolver.dart index c7a9aa5bd..de3dd8c5d 100644 --- a/build_resolvers/lib/src/build_asset_uri_resolver.dart +++ b/build_resolvers/lib/src/build_asset_uri_resolver.dart @@ -261,7 +261,20 @@ Set _parseDependencies(String content, AssetId from) => HashSet.of( .whereType() .where((uriContent) => !_ignoredSchemes.any(Uri.parse(uriContent).isScheme)) - .map((content) => AssetId.resolve(Uri.parse(content), from: from)), + .map((content) => AssetId.resolve(Uri.parse(content), from: from)) + // TODO: Something better here? We assume anything depending on the + // macro APIs is a macro, and the bootstrap program we create for + // those libraries will require the macro implementations, but there + // is no transitive dependency exposed. + .followedBy( + from == AssetId('_fe_analyzer_shared', 'lib/src/macros/api.dart') + ? [ + AssetId('_fe_analyzer_shared', + 'lib/src/macros/executor/client.dart'), + AssetId('_fe_analyzer_shared', + 'lib/src/macros/executor/serialization.dart'), + ] + : const []), ); /// Read the (potentially) cached dependencies of [id] based on parsing the