From 357fbf8a42bede290ed545901e098e0f8a005c73 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 25 Feb 2016 15:29:58 -0800 Subject: [PATCH] Move update_packages.dart to `flutter update-packages` Now that we don't require the Dart SDK to be in your path, it's hard to run ./dev/update_packages.dart. Instead, you can now run `flutter update-packages`. Fixes #1906 --- dev/update_packages.dart | 45 ---------------- packages/flutter_tools/lib/executable.dart | 2 + .../lib/src/commands/update_packages.dart | 51 +++++++++++++++++++ packages/flutter_tools/lib/src/dart/pub.dart | 9 ++-- travis/setup.sh | 2 +- 5 files changed, 60 insertions(+), 49 deletions(-) delete mode 100755 dev/update_packages.dart create mode 100644 packages/flutter_tools/lib/src/commands/update_packages.dart diff --git a/dev/update_packages.dart b/dev/update_packages.dart deleted file mode 100755 index 8a4cf0e7cd..0000000000 --- a/dev/update_packages.dart +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env dart -// Copyright 2015 The Chromium Authors. 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:io'; - -final String binaryName = Platform.isWindows ? 'pub.bat' : 'pub'; -int runPub(Directory directory, List pubArgs) { - int updateCount = 0; - for (FileSystemEntity dir in directory.listSync()) { - if (dir is Directory && FileSystemEntity.isFileSync(dir.path + Platform.pathSeparator + 'pubspec.yaml')) { - updateCount++; - Stopwatch timer = new Stopwatch()..start(); - stdout.write("Updating ${dir.path}..."); - ProcessResult result = Process.runSync( - binaryName, - pubArgs, - workingDirectory: dir.path - ); - timer.stop(); - stdout.write(" (${timer.elapsedMilliseconds} ms)"); - if (result.exitCode != 0) { - print("... failed with exit code ${result.exitCode}."); - print(result.stdout); - print(result.stderr); - } else { - stdout.write("\n"); - } - } - } - return updateCount; -} - -void main(List arguments) { - Stopwatch timer = new Stopwatch()..start(); - bool upgrade = arguments.length > 0 && arguments[0] == '--upgrade'; - String FLUTTER_ROOT = new File(Platform.script.toFilePath()).parent.parent.path; - List pubArgs = [ upgrade ? 'upgrade' : 'get' ]; - int count = 0; - count += runPub(new Directory("$FLUTTER_ROOT/packages"), pubArgs); - count += runPub(new Directory("$FLUTTER_ROOT/examples"), pubArgs); - String command = "$binaryName ${pubArgs.join(' ')}"; - print("Ran \"$command\" $count times in ${timer.elapsedMilliseconds} ms"); -} diff --git a/packages/flutter_tools/lib/executable.dart b/packages/flutter_tools/lib/executable.dart index 28170e3f7e..4f36412b9e 100644 --- a/packages/flutter_tools/lib/executable.dart +++ b/packages/flutter_tools/lib/executable.dart @@ -28,6 +28,7 @@ import 'src/commands/run_mojo.dart'; import 'src/commands/stop.dart'; import 'src/commands/test.dart'; import 'src/commands/trace.dart'; +import 'src/commands/update_packages.dart'; import 'src/commands/upgrade.dart'; import 'src/device.dart'; import 'src/doctor.dart'; @@ -60,6 +61,7 @@ Future main(List args) async { ..addCommand(new StopCommand()) ..addCommand(new TestCommand()) ..addCommand(new TraceCommand()) + ..addCommand(new UpdatePackagesCommand(hideCommand: !verboseHelp)) ..addCommand(new UpgradeCommand()); return Chain.capture(() async { diff --git a/packages/flutter_tools/lib/src/commands/update_packages.dart b/packages/flutter_tools/lib/src/commands/update_packages.dart new file mode 100644 index 0000000000..eabc692f6f --- /dev/null +++ b/packages/flutter_tools/lib/src/commands/update_packages.dart @@ -0,0 +1,51 @@ +// Copyright 2015 The Chromium Authors. 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 '../artifacts.dart'; +import '../dart/pub.dart'; +import '../globals.dart'; +import '../runner/flutter_command.dart'; + +Future _runPub(Directory directory, { bool upgrade: false }) async { + int updateCount = 0; + for (FileSystemEntity dir in directory.listSync()) { + if (dir is Directory && FileSystemEntity.isFileSync(dir.path + Platform.pathSeparator + 'pubspec.yaml')) { + updateCount++; + await pubGet(directory: dir.path, upgrade: upgrade, checkLastModified: false); + } + } + return updateCount; +} + +class UpdatePackagesCommand extends FlutterCommand { + UpdatePackagesCommand({ hideCommand: false }) : _hideCommand = hideCommand { + argParser.addFlag( + 'upgrade', + help: 'Run "pub upgrade" rather than "pub get".', + defaultsTo: false + ); + } + + final String name = 'update-packages'; + final String description = 'Update the packages inside the Flutter repo.'; + + bool get hidden => _hideCommand; + final bool _hideCommand; + + bool get requiresProjectRoot => false; + + @override + Future runInProject() async { + Stopwatch timer = new Stopwatch()..start(); + int count = 0; + bool upgrade = argResults['upgrade']; + count += await _runPub(new Directory("${ArtifactStore.flutterRoot}/packages"), upgrade: upgrade); + count += await _runPub(new Directory("${ArtifactStore.flutterRoot}/examples"), upgrade: upgrade); + printStatus('Ran "pub" $count time${count == 1 ? "" : "s"} in ${timer.elapsedMilliseconds} ms'); + return 0; + } +} diff --git a/packages/flutter_tools/lib/src/dart/pub.dart b/packages/flutter_tools/lib/src/dart/pub.dart index b419f8df37..4e49cc49d7 100644 --- a/packages/flutter_tools/lib/src/dart/pub.dart +++ b/packages/flutter_tools/lib/src/dart/pub.dart @@ -12,7 +12,9 @@ import '../globals.dart'; Future pubGet({ String directory, - bool skipIfAbsent: false + bool skipIfAbsent: false, + bool upgrade: false, + bool checkLastModified: true }) async { if (directory == null) directory = Directory.current.path; @@ -28,10 +30,11 @@ Future pubGet({ return 1; } - if (!pubSpecLock.existsSync() || pubSpecYaml.lastModifiedSync().isAfter(pubSpecLock.lastModifiedSync())) { + if (!checkLastModified || !pubSpecLock.existsSync() || pubSpecYaml.lastModifiedSync().isAfter(pubSpecLock.lastModifiedSync())) { printStatus("Running 'pub get' in $directory${Platform.pathSeparator}..."); + String command = upgrade ? 'upgrade' : 'get'; int code = await runCommandAndStreamOutput( - [sdkBinaryName('pub'), '--verbosity=warning', 'get'], + [sdkBinaryName('pub'), '--verbosity=warning', command], workingDirectory: directory ); if (code != 0) diff --git a/travis/setup.sh b/travis/setup.sh index 4eb06c2d58..eecff61305 100755 --- a/travis/setup.sh +++ b/travis/setup.sh @@ -9,7 +9,7 @@ set -x # Download dependencies flutter ./bin/flutter --version -./bin/cache/dart-sdk/bin/dart ./dev/update_packages.dart +./bin/flutter update-packages if [ $TRAVIS_PULL_REQUEST = "false" ]; then export CLOUDSDK_CORE_DISABLE_PROMPTS=1