Expose packagePath as a getter in FlutterCommand. (#80026)

This commit is contained in:
Lau Ching Jun 2021-04-08 15:19:10 -07:00 committed by GitHub
parent e8cd4827a0
commit db51c6d510
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 3 deletions

View file

@ -283,6 +283,11 @@ abstract class FlutterCommand extends Command<void> {
return bundle.defaultMainPath;
}
/// Path to the Dart's package config file.
///
/// This can be overridden by some of its subclasses.
String get packagesPath => globalResults['packages'] as String;
void usesPubOption({bool hide = false}) {
argParser.addFlag('pub',
defaultsTo: true,
@ -845,7 +850,7 @@ abstract class FlutterCommand extends Command<void> {
: null;
final File packagesFile = globals.fs.file(
globalResults['packages'] as String ?? globals.fs.path.absolute('.dart_tool', 'package_config.json'));
packagesPath ?? globals.fs.path.absolute('.dart_tool', 'package_config.json'));
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
packagesFile, logger: globals.logger, throwOnError: false);
@ -989,8 +994,7 @@ abstract class FlutterCommand extends Command<void> {
bundleSkSLPath: bundleSkSLPath,
dartExperiments: experiments,
performanceMeasurementFile: performanceMeasurementFile,
packagesPath: globalResults['packages'] as String
?? globals.fs.path.absolute('.dart_tool', 'package_config.json'),
packagesPath: packagesPath ?? globals.fs.path.absolute('.dart_tool', 'package_config.json'),
nullSafetyMode: nullSafetyMode,
codeSizeDirectory: codeSizeDirectory,
androidGradleDaemon: androidGradleDaemon,

View file

@ -15,6 +15,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/signals.dart';
import 'package:flutter_tools/src/base/time.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
@ -540,6 +541,12 @@ void main() {
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('use packagesPath to generate BuildInfo', () async {
final DummyFlutterCommand flutterCommand = DummyFlutterCommand(packagesPath: 'foo');
final BuildInfo buildInfo = await flutterCommand.getBuildInfo(forcedBuildMode: BuildMode.debug);
expect(buildInfo.packagesPath, 'foo');
});
});
}

View file

@ -15,6 +15,7 @@ class DummyFlutterCommand extends FlutterCommand {
this.noUsagePath = false,
this.name = 'dummy',
this.commandFunction,
this.packagesPath,
});
final bool noUsagePath;
@ -36,4 +37,7 @@ class DummyFlutterCommand extends FlutterCommand {
Future<FlutterCommandResult> runCommand() async {
return commandFunction == null ? FlutterCommandResult.fail() : await commandFunction();
}
@override
final String packagesPath;
}