Skip to content

Commit

Permalink
Deprecate top level pub.
Browse files Browse the repository at this point in the history
Also makes the `pub` shell script (and its .bat counterpart)
forward to a `dart __deprecated_pub` command that implements the
old top-level.

This allows us to get rid of pub.dart.snapshot saving ~15 MB in a
unzipped sdk.

The reason for not forwarding directly to `dart pub` is that the
interface is slightly different (for example there is no `dart pub --version`).


The only new commit in pub is: `3c2ce330 Expose toplevel as a command`


Bug: dart-lang/pub#2736
Change-Id: I6eb08d120c4844b3a12bc29544df6a868cd6fcc8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210582
Commit-Queue: Sigurd Meldgaard <[email protected]>
Reviewed-by: Jonas Jensen <[email protected]>
  • Loading branch information
sigurdm authored and [email protected] committed Aug 24, 2021
1 parent 77fc025 commit ae81cd5
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 153 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ vars = {
"pool_rev": "7abe634002a1ba8a0928eded086062f1307ccfae",
"process_rev": "56ece43b53b64c63ae51ec184b76bd5360c28d0b",
"protobuf_rev": "c1eb6cb51af39ccbaa1a8e19349546586a5c8e31",
"pub_rev": "9f2ddc02f066c68fb638ff65fbb73761ece23267",
"pub_rev": "cd7a43f2109f7e5eb22e73c7f4e15d25fd57598e",
"pub_semver_rev": "f50d80ef10c4b2fa5f4c8878036a4d9342c0cc82",
"resource_rev": "6b79867d0becf5395e5819a75720963b8298e9a7",
"root_certificates_rev": "692f6d6488af68e0121317a9c2c9eb393eb0ee50",
Expand Down
10 changes: 10 additions & 0 deletions pkg/dartdev/lib/dartdev.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:devtools_server/devtools_server.dart';
import 'package:meta/meta.dart';
import 'package:pedantic/pedantic.dart';
import 'package:pub/pub.dart';

import 'package:usage/usage.dart';

import 'src/analytics.dart';
Expand All @@ -36,6 +37,15 @@ import 'src/vm_interop_handler.dart';
/// analytics logic, it has been moved here.
Future<void> runDartdev(List<String> args, SendPort port) async {
VmInteropHandler.initialize(port);

// TODO(sigurdm): Remove when top-level pub is removed.
if (args[0] == '__deprecated_pub') {
// This is the entry-point supporting the top-level `pub` script.
// ignore: deprecated_member_use
VmInteropHandler.exit(await deprecatedpubCommand().run(args.skip(1)));
return;
}

if (args.contains('run')) {
// These flags have a format that can't be handled by package:args, so while
// they are valid flags we'll assume the VM has verified them by this point.
Expand Down
5 changes: 1 addition & 4 deletions pkg/dartdev/lib/src/commands/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,11 @@ class CreateCommand extends DartdevCommand {
);

if (argResults['pub']) {
if (!Sdk.checkArtifactExists(sdk.pubSnapshot)) {
return 255;
}
log.stdout('');
var progress = log.progress('Running pub get');
var process = await startDartProcess(
sdk,
[sdk.pubSnapshot, 'get', '--no-precompile'],
['pub', 'get'],
cwd: dir,
);

Expand Down
7 changes: 0 additions & 7 deletions pkg/dartdev/lib/src/sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ class Sdk {
'devtools',
);

String get pubSnapshot => path.absolute(
sdkPath,
'bin',
'snapshots',
'pub.dart.snapshot',
);

static bool checkArtifactExists(String path) {
if (!File(path).existsSync()) {
log.stderr('Could not find $path. Have you built the full '
Expand Down
5 changes: 3 additions & 2 deletions pkg/dartdev/test/analytics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ Future<void> main() async {
});
test('create', () {
final p = project(logAnalytics: true);
final result = p.runSync(['create', '-tpackage-simple', 'name']);
final result =
p.runSync(['create', '--no-pub', '-tpackage-simple', 'name']);
expect(extractAnalytics(result), [
{
'hitType': 'screenView',
Expand All @@ -113,7 +114,7 @@ Future<void> main() async {
'label': null,
'value': null,
'cd1': '0',
'cd3': ' template ',
'cd3': ' pub template ',
}
},
{
Expand Down
4 changes: 0 additions & 4 deletions pkg/dartdev/test/sdk_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ void _sdk() {
expectFileExists(Sdk().analysisServerSnapshot);
});

test('pub snapshot', () {
expectFileExists(Sdk().pubSnapshot);
});

test('dds snapshot', () {
expectFileExists(Sdk().ddsSnapshot);
});
Expand Down
5 changes: 0 additions & 5 deletions sdk/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ declare_args() {
# ........gen_kernel.dart.snapshot (if not on ia32)
# ........kernel-service.dart.snapshot
# ........kernel_worker.dart.snapshot
# ........pub.dart.snapshot
# ......resources/
# ........dartdoc/
# ...........packages
Expand Down Expand Up @@ -140,10 +139,6 @@ _platform_sdk_snapshots = [
"frontend_server",
"../utils/kernel-service:frontend_server",
],
[
"pub",
"../utils/pub",
],
]
if (create_kernel_service_snapshot) {
_platform_sdk_snapshots += [ [
Expand Down
84 changes: 0 additions & 84 deletions sdk/bin/pub

This file was deleted.

15 changes: 6 additions & 9 deletions sdk/bin/pub_sdk
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PROG_NAME="$(follow_links "$BASH_SOURCE")"

# Handle the case where dart-sdk/bin has been symlinked to.
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"

DART="$BIN_DIR/dart"

unset VM_OPTIONS
declare -a VM_OPTIONS
Expand All @@ -39,12 +39,9 @@ if [[ $DART_VM_OPTIONS ]]; then
VM_OPTIONS+=("${OPTIONS[@]}")
fi

# Run the pub snapshot.
DART="$BIN_DIR/dart"
if array_contains "--no-preview-dart-2" "${VM_OPTIONS[@]}"; then
echo "Pub no longer supports Dart 1"
exit -1
else
SNAPSHOT="$BIN_DIR/snapshots/pub.dart.snapshot"
exec "$DART" "${VM_OPTIONS[@]}" "$SNAPSHOT" "$@"
if [ -t 2 ]; then # Only print warning when run in terminal.
>&2 echo 'The top level `pub` command is deprecated. Use `dart pub` instead.'
fi

# Forward to the `dart __deprecatedpub` command.
exec "$DART" "${VM_OPTIONS[@]}" __deprecated_pub "$@"
7 changes: 2 additions & 5 deletions sdk/bin/pub_sdk.bat
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ if not "_%DART_VM_OPTIONS%_" == "__" (
)
)

if defined USING_DART_1 (
echo "Pub no longer supports Dart 1"
) else (
"%BIN_DIR%\dart" %VM_OPTIONS% "%BIN_DIR%\snapshots\pub.dart.snapshot" %*
)
echo "The top level `pub.bat` command is deprecated. Use `dart pub` instead." 1>&2
"%BIN_DIR%\dart" %VM_OPTIONS% __deprecated_pub %*

endlocal

Expand Down
21 changes: 0 additions & 21 deletions utils/pub/.gitignore

This file was deleted.

11 changes: 0 additions & 11 deletions utils/pub/BUILD.gn

This file was deleted.

0 comments on commit ae81cd5

Please sign in to comment.