Use .pub-cache from Flutter root, if it exists. (#13248)

The purpose of this PR is to make it so that when the user runs 'flutter', if they have a .pub-cache directory in their flutter root, we use that instead of the default location for the pub cache. Otherwise, it should act as before.

The eventual goal is to support a pre-populated flutter .zip/.tar.gz file that has everything the developer needs in one bundle. In order for that to actually work, we need to have the pub cache be self-contained, and not in the user's home dir.

Another advantage of this is that if you have multiple flutter repos that you're switching between, then the versions in the pub cache will remain static when you switch between them.
This commit is contained in:
Greg Spencer
2017-12-05 12:02:14 -08:00
committed by GitHub
parent 9db8966f94
commit 72d6bcc3f7
8 changed files with 181 additions and 43 deletions

View File

@@ -65,14 +65,25 @@ dependencies:
}
new File('dev/docs/lib/temp_doc.dart').writeAsStringSync(contents.toString());
final String flutterRoot = Directory.current.path;
final Map<String, String> pubEnvironment = <String, String>{
'FLUTTER_ROOT': flutterRoot,
};
// If there's a .pub-cache dir in the flutter root, use that.
final String pubCachePath = '$flutterRoot/.pub-cache';
if (new Directory(pubCachePath).existsSync()) {
pubEnvironment['PUB_CACHE'] = pubCachePath;
}
final String pubExecutable = '$flutterRoot/bin/cache/dart-sdk/bin/pub';
// Run pub.
Process process = await Process.start(
'../../bin/cache/dart-sdk/bin/pub',
pubExecutable,
<String>['get'],
workingDirectory: 'dev/docs',
environment: <String, String>{
'FLUTTER_ROOT': Directory.current.path,
},
environment: pubEnvironment,
);
printStream(process.stdout, prefix: 'pub:stdout: ');
printStream(process.stderr, prefix: 'pub:stderr: ');
@@ -84,9 +95,10 @@ dependencies:
// Verify which version of dartdoc we're using.
final ProcessResult result = Process.runSync(
'../../bin/cache/dart-sdk/bin/pub',
pubExecutable,
<String>['global', 'run', 'dartdoc', '--version'],
workingDirectory: 'dev/docs',
environment: pubEnvironment,
);
print('\n${result.stdout}');
@@ -113,9 +125,10 @@ dependencies:
}
process = await Process.start(
'../../bin/cache/dart-sdk/bin/pub',
pubExecutable,
args,
workingDirectory: 'dev/docs',
environment: pubEnvironment,
);
printStream(process.stdout, prefix: 'dartdoc:stdout: ',
filter: kVerbose ? const <Pattern>[] : <Pattern>[