mirror of
https://github.com/dart-lang/sdk
synced 2024-10-03 00:09:20 +00:00
[Dart CLI] Embed pub in dartdev
This includes the following pub commits: git log --format="%C(auto) %h %s" 5b4df5a6f931c63622ac349602d6ef0367e8070f..fb72c1f774ca27556225b207185c0b6b6ab1c274 fb72c1f7 Make `run` available (but deprecated) in the embedding (#2698) 63b56ea4 Return the exit-code from commands (#2689) 7fc4e273 Deprecate top level (#2694) Change-Id: I5842b1ecb15fc7844d628e2ad5fb00e3f627dbff Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168347 Commit-Queue: Sigurd Meldgaard <sigurdm@google.com> Reviewed-by: Sigurd Meldgaard <sigurdm@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com> Reviewed-by: Jonas Jensen <jonasfj@google.com>
This commit is contained in:
parent
35d83867ba
commit
cd970af91a
|
@ -91,8 +91,9 @@ Updated the Linter to `0.1.123`, which includes:
|
|||
* New option `dart pub outdated mode=null-safety` that will analyze your
|
||||
dependencies for null-safety.
|
||||
* `dart pub publish` will now check your pubspec keys for likely typos.
|
||||
* `pub get` will print a warning if the resolution is in mixed-mode requiring
|
||||
* `dart pub get` will print a warning if the resolution is in mixed-mode requiring
|
||||
the code to run with `dart --no-sound-null-safety`.
|
||||
* New command `dart pub login` that logs in to pub.dev.
|
||||
|
||||
## 2.10.3 - 2020-10-29
|
||||
|
||||
|
|
2
DEPS
2
DEPS
|
@ -132,7 +132,7 @@ vars = {
|
|||
"ply_rev": "604b32590ffad5cbb82e4afef1d305512d06ae93",
|
||||
"pool_rev": "eedbd5fde84f9a1a8da643b475305a81841da599",
|
||||
"protobuf_rev": "3746c8fd3f2b0147623a8e3db89c3ff4330de760",
|
||||
"pub_rev": "5b4df5a6f931c63622ac349602d6ef0367e8070f",
|
||||
"pub_rev": "900e796a37fd9f68de9dd183cf4798fe5f055eaa",
|
||||
"pub_semver_tag": "v1.4.4",
|
||||
"resource_rev": "6b79867d0becf5395e5819a75720963b8298e9a7",
|
||||
"root_certificates_rev": "7e5ec82c99677a2e5b95ce296c4d68b0d3378ed8",
|
||||
|
|
|
@ -12,6 +12,7 @@ import 'package:cli_util/cli_logging.dart';
|
|||
import 'package:dart_style/src/cli/format_command.dart';
|
||||
import 'package:nnbd_migration/migration_cli.dart';
|
||||
import 'package:pedantic/pedantic.dart';
|
||||
import 'package:pub/pub.dart';
|
||||
import 'package:usage/usage.dart';
|
||||
|
||||
import 'src/analytics.dart';
|
||||
|
@ -19,7 +20,6 @@ import 'src/commands/analyze.dart';
|
|||
import 'src/commands/compile.dart';
|
||||
import 'src/commands/create.dart';
|
||||
import 'src/commands/fix.dart';
|
||||
import 'src/commands/pub.dart';
|
||||
import 'src/commands/run.dart';
|
||||
import 'src/commands/test.dart';
|
||||
import 'src/core.dart';
|
||||
|
@ -194,7 +194,7 @@ class DartdevRunner extends CommandRunner<int> {
|
|||
addCommand(FixCommand());
|
||||
addCommand(FormatCommand(verbose: verbose));
|
||||
addCommand(MigrateCommand(verbose: verbose));
|
||||
addCommand(PubCommand());
|
||||
addCommand(pubCommand());
|
||||
addCommand(RunCommand(verbose: verbose));
|
||||
addCommand(TestCommand());
|
||||
}
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
// 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 'dart:async';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
|
||||
import '../core.dart';
|
||||
import '../experiments.dart';
|
||||
import '../sdk.dart';
|
||||
import '../vm_interop_handler.dart';
|
||||
|
||||
class PubCommand extends DartdevCommand {
|
||||
static const String cmdName = 'pub';
|
||||
|
||||
PubCommand() : super(cmdName, 'Work with packages.');
|
||||
|
||||
// TODO(jwren) as soon as pub commands are are implemented directly in
|
||||
// dartdev, remove this static list.
|
||||
/// A list of all subcommands, used only for the implementation of
|
||||
/// [usagePath], see below.
|
||||
static List<String> pubSubcommands = [
|
||||
'cache',
|
||||
'deps',
|
||||
'downgrade',
|
||||
'get',
|
||||
'global',
|
||||
'logout',
|
||||
'outdated',
|
||||
'publish',
|
||||
'run',
|
||||
'upgrade',
|
||||
'uploader',
|
||||
'version',
|
||||
];
|
||||
|
||||
@override
|
||||
ArgParser createArgParser() => ArgParser.allowAnything();
|
||||
|
||||
@override
|
||||
void printUsage() {
|
||||
// Override [printUsage] for invocations of 'dart help pub' which won't
|
||||
// execute [run] below. Without this, the 'dart help pub' reports the
|
||||
// command pub with no commands or flags.
|
||||
if (!Sdk.checkArtifactExists(sdk.pubSnapshot)) {
|
||||
return;
|
||||
}
|
||||
final command = sdk.pubSnapshot;
|
||||
final args = ['help'];
|
||||
|
||||
log.trace('$command ${args.first}');
|
||||
|
||||
// Call 'pub help'
|
||||
VmInteropHandler.run(command, args);
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOr<int> run() async {
|
||||
if (!Sdk.checkArtifactExists(sdk.pubSnapshot)) {
|
||||
return 255;
|
||||
}
|
||||
final command = sdk.pubSnapshot;
|
||||
var args = argResults.arguments;
|
||||
|
||||
final enabledExperiments = argResults.enabledExperiments;
|
||||
// Pass any --enable-experiment options along.
|
||||
if (args.isNotEmpty && enabledExperiments.isNotEmpty) {
|
||||
if (args.first == 'run') {
|
||||
args = [
|
||||
...args.sublist(0, 1),
|
||||
'--$experimentFlagName=${enabledExperiments.join(',')}',
|
||||
...args.sublist(1),
|
||||
];
|
||||
} else if (args.length > 1 && args[0] == 'global' && args[0] == 'run') {
|
||||
args = [
|
||||
...args.sublist(0, 2),
|
||||
'--$experimentFlagName=${enabledExperiments.join(',')}',
|
||||
...args.sublist(2),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
log.trace('$command ${args.join(' ')}');
|
||||
VmInteropHandler.run(command, args);
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ import 'dart:io';
|
|||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:pub/pub.dart';
|
||||
|
||||
import '../core.dart';
|
||||
import '../experiments.dart';
|
||||
|
@ -153,69 +154,27 @@ class RunCommand extends DartdevCommand {
|
|||
|
||||
@override
|
||||
FutureOr<int> run() async {
|
||||
// The command line arguments after 'run'
|
||||
var args = argResults.arguments.toList();
|
||||
var mainCommand = '';
|
||||
var runArgs = <String>[];
|
||||
if (argResults.rest.isNotEmpty) {
|
||||
mainCommand = argResults.rest.first;
|
||||
// The command line arguments after the command name.
|
||||
runArgs = argResults.rest.skip(1).toList();
|
||||
}
|
||||
// --launch-dds is provided by the VM if the VM service is to be enabled. In
|
||||
// that case, we need to launch DDS as well.
|
||||
bool launchDds = false;
|
||||
String launchDdsArg = argResults['launch-dds'];
|
||||
String ddsHost = '';
|
||||
String ddsPort = '';
|
||||
|
||||
final launchDdsArg = args.singleWhere(
|
||||
(element) => element.startsWith('--launch-dds'),
|
||||
orElse: () => null,
|
||||
);
|
||||
bool launchDds = false;
|
||||
if (launchDdsArg != null) {
|
||||
launchDds = true;
|
||||
final ddsUrl = (launchDdsArg.split('=')[1]).split(':');
|
||||
final ddsUrl = launchDdsArg.split(':');
|
||||
ddsHost = ddsUrl[0];
|
||||
ddsPort = ddsUrl[1];
|
||||
}
|
||||
|
||||
var argsContainFile = false;
|
||||
for (var arg in args) {
|
||||
// The arg.contains('.') matches a file name pattern, i.e. some 'foo.dart'
|
||||
if (arg.contains('.')) {
|
||||
argsContainFile = true;
|
||||
} else if (!argsContainFile &&
|
||||
(arg == '--help' || arg == '-h' || arg == 'help')) {
|
||||
// Only print usage if a help flag is provided before the script name.
|
||||
printUsage();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
var disableServiceAuthCodes =
|
||||
argResults['disable-service-auth-codes'] ?? false;
|
||||
|
||||
final cwd = Directory.current;
|
||||
if (!argsContainFile && cwd.existsSync()) {
|
||||
var foundImplicitFileToRun = false;
|
||||
var cwdName = cwd.name;
|
||||
for (var entity in cwd.listSync(followLinks: false)) {
|
||||
if (entity is Directory && entity.name == 'bin') {
|
||||
var filesInBin =
|
||||
entity.listSync(followLinks: false).whereType<File>();
|
||||
|
||||
// Search for a dart file in bin/ with the pattern foo/bin/foo.dart
|
||||
for (var fileInBin in filesInBin) {
|
||||
if (fileInBin.isDartFile && fileInBin.name == '$cwdName.dart') {
|
||||
args.add('bin/${fileInBin.name}');
|
||||
foundImplicitFileToRun = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// break here, no actions taken on any entities that are not bin/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundImplicitFileToRun) {
|
||||
// This throws.
|
||||
usageException('Could not find the implicit file to run: '
|
||||
'bin$separator$cwdName.dart.');
|
||||
}
|
||||
}
|
||||
bool disableServiceAuthCodes = argResults['disable-service-auth-codes'];
|
||||
|
||||
// If the user wants to start a debugging session we need to do some extra
|
||||
// work and spawn a Dart Development Service (DDS) instance. DDS is a VM
|
||||
|
@ -231,20 +190,14 @@ class RunCommand extends DartdevCommand {
|
|||
}
|
||||
}
|
||||
|
||||
var path = args.firstWhere((e) => !e.startsWith('-'));
|
||||
final pathIndex = args.indexOf(path);
|
||||
final runArgs = (pathIndex + 1 == args.length)
|
||||
? <String>[]
|
||||
: args.sublist(pathIndex + 1);
|
||||
String path;
|
||||
try {
|
||||
path = Uri.parse(path).toFilePath();
|
||||
} catch (_) {
|
||||
// Input path will either be a valid path or a file uri
|
||||
// (e.g /directory/file.dart or file:///directory/file.dart). We will try
|
||||
// parsing it as a Uri, but if parsing failed for any reason (likely
|
||||
// because path is not a file Uri), `path` will be passed without
|
||||
// modification to the VM.
|
||||
path = await getExecutableForCommand(mainCommand);
|
||||
} on CommandResolutionFailedException catch (e) {
|
||||
log.stderr(e.message);
|
||||
return errorExitCode;
|
||||
}
|
||||
|
||||
VmInteropHandler.run(path, runArgs);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ dependencies:
|
|||
path: ../nnbd_migration
|
||||
path: ^1.0.0
|
||||
pedantic: ^1.9.0
|
||||
pub:
|
||||
path: ../../third_party/pkg/pub
|
||||
stagehand: 3.3.7
|
||||
telemetry:
|
||||
path: ../telemetry
|
||||
|
|
|
@ -86,23 +86,23 @@ void main() {
|
|||
expect(extractAnalytics(result), [
|
||||
{
|
||||
'hitType': 'screenView',
|
||||
// TODO(sigurdm): this should be pub/get
|
||||
'message': {'viewName': 'pub'}
|
||||
'message': {'viewName': 'pub/get'}
|
||||
},
|
||||
{
|
||||
'hitType': 'event',
|
||||
'message': {
|
||||
'category': 'dartdev',
|
||||
'action': 'pub',
|
||||
'action': 'pub/get',
|
||||
'label': null,
|
||||
'value': null,
|
||||
'cd1': '0',
|
||||
'cd3': ' dry-run '
|
||||
}
|
||||
},
|
||||
{
|
||||
'hitType': 'timing',
|
||||
'message': {
|
||||
'variableName': 'pub',
|
||||
'variableName': 'pub/get',
|
||||
'time': isA<int>(),
|
||||
'category': 'commands',
|
||||
'label': null
|
||||
|
|
|
@ -42,6 +42,11 @@ void command() {
|
|||
command.name != 'pub') {
|
||||
expect(command.argParser.usageLineLength,
|
||||
stdout.hasTerminal ? stdout.terminalColumns : null);
|
||||
} else if (command.name == 'pub') {
|
||||
// TODO(sigurdm): Avoid special casing here.
|
||||
// https://github.com/dart-lang/pub/issues/2700
|
||||
expect(command.argParser.usageLineLength,
|
||||
stdout.hasTerminal ? stdout.terminalColumns : 80);
|
||||
} else {
|
||||
expect(command.argParser.usageLineLength, isNull);
|
||||
}
|
||||
|
|
|
@ -37,10 +37,10 @@ void help() {
|
|||
}
|
||||
});
|
||||
|
||||
test('(help pub == pub help)', () {
|
||||
test('(help pub == pub --help)', () {
|
||||
p = project();
|
||||
var result = p.runSync('help', ['pub']);
|
||||
var pubHelpResult = p.runSync('pub', ['help']);
|
||||
var pubHelpResult = p.runSync('pub', ['--help']);
|
||||
|
||||
expect(result.stdout, contains(pubHelpResult.stdout));
|
||||
expect(result.stderr, contains(pubHelpResult.stderr));
|
||||
|
|
|
@ -20,13 +20,18 @@ void pub() {
|
|||
void _assertPubHelpInvoked(ProcessResult result) {
|
||||
expect(result, isNotNull);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stdout, contains('Pub is a package manager for Dart'));
|
||||
expect(result.stdout, contains('Available commands:'));
|
||||
expect(result.stdout, contains('Work with packages'));
|
||||
expect(result.stdout, contains('Available subcommands:'));
|
||||
expect(result.stderr, isEmpty);
|
||||
}
|
||||
|
||||
test('implicit --help', () {
|
||||
_assertPubHelpInvoked(project().runSync('pub', []));
|
||||
final result = project().runSync('pub', []);
|
||||
expect(result, isNotNull);
|
||||
expect(result.exitCode, 64);
|
||||
expect(result.stderr, contains('Missing subcommand for "dart pub".'));
|
||||
expect(result.stderr, contains('Available subcommands:'));
|
||||
expect(result.stdout, isEmpty);
|
||||
});
|
||||
|
||||
test('--help', () {
|
||||
|
@ -39,7 +44,7 @@ void pub() {
|
|||
|
||||
test('help cache', () {
|
||||
p = project();
|
||||
var result = p.runSync('pub', ['help', 'cache']);
|
||||
var result = p.runSync('help', ['pub', 'cache']);
|
||||
var result2 = p.runSync('pub', ['cache', '--help']);
|
||||
|
||||
expect(result.exitCode, 0);
|
||||
|
@ -53,7 +58,7 @@ void pub() {
|
|||
|
||||
test('help publish', () {
|
||||
p = project();
|
||||
var result = p.runSync('pub', ['help', 'publish']);
|
||||
var result = p.runSync('help', ['pub', 'publish']);
|
||||
var result2 = p.runSync('pub', ['publish', '--help']);
|
||||
|
||||
expect(result.exitCode, 0);
|
||||
|
|
|
@ -65,9 +65,11 @@ void run() {
|
|||
ProcessResult result = p.runSync('run', []);
|
||||
|
||||
expect(result.stdout, isEmpty);
|
||||
expect(result.stderr,
|
||||
contains('Could not find the implicit file to run: bin'));
|
||||
expect(result.exitCode, 64);
|
||||
expect(
|
||||
result.stderr,
|
||||
contains(
|
||||
'Could not find `bin/dartdev_temp.dart` in package `dartdev_temp`.'));
|
||||
expect(result.exitCode, 255);
|
||||
});
|
||||
|
||||
test('arguments are properly passed', () {
|
||||
|
|
|
@ -9,7 +9,6 @@ import 'package:dartdev/src/commands/analyze.dart';
|
|||
import 'package:dartdev/src/commands/compile.dart';
|
||||
import 'package:dartdev/src/commands/create.dart';
|
||||
import 'package:dartdev/src/commands/fix.dart';
|
||||
import 'package:dartdev/src/commands/pub.dart';
|
||||
import 'package:dartdev/src/commands/run.dart';
|
||||
import 'package:dartdev/src/commands/test.dart';
|
||||
import 'package:dartdev/src/core.dart';
|
||||
|
@ -81,10 +80,6 @@ void _dartdevCommand() {
|
|||
_assertDartdevCommandProperties(FixCommand(), 'fix', 'fix');
|
||||
});
|
||||
|
||||
test('pub', () {
|
||||
_assertDartdevCommandProperties(PubCommand(), 'pub', 'pub');
|
||||
});
|
||||
|
||||
test('run', () {
|
||||
_assertDartdevCommandProperties(RunCommand(verbose: false), 'run', 'run');
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue