Commit 357fbf8a authored by Adam Barth's avatar Adam Barth

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
parent 0c05666e
#!/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<String> 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<String> 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<String> 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");
}
......@@ -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<String> args) async {
..addCommand(new StopCommand())
..addCommand(new TestCommand())
..addCommand(new TraceCommand())
..addCommand(new UpdatePackagesCommand(hideCommand: !verboseHelp))
..addCommand(new UpgradeCommand());
return Chain.capture(() async {
......
// 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<int> _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<int> 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;
}
}
......@@ -12,7 +12,9 @@ import '../globals.dart';
Future<int> 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<int> 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(
<String>[sdkBinaryName('pub'), '--verbosity=warning', 'get'],
<String>[sdkBinaryName('pub'), '--verbosity=warning', command],
workingDirectory: directory
);
if (code != 0)
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment