mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
e681abace9
TEST=N/A Change-Id: I7440c1165a7403aad023f002a97c90572cb66c59 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205820 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com>
92 lines
3.3 KiB
Dart
92 lines
3.3 KiB
Dart
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
|
|
// 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.
|
|
|
|
// @dart = 2.9
|
|
|
|
import 'package:cli_util/cli_util.dart';
|
|
import 'package:dev_compiler/dev_compiler.dart';
|
|
import 'package:front_end/src/api_unstable/ddc.dart';
|
|
import 'package:front_end/src/compute_platform_binaries_location.dart';
|
|
import 'package:front_end/src/fasta/incremental_serializer.dart';
|
|
import 'package:kernel/ast.dart' show Component;
|
|
import 'package:kernel/target/targets.dart';
|
|
import 'package:path/path.dart' as p;
|
|
|
|
class DevelopmentIncrementalCompiler extends IncrementalCompiler {
|
|
Uri entryPoint;
|
|
|
|
DevelopmentIncrementalCompiler(CompilerOptions options, this.entryPoint,
|
|
[Uri initializeFrom,
|
|
bool outlineOnly,
|
|
IncrementalSerializer incrementalSerializer])
|
|
: super(
|
|
CompilerContext(
|
|
ProcessedOptions(options: options, inputs: [entryPoint])),
|
|
initializeFrom,
|
|
outlineOnly,
|
|
incrementalSerializer);
|
|
|
|
DevelopmentIncrementalCompiler.fromComponent(CompilerOptions options,
|
|
this.entryPoint, Component componentToInitializeFrom,
|
|
[bool outlineOnly, IncrementalSerializer incrementalSerializer])
|
|
: super.fromComponent(
|
|
CompilerContext(
|
|
ProcessedOptions(options: options, inputs: [entryPoint])),
|
|
componentToInitializeFrom,
|
|
outlineOnly,
|
|
incrementalSerializer);
|
|
}
|
|
|
|
class SetupCompilerOptions {
|
|
static final sdkRoot = computePlatformBinariesLocation();
|
|
static final sdkUnsoundSummaryPath = p.join(sdkRoot.path, 'ddc_sdk.dill');
|
|
static final sdkSoundSummaryPath =
|
|
p.join(sdkRoot.path, 'ddc_outline_sound.dill');
|
|
static final librariesSpecificationUri =
|
|
p.join(p.dirname(p.dirname(getSdkPath())), 'libraries.json');
|
|
|
|
static CompilerOptions getOptions(bool soundNullSafety) {
|
|
var options = CompilerOptions()
|
|
..verbose = false // set to true for debugging
|
|
..sdkRoot = sdkRoot
|
|
..target = DevCompilerTarget(TargetFlags())
|
|
..librariesSpecificationUri = Uri.base.resolve('sdk/lib/libraries.json')
|
|
..omitPlatform = true
|
|
..sdkSummary = sdkRoot.resolve(
|
|
soundNullSafety ? sdkSoundSummaryPath : sdkUnsoundSummaryPath)
|
|
..environmentDefines = const {}
|
|
..nnbdMode = soundNullSafety ? NnbdMode.Strong : NnbdMode.Weak;
|
|
return options;
|
|
}
|
|
|
|
static final String dartUnsoundComment = '// @dart = 2.9';
|
|
static final String dartSoundComment = '//';
|
|
|
|
final List<String> errors = [];
|
|
final CompilerOptions options;
|
|
final String dartLangComment;
|
|
final ModuleFormat moduleFormat;
|
|
final bool soundNullSafety;
|
|
|
|
SetupCompilerOptions(
|
|
{this.soundNullSafety = true, this.moduleFormat = ModuleFormat.amd})
|
|
: options = getOptions(soundNullSafety),
|
|
dartLangComment =
|
|
soundNullSafety ? dartSoundComment : dartUnsoundComment {
|
|
options.onDiagnostic = (DiagnosticMessage m) {
|
|
errors.addAll(m.plainTextFormatted);
|
|
};
|
|
}
|
|
|
|
String get loadModule {
|
|
switch (moduleFormat) {
|
|
case ModuleFormat.amd:
|
|
return 'require';
|
|
case ModuleFormat.ddc:
|
|
return 'dart_library.import';
|
|
default:
|
|
throw UnsupportedError('Module format: $moduleFormat');
|
|
}
|
|
}
|
|
}
|