Skip to content

Commit

Permalink
Version 2.14.0-319.0.dev
Browse files Browse the repository at this point in the history
Merge commit 'a99b92c2525c6e490e2a55fce2888d251688b67a' into 'dev'
  • Loading branch information
Dart CI committed Jul 15, 2021
2 parents a2caa78 + a99b92c commit d53eb10
Show file tree
Hide file tree
Showing 20 changed files with 712 additions and 143 deletions.
2 changes: 1 addition & 1 deletion .dart_tool/package_config.json
Expand Up @@ -11,7 +11,7 @@
"constraint, update this by running tools/generate_package_config.dart."
],
"configVersion": 2,
"generated": "2021-07-02T15:48:57.033703",
"generated": "2021-07-14T10:43:41.119864",
"generator": "tools/generate_package_config.dart",
"packages": [
{
Expand Down
2 changes: 1 addition & 1 deletion DEPS
Expand Up @@ -164,7 +164,7 @@ vars = {
"test_process_tag": "2.0.0",
"term_glyph_rev": "6a0f9b6fb645ba75e7a00a4e20072678327a0347",
"test_reflective_loader_rev": "54e930a11c372683792e22bddad79197728c91ce",
"test_rev": "030816c32b6fe78d5fb7653afbd9f63cca18bacf",
"test_rev": "099dcc4d052a30c6921489cfbefa1c8531d12975",
"typed_data_tag": "f94fc57b8e8c0e4fe4ff6cfd8290b94af52d3719",
"usage_rev": "e0780cd8b2f8af69a28dc52678ffe8492da27d06",
"vector_math_rev": "0c9f5d68c047813a6dcdeb88ba7a42daddf25025",
Expand Down
19 changes: 0 additions & 19 deletions pkg/analyzer/lib/src/context/builder.dart
Expand Up @@ -8,25 +8,6 @@ import 'dart:core';
import 'package:analyzer/file_system/file_system.dart';
import 'package:yaml/yaml.dart';

/// TODO(scheglov) It is not used, inline it.
class ContextBuilderOptions {
/// The file path of the analysis options file that should be used in place of
/// any file in the root directory or a parent of the root directory, or `null`
/// if the normal lookup mechanism should be used.
String? defaultAnalysisOptionsFilePath;

/// A table mapping variable names to values for the declared variables.
Map<String, String> declaredVariables = {};

/// The file path of the .packages file that should be used in place of any
/// file found using the normal (Package Specification DEP) lookup mechanism,
/// or `null` if the normal lookup mechanism should be used.
String? defaultPackageFilePath;

/// Initialize a newly created set of options
ContextBuilderOptions();
}

/// Given a package map, check in each package's lib directory for the existence
/// of an `_embedder.yaml` file. If the file contains a top level YamlMap, it
/// will be added to the [embedderYamls] map.
Expand Down
10 changes: 5 additions & 5 deletions pkg/analyzer_cli/lib/src/driver.dart
Expand Up @@ -431,7 +431,7 @@ class Driver implements CommandLineStarter {
}

void _verifyAnalysisOptionsFileExists(CommandLineOptions options) {
var path = options.analysisOptionsFile;
var path = options.defaultAnalysisOptionsPath;
if (path != null) {
if (!resourceProvider.getFile(path).exists) {
printAndFail('Options file not found: $path',
Expand All @@ -449,8 +449,8 @@ class Driver implements CommandLineStarter {
CommandLineOptions previous, CommandLineOptions newOptions) {
return previous != null &&
newOptions != null &&
newOptions.packageConfigPath == previous.packageConfigPath &&
_equalMaps(newOptions.definedVariables, previous.definedVariables) &&
newOptions.defaultPackagesPath == previous.defaultPackagesPath &&
_equalMaps(newOptions.declaredVariables, previous.declaredVariables) &&
newOptions.log == previous.log &&
newOptions.disableHints == previous.disableHints &&
newOptions.showPackageWarnings == previous.showPackageWarnings &&
Expand Down Expand Up @@ -554,8 +554,8 @@ class _AnalysisContextProvider {
_collection = AnalysisContextCollectionImpl(
byteStore: Driver.analysisDriverMemoryByteStore,
includedPaths: _pathList,
optionsFile: _commandLineOptions.analysisOptionsFile,
packagesFile: _commandLineOptions.packageConfigPath,
optionsFile: _commandLineOptions.defaultAnalysisOptionsPath,
packagesFile: _commandLineOptions.defaultPackagesPath,
resourceProvider: _resourceProvider,
sdkPath: _commandLineOptions.dartSdkPath,
updateAnalysisOptions: _updateAnalysisOptions,
Expand Down
118 changes: 53 additions & 65 deletions pkg/analyzer_cli/lib/src/options.dart
Expand Up @@ -6,7 +6,6 @@ import 'dart:io' as io;

import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/context/builder.dart';
import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl;
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
Expand Down Expand Up @@ -51,8 +50,18 @@ typedef ExitHandler = void Function(int code);
class CommandLineOptions {
final ArgResults _argResults;

/// The options defining the context in which analysis is performed.
final ContextBuilderOptions contextBuilderOptions;
/// The file path of the analysis options file that should be used in place of
/// any file in the root directory or a parent of the root directory,
/// or `null` if the normal lookup mechanism should be used.
String defaultAnalysisOptionsPath;

/// The file path of the .packages file that should be used in place of any
/// file found using the normal (Package Specification DEP) lookup mechanism,
/// or `null` if the normal lookup mechanism should be used.
String defaultPackagesPath;

/// A table mapping variable names to values for the declared variables.
final Map<String, String> declaredVariables = {};

/// The path to the dart SDK.
String dartSdkPath;
Expand Down Expand Up @@ -124,10 +133,6 @@ class CommandLineOptions {
ResourceProvider resourceProvider,
ArgResults args,
) : _argResults = args,
contextBuilderOptions = _createContextBuilderOptions(
resourceProvider,
args,
),
dartSdkPath = cast(args[_sdkPathOption]),
disableCacheFlushing = cast(args['disable-cache-flushing']),
disableHints = cast(args['no-hints']),
Expand All @@ -149,22 +154,48 @@ class CommandLineOptions {
lintsAreFatal = cast(args['fatal-lints']),
trainSnapshot = cast(args['train-snapshot']),
verbose = cast(args['verbose']),
color = cast(args['color']);
color = cast(args['color']) {
//
// File locations.
//
defaultAnalysisOptionsPath = _absoluteNormalizedPath(
resourceProvider,
cast(args[_analysisOptionsFileOption]),
);
defaultPackagesPath = _absoluteNormalizedPath(
resourceProvider,
cast(args[_packagesOption]),
);

/// The path to an analysis options file
String get analysisOptionsFile =>
contextBuilderOptions.defaultAnalysisOptionsFilePath;
//
// Declared variables.
//
var variables = (args[_defineVariableOption] as List).cast<String>();
for (var variable in variables) {
var index = variable.indexOf('=');
if (index < 0) {
// TODO (brianwilkerson) Decide the semantics we want in this case.
// The VM prints "No value given to -D option", then tries to load '-Dfoo'
// as a file and dies. Unless there was nothing after the '-D', in which
// case it prints the warning and ignores the option.
} else {
var name = variable.substring(0, index);
if (name.isNotEmpty) {
// TODO (brianwilkerson) Decide the semantics we want in the case where
// there is no name. If there is no name, the VM tries to load a file
// named '-D' and dies.
declaredVariables[name] = variable.substring(index + 1);
}
}
}
}

/// The default language version for files that are not in a package.
/// (Or null if no default language version to force.)
String get defaultLanguageVersion {
return cast(_argResults[_defaultLanguageVersionOption]);
}

/// A table mapping the names of defined variables to their values.
Map<String, String> get definedVariables =>
contextBuilderOptions.declaredVariables;

/// A list of the names of the experiments that are to be enabled.
List<String> get enabledExperiments {
return cast(_argResults[_enableExperimentOption]);
Expand All @@ -176,9 +207,6 @@ class CommandLineOptions {

bool get noImplicitDynamic => _argResults[_noImplicitDynamicFlag] as bool;

/// The path to a `.packages` configuration file
String get packageConfigPath => contextBuilderOptions.defaultPackageFilePath;

/// Update the [analysisOptions] with flags that the user specified
/// explicitly. The [analysisOptions] are usually loaded from one of
/// `analysis_options.yaml` files, possibly with includes. We consider
Expand Down Expand Up @@ -307,57 +335,17 @@ class CommandLineOptions {
return options;
}

/// Use the command-line [args] to create a context builder options.
static ContextBuilderOptions _createContextBuilderOptions(
static String _absoluteNormalizedPath(
ResourceProvider resourceProvider,
ArgResults args,
String path,
) {
String absoluteNormalizedPath(String path) {
if (path == null) {
return null;
}
var pathContext = resourceProvider.pathContext;
return pathContext.normalize(
pathContext.absolute(path),
);
if (path == null) {
return null;
}

var builderOptions = ContextBuilderOptions();

//
// File locations.
//
builderOptions.defaultAnalysisOptionsFilePath = absoluteNormalizedPath(
cast(args[_analysisOptionsFileOption]),
);
builderOptions.defaultPackageFilePath = absoluteNormalizedPath(
cast(args[_packagesOption]),
var pathContext = resourceProvider.pathContext;
return pathContext.normalize(
pathContext.absolute(path),
);
//
// Declared variables.
//
var declaredVariables = <String, String>{};
var variables = (args[_defineVariableOption] as List).cast<String>();
for (var variable in variables) {
var index = variable.indexOf('=');
if (index < 0) {
// TODO (brianwilkerson) Decide the semantics we want in this case.
// The VM prints "No value given to -D option", then tries to load '-Dfoo'
// as a file and dies. Unless there was nothing after the '-D', in which
// case it prints the warning and ignores the option.
} else {
var name = variable.substring(0, index);
if (name.isNotEmpty) {
// TODO (brianwilkerson) Decide the semantics we want in the case where
// there is no name. If there is no name, the VM tries to load a file
// named '-D' and dies.
declaredVariables[name] = variable.substring(index + 1);
}
}
}
builderOptions.declaredVariables = declaredVariables;

return builderOptions;
}

/// Add the standard flags and options to the given [parser]. The standard flags
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer_cli/lib/src/perf_report.dart
Expand Up @@ -38,8 +38,8 @@ String makePerfReport(int startTime, int endTime, CommandLineOptions options,
'showPackageWarnings': options.showPackageWarnings,
'showPackageWarningsPrefix': options.showPackageWarningsPrefix,
'showSdkWarnings': options.showSdkWarnings,
'definedVariables': options.definedVariables,
'packageConfigPath': options.packageConfigPath,
'definedVariables': options.declaredVariables,
'packageConfigPath': options.defaultPackagesPath,
'sourceFiles': options.sourceFiles,
};

Expand Down
23 changes: 9 additions & 14 deletions pkg/analyzer_cli/test/options_test.dart
Expand Up @@ -84,8 +84,8 @@ void main() {

test('defined variables', () {
var options = parse(['--dart-sdk', '.', '-Dfoo=bar', 'foo.dart']);
expect(options.definedVariables['foo'], equals('bar'));
expect(options.definedVariables['bar'], isNull);
expect(options.declaredVariables['foo'], equals('bar'));
expect(options.declaredVariables['bar'], isNull);
});

test('disable cache flushing', () {
Expand Down Expand Up @@ -210,7 +210,7 @@ void main() {
test('options', () {
var options =
parse(['--dart-sdk', '.', '--options', 'options.yaml', 'foo.dart']);
expect(options.analysisOptionsFile, endsWith('options.yaml'));
expect(options.defaultAnalysisOptionsPath, endsWith('options.yaml'));
});

test('lints', () {
Expand Down Expand Up @@ -284,8 +284,7 @@ class ArgumentsTest with ResourceProviderMixin {
void test_declaredVariables() {
_parse(['-Da=0', '-Db=', 'a.dart']);

var options = commandLineOptions.contextBuilderOptions;
var definedVariables = options.declaredVariables;
var definedVariables = commandLineOptions.declaredVariables;

expect(definedVariables['a'], '0');
expect(definedVariables['b'], '');
Expand All @@ -296,9 +295,8 @@ class ArgumentsTest with ResourceProviderMixin {
var expected = 'my_options.yaml';
_parse(['--options=$expected', 'a.dart']);

var builderOptions = commandLineOptions.contextBuilderOptions;
expect(
builderOptions.defaultAnalysisOptionsFilePath,
commandLineOptions.defaultAnalysisOptionsPath,
endsWith(expected),
);
}
Expand All @@ -307,20 +305,17 @@ class ArgumentsTest with ResourceProviderMixin {
var expected = 'my_package_config.json';
_parse(['--packages=$expected', 'a.dart']);

var builderOptions = commandLineOptions.contextBuilderOptions;
expect(
builderOptions.defaultPackageFilePath,
commandLineOptions.defaultPackagesPath,
endsWith(expected),
);
}

void test_defaults() {
_parse(['a.dart']);
var builderOptions = commandLineOptions.contextBuilderOptions;
expect(builderOptions, isNotNull);
expect(builderOptions.declaredVariables, isEmpty);
expect(builderOptions.defaultAnalysisOptionsFilePath, isNull);
expect(builderOptions.defaultPackageFilePath, isNull);
expect(commandLineOptions.declaredVariables, isEmpty);
expect(commandLineOptions.defaultAnalysisOptionsPath, isNull);
expect(commandLineOptions.defaultPackagesPath, isNull);
}

void test_filterUnknownArguments() {
Expand Down
4 changes: 4 additions & 0 deletions pkg/dds/CHANGELOG.md
@@ -1,3 +1,7 @@
# 2.0.2
- Fix possibility of `LateInitializationError` being thrown when trying to
cleanup after an error during initialization.

# 2.0.1
- Update `package:vm_service` to ^7.0.0.

Expand Down
37 changes: 23 additions & 14 deletions pkg/dds/lib/src/dds_impl.dart
Expand Up @@ -67,7 +67,7 @@ class DartDevelopmentServiceImpl implements DartDevelopmentService {

Future<void> startService() async {
bool started = false;
final completer = Completer<void>();
DartDevelopmentServiceException? error;
// TODO(bkonyi): throw if we've already shutdown.
// Establish the connection to the VM service.
_vmServiceSocket = webSocketBuilder(remoteVmServiceWsUri);
Expand All @@ -76,18 +76,25 @@ class DartDevelopmentServiceImpl implements DartDevelopmentService {
unawaited(
vmServiceClient.listen().then(
(_) {
shutdown();
if (!started && !completer.isCompleted) {
completer
.completeError(DartDevelopmentServiceException.failedToStart());
if (started) {
shutdown();
} else {
// If we fail to connect to the service or the connection is
// terminated while we're starting up, we'll need to cleanup later
// once DDS has finished initializing to make sure all ports are
// closed before throwing the exception.
error = DartDevelopmentServiceException.failedToStart();
}
},
onError: (e, st) {
shutdown();
if (!completer.isCompleted) {
completer.completeError(
DartDevelopmentServiceException.connectionIssue(e.toString()),
st,
if (started) {
shutdown();
} else {
// If we encounter an error while we're starting up, we'll need to
// cleanup later once DDS has finished initializing to make sure
// all ports are closed before throwing the exception.
error = DartDevelopmentServiceException.connectionIssue(
e.toString(),
);
}
},
Expand All @@ -104,13 +111,15 @@ class DartDevelopmentServiceImpl implements DartDevelopmentService {
// Once we have a connection to the VM service, we're ready to spawn the intermediary.
await _startDDSServer();
started = true;
completer.complete();
} on StateError {
/* Ignore json-rpc state errors */
} catch (e, st) {
completer.completeError(e, st);
}
return completer.future;

// Check if we encountered any errors during startup, cleanup, and throw.
if (error != null) {
await shutdown();
throw error!;
}
}

Future<void> _startDDSServer() async {
Expand Down

0 comments on commit d53eb10

Please sign in to comment.