ffc36db613
where --enable experiment is accepted Adds --enable-experiment support for: - dart compile aot-snapshot - dart compile jit-snapshot - dart compile js - dart compile exe - dart compile kernel Also changes --enable-experiment from a top level CLI flag to a per-command flag. --enable-experiment flags will now only be interpreted by the VM if: 1) They are provided before a CLI command (e.g., dart --enable-experiment=non-nullable analyze) or 2) They are provided with an explicit or implicit run command (e.g., dart --enable-experiment=non-nullable foo.dart or dart --enable-experiment=non-nullable run foo.dart or dart run --enable-experiment=non-nullable foo.dart) This should make it more generally clear where --enable-experiment is accepted and what subcommands can accept the flag. Prior to this change, providing --enable-experiment anywhere, even for commands without experiment support, would not raise an error. Fixes https://github.com/dart-lang/sdk/issues/43623 Change-Id: I5ec48b2dd2bb6db5526185dae2edbca95ef24d9f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169902 Commit-Queue: Ben Konyi <bkonyi@google.com> Reviewed-by: Sigurd Meldgaard <sigurdm@google.com> Reviewed-by: Jonas Jensen <jonasfj@google.com>
87 lines
3.1 KiB
Dart
87 lines
3.1 KiB
Dart
// Copyright (c) 2020, 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.
|
|
|
|
import 'package:meta/meta.dart';
|
|
import 'package:usage/usage.dart';
|
|
|
|
/// The [String] identifier `dartdev`, used as the category in the events sent
|
|
/// to analytics.
|
|
const String _dartdev = 'dartdev';
|
|
|
|
/// The collection of custom dimensions understood by the analytics backend.
|
|
/// When adding to this list, first ensure that the custom dimension is
|
|
/// defined in the backend, or will be defined shortly after the relevant PR
|
|
/// lands. The pattern here matches the flutter cli.
|
|
enum _CustomDimensions {
|
|
commandExitCode, // cd1
|
|
enabledExperiments, // cd2
|
|
commandFlags, // cd3
|
|
}
|
|
|
|
String _cdKey(_CustomDimensions cd) => 'cd${cd.index + 1}';
|
|
|
|
Map<String, String> _useCdKeys(Map<_CustomDimensions, String> parameters) {
|
|
return parameters.map(
|
|
(_CustomDimensions k, String v) => MapEntry<String, String>(_cdKey(k), v),
|
|
);
|
|
}
|
|
|
|
/// Sends a usage event on [analytics].
|
|
///
|
|
/// [command] is the top-level command name being executed here, 'analyze' and
|
|
/// 'pub' are examples.
|
|
///
|
|
/// [action] is the command, and optionally the subcommand, joined with '/',
|
|
/// an example here is 'pub/get'.
|
|
///
|
|
/// [label] is not used yet used when reporting dartdev analytics, but the API
|
|
/// is included here for possible future use.
|
|
///
|
|
/// [exitCode] is the exit code returned from this invocation of dartdev.
|
|
///
|
|
/// [specifiedExperiements] are the experiments passed into the dartdev
|
|
/// command. If the command doesn't use the experiments, they are not reported.
|
|
///
|
|
/// [commandFlags] are the flags (no values) used to run this command.
|
|
Future<void> sendUsageEvent(
|
|
Analytics analytics,
|
|
String action, {
|
|
String label,
|
|
List<String> specifiedExperiments,
|
|
@required int exitCode,
|
|
@required List<String> commandFlags,
|
|
}) {
|
|
/// The category stores the name of this cli tool, 'dartdev'. This matches the
|
|
/// pattern from the flutter cli tool which always passes 'flutter' as the
|
|
/// category.
|
|
final category = _dartdev;
|
|
commandFlags =
|
|
commandFlags?.where((e) => e != 'enable-experiment')?.toList() ?? [];
|
|
specifiedExperiments = specifiedExperiments?.toList() ?? [];
|
|
|
|
// Sort the flag lists to slightly reduce the explosion of possibilities.
|
|
commandFlags..sort();
|
|
specifiedExperiments.sort();
|
|
|
|
// Insert a seperator before and after the flags list to make it easier to filter
|
|
// for a specific flag:
|
|
final enabledExperimentsString = ' ${specifiedExperiments.join(' ')} ';
|
|
final commandFlagsString = ' ${commandFlags.join(' ')} ';
|
|
|
|
final Map<String, String> parameters = _useCdKeys(<_CustomDimensions, String>{
|
|
if (exitCode != null)
|
|
_CustomDimensions.commandExitCode: exitCode.toString(),
|
|
if (specifiedExperiments.isNotEmpty)
|
|
_CustomDimensions.enabledExperiments: enabledExperimentsString,
|
|
if (commandFlags.isNotEmpty)
|
|
_CustomDimensions.commandFlags: commandFlagsString,
|
|
});
|
|
return analytics.sendEvent(
|
|
category,
|
|
action,
|
|
label: label,
|
|
parameters: parameters,
|
|
);
|
|
}
|