buildSdkSummary function
Future<Uint8List>
buildSdkSummary({
- required ResourceProvider resourceProvider,
- required String sdkPath,
- String? embedderYamlPath,
Build summary for SDK at the given sdkPath
.
If embedderYamlPath
is provided, then libraries from this file are
appended to the libraries of the specified SDK.
Implementation
Future<Uint8List> buildSdkSummary({
required ResourceProvider resourceProvider,
required String sdkPath,
String? embedderYamlPath,
}) async {
var sdk = FolderBasedDartSdk(
resourceProvider,
resourceProvider.getFolder(sdkPath),
);
// Append libraries from the embedder.
if (embedderYamlPath != null) {
var file = resourceProvider.getFile(embedderYamlPath);
var content = file.readAsStringSync();
var map = loadYaml(content) as YamlMap;
var embedderSdk = EmbedderSdk(
resourceProvider,
{file.parent: map},
languageVersion: sdk.languageVersion,
);
for (var library in embedderSdk.sdkLibraries) {
var uriStr = library.shortName;
if (sdk.libraryMap.getLibrary(uriStr) == null) {
sdk.libraryMap.setLibrary(uriStr, library);
}
}
}
final logger = PerformanceLog(StringBuffer());
final scheduler = AnalysisDriverScheduler(logger);
final analysisDriver = AnalysisDriver(
scheduler: scheduler,
logger: logger,
resourceProvider: resourceProvider,
byteStore: MemoryByteStore(),
sourceFactory: SourceFactory([
DartUriResolver(sdk),
]),
analysisOptions: AnalysisOptionsImpl(),
packages: Packages({}),
);
scheduler.start();
final libraryUriList = sdk.uris.map(Uri.parse).toList();
return await analysisDriver.buildPackageBundle(
uriList: libraryUriList,
packageBundleSdk: PackageBundleSdk(
languageVersionMajor: sdk.languageVersion.major,
languageVersionMinor: sdk.languageVersion.minor,
allowedExperimentsJson: sdk.allowedExperimentsJson,
),
);
}