mirror of
https://github.com/flutter/flutter
synced 2024-10-12 19:23:02 +00:00
Expose packagePath
as a getter in FlutterCommand. (#80026)
This commit is contained in:
parent
e8cd4827a0
commit
db51c6d510
|
@ -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,
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue