create static method
Future<BuildOptions>
create(
- LogSubscription logSubscription, {
- Duration debounceDelay = const Duration(milliseconds: 250),
- bool deleteFilesByDefault = false,
- bool enableLowResourcesMode = false,
- required PackageGraph packageGraph,
- Map<
String, BuildConfig> overrideBuildConfig = const {}, - bool skipBuildScriptCheck = false,
- bool trackPerformance = false,
- String? logPerformanceDir,
- Resolvers? resolvers,
Creates a BuildOptions
with sane defaults.
NOTE: If a custom resolvers
instance is passed it must ensure that it
enables enabledExperiments
on any analysis options it creates.
Implementation
static Future<BuildOptions> create(
LogSubscription logSubscription, {
Duration debounceDelay = const Duration(milliseconds: 250),
bool deleteFilesByDefault = false,
bool enableLowResourcesMode = false,
required PackageGraph packageGraph,
Map<String, BuildConfig> overrideBuildConfig = const {},
bool skipBuildScriptCheck = false,
bool trackPerformance = false,
String? logPerformanceDir,
Resolvers? resolvers,
}) async {
TargetGraph targetGraph;
try {
targetGraph = await TargetGraph.forPackageGraph(packageGraph,
overrideBuildConfig: overrideBuildConfig,
defaultRootPackageSources: defaultRootPackageSources,
requiredSourcePaths: [r'lib/$lib$'],
requiredRootSourcePaths: [r'$package$', r'lib/$lib$']);
} on BuildConfigParseException catch (e, s) {
_logger.severe('''
Failed to parse `build.yaml` for ${e.packageName}.
If you believe you have gotten this message in error, especially if using a new
feature, you may need to run `dart run build_runner clean` and then rebuild.
''', e.exception, s);
throw const CannotBuildException();
}
/// Set up other defaults.
if (logPerformanceDir != null) {
// Requiring this to be under the root package allows us to use an
// `AssetWriter` to write logs.
if (!p.isWithin(p.current, logPerformanceDir)) {
_logger.severe('Performance logs may only be output under the root '
'package, but got `$logPerformanceDir` which is not.');
throw const CannotBuildException();
}
trackPerformance = true;
}
resolvers ??= AnalyzerResolvers.sharedInstance;
return BuildOptions._(
debounceDelay: debounceDelay,
deleteFilesByDefault: deleteFilesByDefault,
enableLowResourcesMode: enableLowResourcesMode,
logListener: logSubscription.logListener,
packageGraph: packageGraph,
skipBuildScriptCheck: skipBuildScriptCheck,
trackPerformance: trackPerformance,
targetGraph: targetGraph,
logPerformanceDir: logPerformanceDir,
resolvers: resolvers,
);
}