Skip to content

Commit

Permalink
[ddk] Pass environmentDefines to CFE through CompilerOptions
Browse files Browse the repository at this point in the history
CFE needs to have access to them to be able to perform constant
evaluation.

Bug: #37357
Change-Id: I15705e6fda330a05765ec2e8354051276cb88b07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108278
Auto-Submit: Vyacheslav Egorov <[email protected]>
Reviewed-by: Vijay Menon <[email protected]>
Reviewed-by: Jens Johansen <[email protected]>
Commit-Queue: Vyacheslav Egorov <[email protected]>
  • Loading branch information
mraleph authored and [email protected] committed Jul 9, 2019
1 parent 5450d08 commit fce43eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions pkg/dev_compiler/lib/src/kernel/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ Future<CompilerResult> _compile(List<String> args,
DevCompilerTarget(
TargetFlags(trackWidgetCreation: trackWidgetCreation)),
fileSystem: fileSystem,
experiments: experiments);
experiments: experiments,
environmentDefines: declaredVariables);
} else {
doneInputSummaries = List<Component>(summaryModules.length);
compilerState = await fe.initializeIncrementalCompiler(
Expand All @@ -262,7 +263,8 @@ Future<CompilerResult> _compile(List<String> args,
DevCompilerTarget(
TargetFlags(trackWidgetCreation: trackWidgetCreation)),
fileSystem: fileSystem,
experiments: experiments);
experiments: experiments,
environmentDefines: declaredVariables);
incrementalCompiler = compilerState.incrementalCompiler;
cachedSdkInput =
compilerState.workerInputCache[sourcePathToUri(sdkSummaryPath)];
Expand Down
18 changes: 12 additions & 6 deletions pkg/front_end/lib/src/api_unstable/ddc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ Future<InitializedCompilerState> initializeCompiler(
List<Uri> inputSummaries,
Target target,
{FileSystem fileSystem,
Map<ExperimentalFlag, bool> experiments}) async {
Map<ExperimentalFlag, bool> experiments,
Map<String, String> environmentDefines}) async {
inputSummaries.sort((a, b) => a.toString().compareTo(b.toString()));

if (oldState != null &&
Expand All @@ -90,7 +91,8 @@ Future<InitializedCompilerState> initializeCompiler(
oldState.options.packagesFileUri == packagesFile &&
oldState.options.librariesSpecificationUri == librariesSpecificationUri &&
equalLists(oldState.options.inputSummaries, inputSummaries) &&
equalMaps(oldState.options.experimentalFlags, experiments)) {
equalMaps(oldState.options.experimentalFlags, experiments) &&
equalMaps(oldState.options.environmentDefines, environmentDefines)) {
// Reuse old state.

// These libraries are marked external when compiling. If not un-marking
Expand All @@ -114,7 +116,8 @@ Future<InitializedCompilerState> initializeCompiler(
..inputSummaries = inputSummaries
..librariesSpecificationUri = librariesSpecificationUri
..target = target
..fileSystem = fileSystem ?? StandardFileSystem.instance;
..fileSystem = fileSystem ?? StandardFileSystem.instance
..environmentDefines = environmentDefines;
if (experiments != null) options.experimentalFlags = experiments;

ProcessedOptions processedOpts = new ProcessedOptions(options: options);
Expand All @@ -134,7 +137,8 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
Map<Uri, List<int>> workerInputDigests,
Target target,
{FileSystem fileSystem,
Map<ExperimentalFlag, bool> experiments}) async {
Map<ExperimentalFlag, bool> experiments,
Map<String, String> environmentDefines}) async {
inputSummaries.sort((a, b) => a.toString().compareTo(b.toString()));

IncrementalCompiler incrementalCompiler;
Expand All @@ -156,7 +160,8 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
oldState.options.compileSdk != compileSdk ||
cachedSdkInput == null ||
!digestsEqual(cachedSdkInput.digest, sdkDigest) ||
!equalMaps(oldState.options.experimentalFlags, experiments)) {
!equalMaps(oldState.options.experimentalFlags, experiments) ||
!equalMaps(oldState.options.environmentDefines, environmentDefines)) {
// No previous state.
options = new CompilerOptions()
..compileSdk = compileSdk
Expand All @@ -166,7 +171,8 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
..inputSummaries = inputSummaries
..librariesSpecificationUri = librariesSpecificationUri
..target = target
..fileSystem = fileSystem ?? StandardFileSystem.instance;
..fileSystem = fileSystem ?? StandardFileSystem.instance
..environmentDefines = environmentDefines;
if (experiments != null) options.experimentalFlags = experiments;

// We'll load a new sdk, anything loaded already will have a wrong root.
Expand Down

0 comments on commit fce43eb

Please sign in to comment.