mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 21:50:11 +00:00
update kernel worker to support -D environment defines
Change-Id: Ic73cfcc8dc0bd8b721733e0696b028aa572125e0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121927 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Jake Macdonald <jakemac@google.com>
This commit is contained in:
parent
ffcfab3093
commit
22e249d4d5
|
@ -68,6 +68,7 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
|
|||
FileSystem fileSystem,
|
||||
Iterable<String> experiments,
|
||||
bool outlineOnly,
|
||||
Map<String, String> environmentDefines,
|
||||
{bool trackNeededDillLibraries: false}) async {
|
||||
List<Component> outputLoadedInputSummaries =
|
||||
new List<Component>(summaryInputs.length);
|
||||
|
@ -88,7 +89,8 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
|
|||
experimentalFlags: experimentalFlags,
|
||||
outlineOnly: outlineOnly,
|
||||
omitPlatform: true,
|
||||
trackNeededDillLibraries: trackNeededDillLibraries);
|
||||
trackNeededDillLibraries: trackNeededDillLibraries,
|
||||
environmentDefines: environmentDefines);
|
||||
}
|
||||
|
||||
Future<InitializedCompilerState> initializeCompiler(
|
||||
|
@ -100,7 +102,8 @@ Future<InitializedCompilerState> initializeCompiler(
|
|||
List<Uri> linkedInputs,
|
||||
Target target,
|
||||
FileSystem fileSystem,
|
||||
Iterable<String> experiments) async {
|
||||
Iterable<String> experiments,
|
||||
Map<String, String> environmentDefines) async {
|
||||
// TODO(sigmund): use incremental compiler when it supports our use case.
|
||||
// Note: it is common for the summary worker to invoke the compiler with the
|
||||
// same input summary URIs, but with different contents, so we'd need to be
|
||||
|
@ -114,7 +117,7 @@ Future<InitializedCompilerState> initializeCompiler(
|
|||
..linkedDependencies = linkedInputs
|
||||
..target = target
|
||||
..fileSystem = fileSystem
|
||||
..environmentDefines = const {}
|
||||
..environmentDefines = environmentDefines
|
||||
..experimentalFlags = parseExperimentalFlags(
|
||||
parseExperimentalArguments(experiments),
|
||||
onError: (e) => throw e);
|
||||
|
|
|
@ -142,7 +142,8 @@ final summaryArgsParser = new ArgParser()
|
|||
..addOption('used-inputs')
|
||||
..addFlag('track-widget-creation', defaultsTo: false)
|
||||
..addMultiOption('enable-experiment',
|
||||
help: 'Enable a language experiment when invoking the CFE.');
|
||||
help: 'Enable a language experiment when invoking the CFE.')
|
||||
..addMultiOption('define', abbr: 'D');
|
||||
|
||||
class ComputeKernelResult {
|
||||
final bool succeeded;
|
||||
|
@ -166,6 +167,7 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
|
|||
fe.InitializedCompilerState previousState}) async {
|
||||
dynamic out = outputBuffer ?? stderr;
|
||||
bool succeeded = true;
|
||||
|
||||
var parsedArgs = summaryArgsParser.parse(args);
|
||||
|
||||
if (parsedArgs['help']) {
|
||||
|
@ -244,6 +246,8 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
|
|||
fe.InitializedCompilerState state;
|
||||
bool usingIncrementalCompiler = false;
|
||||
bool recordUsedInputs = parsedArgs["used-inputs"] != null;
|
||||
var environmentDefines = _parseEnvironmentDefines(parsedArgs['define']);
|
||||
|
||||
if (parsedArgs['use-incremental-compiler']) {
|
||||
usingIncrementalCompiler = true;
|
||||
|
||||
|
@ -286,6 +290,7 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
|
|||
fileSystem,
|
||||
(parsedArgs['enable-experiment'] as List<String>),
|
||||
summaryOnly,
|
||||
environmentDefines,
|
||||
trackNeededDillLibraries: recordUsedInputs);
|
||||
} else {
|
||||
state = await fe.initializeCompiler(
|
||||
|
@ -298,7 +303,8 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
|
|||
linkedInputs,
|
||||
target,
|
||||
fileSystem,
|
||||
(parsedArgs['enable-experiment'] as List<String>));
|
||||
parsedArgs['enable-experiment'] as List<String>,
|
||||
environmentDefines);
|
||||
}
|
||||
|
||||
void onDiagnostic(fe.DiagnosticMessage message) {
|
||||
|
@ -448,3 +454,20 @@ Uri _toUri(String uriString) {
|
|||
// concatenated with Unix-style paths.
|
||||
return Uri.base.resolve(uriString.replaceAll("\\", "/"));
|
||||
}
|
||||
|
||||
Map<String, String> _parseEnvironmentDefines(List<String> args) {
|
||||
var environment = <String, String>{};
|
||||
|
||||
for (var arg in args) {
|
||||
var eq = arg.indexOf('=');
|
||||
if (eq <= 0) {
|
||||
var kind = eq == 0 ? 'name' : 'value';
|
||||
throw FormatException('no $kind given to -D option `$arg`');
|
||||
}
|
||||
var name = arg.substring(0, eq);
|
||||
var value = arg.substring(eq + 1);
|
||||
environment[name] = value;
|
||||
}
|
||||
|
||||
return environment;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue