Skip to content

Commit b308456

Browse files
committed
Auto-run "pub get" more for "pub run".
Currently we don't auto-run "pub get" if there's no lockfile and also no dependencies. We should, in order to create a self-link. [email protected] Review URL: https://codereview.chromium.org//1277633004 .
1 parent 11daef3 commit b308456

14 files changed

+41
-50
lines changed

lib/src/entrypoint.dart

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -425,37 +425,26 @@ class Entrypoint {
425425

426426
/// Gets dependencies if the lockfile is out of date with respect to the
427427
/// pubspec.
428-
Future ensureLockFileIsUpToDate() {
429-
return new Future.sync(() {
430-
// If we don't have a current lock file, we definitely need to install.
431-
if (!_isLockFileUpToDate(lockFile)) {
432-
if (lockFileExists) {
433-
log.message(
434-
"Your pubspec has changed, so we need to update your lockfile:");
435-
} else {
436-
log.message(
437-
"You don't have a lockfile, so we need to generate that:");
438-
}
439-
440-
return false;
441-
}
442-
443-
// If we do have a lock file, we still need to make sure the packages
444-
// are actually installed. The user may have just gotten a package that
428+
Future ensureLockFileIsUpToDate() async {
429+
if (!lockFileExists) {
430+
log.message(
431+
"You don't have a lockfile, so we need to generate that:");
432+
} else if (_isLockFileUpToDate(lockFile)) {
433+
// If we do have a lock file, we still need to make sure the packages are
434+
// actually installed. The user may have just gotten a package that
445435
// includes a lockfile.
446-
return _arePackagesAvailable(lockFile).then((available) {
447-
if (!available) {
448-
log.message(
449-
"You are missing some dependencies, so we need to install them "
450-
"first:");
451-
}
436+
if (await _arePackagesAvailable(lockFile)) return;
452437

453-
return available;
454-
});
455-
}).then((upToDate) {
456-
if (upToDate) return null;
457-
return acquireDependencies(SolveType.GET);
458-
});
438+
// If we don't have a current lock file, we definitely need to install.
439+
log.message(
440+
"You are missing some dependencies, so we need to install them "
441+
"first:");
442+
} else {
443+
log.message(
444+
"Your pubspec has changed, so we need to update your lockfile:");
445+
}
446+
447+
await acquireDependencies(SolveType.GET);
459448
}
460449

461450
/// Loads the package graph for the application and all of its transitive

test/run/allows_dart_extension_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ main() {
2424
])
2525
]).create();
2626

27-
var pub = pubRun(args: ["script.dart"]);
27+
var pub = pubRun(args: ["script.dart"], shouldGetFirst: true);
2828
pub.stdout.expect("stdout output");
2929
pub.stderr.expect("stderr output");
3030
pub.shouldExit(123);

test/run/app_can_read_from_stdin_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ main() {
2727
])
2828
]).create();
2929

30-
var pub = pubRun(args: ["bin/script"]);
30+
var pub = pubRun(args: ["bin/script"], shouldGetFirst: true);
3131

3232
pub.stdout.expect("started");
3333
pub.writeLine("first");

test/run/forwards_signal_posix_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ main() {
4141
])
4242
]).create();
4343

44-
var pub = pubRun(args: ["bin/script"]);
44+
var pub = pubRun(args: ["bin/script"], shouldGetFirst: true);
4545

4646
pub.stdout.expect("ready");
4747
for (var signal in _catchableSignals) {

test/run/ignores_explicit_dart2js_transformer_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ main() {
1717
])
1818
]).create();
1919

20-
var pub = pubRun(args: ["bin/script"]);
20+
var pub = pubRun(args: ["bin/script"], shouldGetFirst: true);
2121
pub.stdout.expect("Hello!");
2222
pub.shouldExit(0);
2323
});

test/run/includes_parent_directories_of_entrypoint_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ main() {
3131
])
3232
]).create();
3333

34-
var pub = pubRun(args: [path.join("tool", "a", "b", "app")]);
34+
var pub = pubRun(args: [path.join("tool", "a", "b", "app")],
35+
shouldGetFirst: true);
3536
pub.stdout.expect("a b");
3637
pub.shouldExit();
3738
});

test/run/loads_package_imports_in_a_dependency_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ main() => print(value);
2727
})
2828
]).create();
2929

30-
pubGet();
31-
32-
var pub = pubRun(args: ["foo:bar"]);
30+
var pub = pubRun(args: ["foo:bar"], shouldGetFirst: true);
3331
pub.stdout.expect("foobar");
3432
pub.shouldExit();
3533
});

test/run/passes_along_arguments_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ main() {
2222

2323
// Use some args that would trip up pub's arg parser to ensure that it
2424
// isn't trying to look at them.
25-
var pub = pubRun(args: ["bin/args", "--verbose", "-m", "--", "help"]);
25+
var pub = pubRun(args: ["bin/args", "--verbose", "-m", "--", "help"],
26+
shouldGetFirst: true);
2627

2728
pub.stdout.expect("--verbose -m -- help");
2829
pub.shouldExit();

test/run/runs_app_in_directory_in_entrypoint_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ main() {
1919
])
2020
]).create();
2121

22-
var pub = pubRun(args: [path.join("tool", "app")]);
22+
var pub = pubRun(args: [path.join("tool", "app")], shouldGetFirst: true);
2323
pub.stdout.expect("tool");
2424
pub.shouldExit();
2525

test/run/runs_app_in_entrypoint_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ main() {
2424
])
2525
]).create();
2626

27-
var pub = pubRun(args: ["bin/script"]);
27+
var pub = pubRun(args: ["bin/script"], shouldGetFirst: true);
2828
pub.stdout.expect("stdout output");
2929
pub.stderr.expect("stderr output");
3030
pub.shouldExit(123);

test/run/runs_named_app_in_dependency_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ main() {
2020
})
2121
]).create();
2222

23-
pubGet();
24-
25-
var pub = pubRun(args: ["foo:bar"]);
23+
var pub = pubRun(args: ["foo:bar"], shouldGetFirst: true);
2624
pub.stdout.expect("foobar");
2725
pub.shouldExit();
2826
});

test/run/runs_named_app_in_dev_dependency_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ main() {
2323
})
2424
]).create();
2525

26-
pubGet();
27-
28-
var pub = pubRun(args: ["foo:bar"]);
26+
var pub = pubRun(args: ["foo:bar"], shouldGetFirst: true);
2927
pub.stdout.expect("foobar");
3028
pub.shouldExit();
3129
});

test/run/runs_shorthand_app_in_dependency_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ main() {
2323
})
2424
]).create();
2525

26-
pubGet();
27-
28-
var pub = pubRun(args: ["foo"]);
26+
var pub = pubRun(args: ["foo"], shouldGetFirst: true);
2927
pub.stdout.expect("foo");
3028
pub.shouldExit();
3129
});

test/test_pub.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,19 @@ void pubDowngrade({Iterable<String> args, output, error, warning,
354354
/// "pub run".
355355
///
356356
/// Returns the `pub run` process.
357-
ScheduledProcess pubRun({bool global: false, Iterable<String> args}) {
357+
ScheduledProcess pubRun({bool shouldGetFirst: false, bool global: false,
358+
Iterable<String> args}) {
358359
var pubArgs = global ? ["global", "run"] : ["run"];
359360
pubArgs.addAll(args);
360361
var pub = startPub(args: pubArgs);
361362

363+
if (shouldGetFirst) {
364+
pub.stdout.expect(consumeThrough(anyOf([
365+
"Got dependencies!",
366+
matches(new RegExp(r"^Changed \d+ dependenc"))
367+
])));
368+
}
369+
362370
// Loading sources and transformers isn't normally printed, but the pub test
363371
// infrastructure runs pub in verbose mode, which enables this.
364372
pub.stdout.expect(consumeWhile(startsWith("Loading")));

0 commit comments

Comments
 (0)