Skip to content

Commit

Permalink
provide a valid package config and extra dependencies for macro compi…
Browse files Browse the repository at this point in the history
…lation
  • Loading branch information
jakemac53 committed Feb 20, 2024
1 parent 1c895c3 commit 109769b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion _test/test/macro_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down
19 changes: 19 additions & 0 deletions build_resolvers/lib/src/analysis_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +24,24 @@ Future<AnalysisDriverForPackageBuild> 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(
Expand Down
15 changes: 14 additions & 1 deletion build_resolvers/lib/src/build_asset_uri_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,20 @@ Set<AssetId> _parseDependencies(String content, AssetId from) => HashSet.of(
.whereType<String>()
.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
Expand Down

0 comments on commit 109769b

Please sign in to comment.