Skip to content

Prepare for dart 3.0 alpha changes: generate assets #1887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 70 additions & 70 deletions .github/workflows/dart.yml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
- Add back `ChromeProxyService.setExceptionPauseMode()` without override.
- Make hot restart atomic to prevent races on simultaneous execution.
- Return error on expression evaluation if expression evaluator stopped.
- Prepare for Dart 3 alpha breaking changes:
- Generate missing SDK assets for tests.
- Enable frontend server null safe tests.

**Breaking changes**
- Include an optional param to `Dwds.start` to indicate whether it is running
internally or externally.
- Include an optional param to `Dwds.start` to indicate whether it a Flutter app
or not.
- Remove deprecated `ChromeProxyService.setExceptionPauseMode()`.
- Replace `SdkConfiguration.unsoundSdkSummaryPath` with
`SdkConfiguration.weakSdkSummaryPath`.

## 16.0.1

Expand Down
4 changes: 2 additions & 2 deletions dwds/lib/dart_web_debug_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ class Dwds {
bool enableDevtoolsLaunch = true,
DevtoolsLauncher? devtoolsLauncher,
bool launchDevToolsInNewWindow = true,
SdkConfigurationProvider? sdkConfigurationProvider,
SdkConfigurationProvider sdkConfigurationProvider =
const DefaultSdkConfigurationProvider(),
bool emitDebugEvents = true,
bool isInternalBuild = false,
bool isFlutterApp = false,
}) async {
globalLoadStrategy = loadStrategy;
sdkConfigurationProvider ??= DefaultSdkConfigurationProvider();

DevTools? devTools;
Future<String>? extensionUri;
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/dwds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ export 'src/services/expression_compiler.dart'
export 'src/services/expression_compiler_service.dart'
show ExpressionCompilerService;
export 'src/utilities/sdk_configuration.dart'
show SdkConfiguration, SdkConfigurationProvider;
show SdkLayout, SdkConfiguration, SdkConfigurationProvider;
8 changes: 4 additions & 4 deletions dwds/lib/src/services/expression_compiler_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class _Compiler {
final workerUri = sdkConfiguration.compilerWorkerUri!;
final sdkSummaryUri = soundNullSafety
? sdkConfiguration.soundSdkSummaryUri!
: sdkConfiguration.unsoundSdkSummaryUri!;
: sdkConfiguration.weakSdkSummaryUri!;

final args = [
'--experimental-expression-compiler',
Expand Down Expand Up @@ -241,11 +241,11 @@ class ExpressionCompilerService implements ExpressionCompiler {
this._address,
this._port, {
bool verbose = false,
SdkConfigurationProvider? sdkConfigurationProvider,
SdkConfigurationProvider sdkConfigurationProvider =
const DefaultSdkConfigurationProvider(),
this.experiments = const [],
}) : _verbose = verbose,
_sdkConfigurationProvider =
sdkConfigurationProvider ?? DefaultSdkConfigurationProvider();
_sdkConfigurationProvider = sdkConfigurationProvider;

@override
Future<ExpressionCompilationResult> compileExpressionToJs(
Expand Down
186 changes: 154 additions & 32 deletions dwds/lib/src/utilities/sdk_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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.

import 'dart:async';
import 'dart:io';

import 'package:file/file.dart';
Expand All @@ -24,42 +25,171 @@ class InvalidSdkConfigurationException implements Exception {
/// SDK configuration provider interface.
///
/// Supports lazily populated configurations by allowing to create
/// configuration asyncronously.
/// configuration asynchronously.
abstract class SdkConfigurationProvider {
const SdkConfigurationProvider();

Future<SdkConfiguration> get configuration;
}

/// Sdk layout.
///
/// Contains definition of the default SDK layout.
/// We keep all the path constants in one place for ease of update.
class SdkLayout {
static final sdkDir = p.dirname(p.dirname(Platform.resolvedExecutable));
static final defaultSdkLayout = createDefault(sdkDir);

static SdkLayout createDefault(String sdkDirectory) {
final sdkJsWeakFileName = 'dart_sdk.js';
final sdkJsMapWeakFileName = 'dart_sdk.js.map';
final sdkJsSoundFileName = 'dart_sdk_sound.js';
final sdkJsMapSoundFileName = 'dart_sdk_sound.js.map';
final sdkSummarySoundFileName = 'ddc_outline_sound.dill';
final sdkSummaryWeakFileName = 'ddc_sdk.dill';
final sdkFullDillSoundFileName = 'ddc_platform_sound.dill';
final sdkFullDillWeakFileName = 'ddc_platform.dill';

final sdkSummaryDirectory = p.join(sdkDirectory, 'lib', '_internal');
final sdkJsDirectory =
p.join(sdkDirectory, 'lib', 'dev_compiler', 'kernel', 'amd');

final soundSummaryPath =
p.join(sdkSummaryDirectory, sdkSummarySoundFileName);
final soundFullDillPath =
p.join(sdkSummaryDirectory, sdkFullDillSoundFileName);
final soundJsPath = p.join(sdkJsDirectory, sdkJsSoundFileName);
final soundJsMapPath = p.join(sdkJsDirectory, sdkJsMapSoundFileName);

final weakSummaryPath = p.join(sdkSummaryDirectory, sdkSummaryWeakFileName);
final weakFullDillPath =
p.join(sdkSummaryDirectory, sdkFullDillWeakFileName);
final weakJsPath = p.join(sdkJsDirectory, sdkJsWeakFileName);
final weakJsMapPath = p.join(sdkJsDirectory, sdkJsMapWeakFileName);

final librariesPath = p.join(sdkDirectory, 'lib', 'libraries.json');
final dartdevcSnapshotPath =
p.join(sdkDirectory, 'bin', 'snapshots', 'dartdevc.dart.snapshot');
final kernelWorkerSnapshotPath =
p.join(sdkDirectory, 'bin', 'snapshots', 'kernel_worker.dart.snapshot');

return SdkLayout(
sdkJsWeakFileName: sdkJsWeakFileName,
sdkJsMapWeakFileName: sdkJsMapWeakFileName,
sdkJsSoundFileName: sdkJsSoundFileName,
sdkJsMapSoundFileName: sdkJsMapSoundFileName,
sdkSummarySoundFileName: sdkSummarySoundFileName,
sdkSummaryWeakFileName: sdkSummaryWeakFileName,
sdkFullDillSoundFileName: sdkFullDillSoundFileName,
sdkFullDillWeakFileName: sdkFullDillWeakFileName,
sdkDirectory: sdkDirectory,
soundSummaryPath: soundSummaryPath,
soundFullDillPath: soundFullDillPath,
soundJsPath: soundJsPath,
soundJsMapPath: soundJsMapPath,
weakSummaryPath: weakSummaryPath,
weakFullDillPath: weakFullDillPath,
weakJsPath: weakJsPath,
weakJsMapPath: weakJsMapPath,
librariesPath: librariesPath,
dartdevcSnapshotPath: dartdevcSnapshotPath,
kernelWorkerSnapshotPath: kernelWorkerSnapshotPath,
);
}

final String sdkJsWeakFileName;
final String sdkJsMapWeakFileName;
final String sdkJsSoundFileName;
final String sdkJsMapSoundFileName;
final String sdkSummarySoundFileName;
final String sdkSummaryWeakFileName;
final String sdkFullDillSoundFileName;
final String sdkFullDillWeakFileName;

final String sdkDirectory;

final String soundSummaryPath;
final String soundFullDillPath;
final String soundJsPath;
final String soundJsMapPath;

final String weakSummaryPath;
final String weakFullDillPath;
final String weakJsPath;
final String weakJsMapPath;

final String librariesPath;

final String dartdevcSnapshotPath;
final String kernelWorkerSnapshotPath;

SdkLayout({
required this.sdkJsWeakFileName,
required this.sdkJsMapWeakFileName,
required this.sdkJsSoundFileName,
required this.sdkJsMapSoundFileName,
required this.sdkSummarySoundFileName,
required this.sdkSummaryWeakFileName,
required this.sdkFullDillSoundFileName,
required this.sdkFullDillWeakFileName,
required this.sdkDirectory,
required this.soundSummaryPath,
required this.soundFullDillPath,
required this.soundJsPath,
required this.soundJsMapPath,
required this.weakSummaryPath,
required this.weakFullDillPath,
required this.weakJsPath,
required this.weakJsMapPath,
required this.librariesPath,
required this.dartdevcSnapshotPath,
required this.kernelWorkerSnapshotPath,
});
}

/// Data class describing the SDK layout.
///
/// Provides helpers to convert paths to uris that work on all platforms.
///
/// Call [validate] method to make sure the files in the configuration
/// layout exist before reading the files.
class SdkConfiguration {
// TODO(annagrin): update the tests to take those parameters
// and make all of the paths required (except for the compilerWorkerPath
// that is not used in Flutter).
static final defaultSdkLayout = SdkLayout.defaultSdkLayout;
static final defaultConfiguration =
SdkConfiguration.fromSdkLayout(defaultSdkLayout);

String? sdkDirectory;
String? unsoundSdkSummaryPath;
String? weakSdkSummaryPath;
String? soundSdkSummaryPath;
String? librariesPath;
String? compilerWorkerPath;

SdkConfiguration({
this.sdkDirectory,
this.unsoundSdkSummaryPath,
this.weakSdkSummaryPath,
this.soundSdkSummaryPath,
this.librariesPath,
this.compilerWorkerPath,
});

SdkConfiguration.empty() : this();

SdkConfiguration.fromSdkLayout(SdkLayout sdkLayout)
: this(
sdkDirectory: sdkLayout.sdkDirectory,
weakSdkSummaryPath: sdkLayout.weakSummaryPath,
soundSdkSummaryPath: sdkLayout.soundSummaryPath,
librariesPath: sdkLayout.librariesPath,
compilerWorkerPath: sdkLayout.dartdevcSnapshotPath,
);

static Uri? _toUri(String? path) => path == null ? null : p.toUri(path);
static Uri? _toAbsoluteUri(String? path) =>
path == null ? null : p.toUri(p.absolute(path));

Uri? get sdkDirectoryUri => _toUri(sdkDirectory);
Uri? get soundSdkSummaryUri => _toUri(soundSdkSummaryPath);
Uri? get unsoundSdkSummaryUri => _toUri(unsoundSdkSummaryPath);
Uri? get weakSdkSummaryUri => _toUri(weakSdkSummaryPath);
Uri? get librariesUri => _toUri(librariesPath);

/// Note: has to be ///file: Uri to run in an isolate.
Expand All @@ -85,14 +215,23 @@ class SdkConfiguration {
}

void validateSummaries({FileSystem fileSystem = const LocalFileSystem()}) {
if (unsoundSdkSummaryPath == null ||
!fileSystem.file(unsoundSdkSummaryPath).existsSync()) {
validateSoundSummaries(fileSystem: fileSystem);
validateWeakSummaries(fileSystem: fileSystem);
}

void validateWeakSummaries(
{FileSystem fileSystem = const LocalFileSystem()}) {
if (weakSdkSummaryPath == null ||
!fileSystem.file(weakSdkSummaryPath).existsSync()) {
throw InvalidSdkConfigurationException(
'Sdk summary $unsoundSdkSummaryPath does not exist');
'Sdk summary $weakSdkSummaryPath does not exist');
}
}

if (soundSdkSummaryPath == null ||
!fileSystem.file(soundSdkSummaryPath).existsSync()) {
void validateSoundSummaries(
{FileSystem fileSystem = const LocalFileSystem()}) {
if ((soundSdkSummaryPath == null ||
!fileSystem.file(soundSdkSummaryPath).existsSync())) {
throw InvalidSdkConfigurationException(
'Sdk summary $soundSdkSummaryPath does not exist');
}
Expand All @@ -116,27 +255,10 @@ class SdkConfiguration {
}
}

/// Implementation for the default SDK configuration layout.
class DefaultSdkConfigurationProvider extends SdkConfigurationProvider {
DefaultSdkConfigurationProvider();
const DefaultSdkConfigurationProvider();

late final SdkConfiguration _configuration = _create();

/// Create and validate configuration matching the default SDK layout.
@override
Future<SdkConfiguration> get configuration async => _configuration;

SdkConfiguration _create() {
final binDir = p.dirname(Platform.resolvedExecutable);
final sdkDir = p.dirname(binDir);

return SdkConfiguration(
sdkDirectory: sdkDir,
unsoundSdkSummaryPath: p.join(sdkDir, 'lib', '_internal', 'ddc_sdk.dill'),
soundSdkSummaryPath:
p.join(sdkDir, 'lib', '_internal', 'ddc_outline_sound.dill'),
librariesPath: p.join(sdkDir, 'lib', 'libraries.json'),
compilerWorkerPath: p.join(binDir, 'snapshots', 'dartdevc.dart.snapshot'),
);
}
Future<SdkConfiguration> get configuration async =>
SdkConfiguration.defaultConfiguration;
}
Loading