[flutter_tools] migrate .packages to package_config, partial (#70200)
This commit is contained in:
@@ -32,7 +32,7 @@ class BuildInfo {
|
||||
this.dartExperiments = const <String>[],
|
||||
@required this.treeShakeIcons,
|
||||
this.performanceMeasurementFile,
|
||||
this.packagesPath = '.packages',
|
||||
this.packagesPath = '.packages', // TODO(jonahwilliams): make this required and remove the default.
|
||||
this.nullSafetyMode = NullSafetyMode.autodetect,
|
||||
this.codeSizeDirectory,
|
||||
this.androidGradleDaemon = true,
|
||||
|
||||
@@ -81,9 +81,7 @@ class BundleBuilder {
|
||||
String manifestPath = defaultManifestPath,
|
||||
String applicationKernelFilePath,
|
||||
String depfilePath,
|
||||
String privateKeyPath = defaultPrivateKeyPath,
|
||||
String assetDirPath,
|
||||
String packagesPath,
|
||||
bool precompiledSnapshot = false,
|
||||
bool reportLicensedPackages = false,
|
||||
bool trackWidgetCreation = false,
|
||||
@@ -96,7 +94,6 @@ class BundleBuilder {
|
||||
mainPath ??= defaultMainPath;
|
||||
depfilePath ??= defaultDepfilePath;
|
||||
assetDirPath ??= getAssetBuildDirectory();
|
||||
packagesPath ??= globals.fs.path.absolute('.packages');
|
||||
final FlutterProject flutterProject = FlutterProject.current();
|
||||
await buildWithAssemble(
|
||||
buildMode: buildInfo.mode,
|
||||
|
||||
@@ -741,7 +741,7 @@ class PubDependencies extends ArtifactSet {
|
||||
FileSystem fileSystem,
|
||||
) async {
|
||||
final File toolPackageConfig = fileSystem.file(
|
||||
fileSystem.path.join(_flutterRoot(), 'packages', 'flutter_tools', kPackagesFileName),
|
||||
fileSystem.path.join(_flutterRoot(), 'packages', 'flutter_tools', '.dart_tool', 'package_config.json'),
|
||||
);
|
||||
if (!toolPackageConfig.existsSync()) {
|
||||
return false;
|
||||
|
||||
@@ -121,7 +121,6 @@ class BuildBundleCommand extends BuildSubCommand {
|
||||
mainPath: targetFile,
|
||||
manifestPath: stringArg('manifest'),
|
||||
depfilePath: stringArg('depfile'),
|
||||
privateKeyPath: stringArg('private-key'),
|
||||
assetDirPath: stringArg('asset-dir'),
|
||||
precompiledSnapshot: boolArg('precompiled'),
|
||||
reportLicensedPackages: boolArg('report-licensed-packages'),
|
||||
|
||||
@@ -171,6 +171,7 @@ class TestCommand extends FlutterCommand {
|
||||
final List<String> plainNames = stringsArg('plain-name');
|
||||
final String tags = stringArg('tags');
|
||||
final String excludeTags = stringArg('exclude-tags');
|
||||
final BuildInfo buildInfo = getBuildInfo(forcedBuildMode: BuildMode.debug);
|
||||
|
||||
if (buildTestAssets && flutterProject.manifest.assets.isNotEmpty) {
|
||||
await _buildTestAsset();
|
||||
@@ -225,6 +226,8 @@ class TestCommand extends FlutterCommand {
|
||||
collector = CoverageCollector(
|
||||
verbose: !machine,
|
||||
libraryPredicate: (String libraryName) => libraryName.contains(projectName),
|
||||
// TODO(jonahwilliams): file bug for incorrect URI handling on windws
|
||||
packagesPath: globals.fs.path.absolute('.packages'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -236,7 +239,6 @@ class TestCommand extends FlutterCommand {
|
||||
}
|
||||
|
||||
final bool disableServiceAuthCodes = boolArg('disable-service-auth-codes');
|
||||
final BuildInfo buildInfo = getBuildInfo(forcedBuildMode: BuildMode.debug);
|
||||
|
||||
final int result = await testRunner.runTests(
|
||||
testWrapper,
|
||||
|
||||
@@ -11,23 +11,10 @@ import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/logger.dart';
|
||||
|
||||
const String kPackagesFileName = '.packages';
|
||||
|
||||
// No touching!
|
||||
String get globalPackagesPath => _globalPackagesPath ?? kPackagesFileName;
|
||||
|
||||
set globalPackagesPath(String value) {
|
||||
_globalPackagesPath = value;
|
||||
}
|
||||
|
||||
bool get isUsingCustomPackagesPath => _globalPackagesPath != null;
|
||||
|
||||
String _globalPackagesPath;
|
||||
|
||||
/// Load the package configuration from [file] or throws a [ToolExit]
|
||||
/// if the operation would fail.
|
||||
///
|
||||
/// If [nonFatal] is true, in the event of an error an empty package
|
||||
/// If [throwOnError] is false, in the event of an error an empty package
|
||||
/// config is returned.
|
||||
Future<PackageConfig> loadPackageConfigWithLogging(File file, {
|
||||
@required Logger logger,
|
||||
|
||||
@@ -1092,7 +1092,7 @@ Future<Directory> _loadDwdsDirectory(
|
||||
final String toolPackagePath =
|
||||
fileSystem.path.join(Cache.flutterRoot, 'packages', 'flutter_tools');
|
||||
final String packageFilePath =
|
||||
fileSystem.path.join(toolPackagePath, kPackagesFileName);
|
||||
fileSystem.path.join(toolPackagePath, '.dart_tool', 'package_config.json');
|
||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||
fileSystem.file(packageFilePath),
|
||||
logger: logger,
|
||||
|
||||
@@ -369,9 +369,8 @@ class FlutterDevice {
|
||||
|
||||
Future<Uri> setupDevFS(
|
||||
String fsName,
|
||||
Directory rootDirectory, {
|
||||
String packagesFilePath,
|
||||
}) {
|
||||
Directory rootDirectory,
|
||||
) {
|
||||
// One devFS per device. Shared by all running instances.
|
||||
devFS = DevFS(
|
||||
vmService,
|
||||
|
||||
@@ -366,7 +366,6 @@ class HotRunner extends ResidentRunner {
|
||||
await device.setupDevFS(
|
||||
fsName,
|
||||
globals.fs.directory(projectRootPath),
|
||||
packagesFilePath: packagesFilePath,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import '../build_system/targets/icon_tree_shaker.dart' show kIconTreeShakerEnabl
|
||||
import '../bundle.dart' as bundle;
|
||||
import '../cache.dart';
|
||||
import '../dart/generate_synthetic_packages.dart';
|
||||
import '../dart/package_map.dart';
|
||||
import '../dart/pub.dart';
|
||||
import '../device.dart';
|
||||
import '../features.dart';
|
||||
@@ -882,7 +881,8 @@ abstract class FlutterCommand extends Command<void> {
|
||||
bundleSkSLPath: bundleSkSLPath,
|
||||
dartExperiments: experiments,
|
||||
performanceMeasurementFile: performanceMeasurementFile,
|
||||
packagesPath: globalResults['packages'] as String ?? '.packages',
|
||||
packagesPath: globalResults['packages'] as String
|
||||
?? globals.fs.path.absolute('.dart_tool', 'package_config.json'),
|
||||
nullSafetyMode: nullSafetyMode,
|
||||
codeSizeDirectory: codeSizeDirectory,
|
||||
androidGradleDaemon: androidGradleDaemon,
|
||||
@@ -1174,7 +1174,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
@protected
|
||||
@mustCallSuper
|
||||
Future<void> validateCommand() async {
|
||||
if (_requiresPubspecYaml && !isUsingCustomPackagesPath) {
|
||||
if (_requiresPubspecYaml && !globalResults.wasParsed('packages')) {
|
||||
// Don't expect a pubspec.yaml file if the user passed in an explicit .packages file path.
|
||||
|
||||
// If there is no pubspec in the current directory, look in the parent
|
||||
|
||||
@@ -16,7 +16,6 @@ import '../base/user_messages.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../cache.dart';
|
||||
import '../convert.dart';
|
||||
import '../dart/package_map.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../tester/flutter_tester.dart';
|
||||
|
||||
@@ -82,19 +81,9 @@ class FlutterCommandRunner extends CommandRunner<void> {
|
||||
argParser.addFlag('suppress-analytics',
|
||||
negatable: false,
|
||||
help: 'Suppress analytics reporting when this command runs.');
|
||||
|
||||
String packagesHelp;
|
||||
bool showPackagesCommand;
|
||||
if (globals.fs.isFileSync(kPackagesFileName)) {
|
||||
packagesHelp = '(defaults to "$kPackagesFileName")';
|
||||
showPackagesCommand = verboseHelp;
|
||||
} else {
|
||||
packagesHelp = '(required, since the current directory does not contain a "$kPackagesFileName" file)';
|
||||
showPackagesCommand = true;
|
||||
}
|
||||
argParser.addOption('packages',
|
||||
hide: !showPackagesCommand,
|
||||
help: 'Path to your ".packages" file.\n$packagesHelp');
|
||||
hide: !verboseHelp,
|
||||
help: 'Path to your "package_config.json" file.');
|
||||
if (verboseHelp) {
|
||||
argParser.addSeparator('Local build selection options (not normally required):');
|
||||
}
|
||||
@@ -219,7 +208,8 @@ class FlutterCommandRunner extends CommandRunner<void> {
|
||||
// Set up the tooling configuration.
|
||||
final EngineBuildPaths engineBuildPaths = await globals.localEngineLocator.findEnginePath(
|
||||
topLevelResults['local-engine-src-path'] as String,
|
||||
topLevelResults['local-engine'] as String
|
||||
topLevelResults['local-engine'] as String,
|
||||
topLevelResults['packages'] as String,
|
||||
);
|
||||
if (engineBuildPaths != null) {
|
||||
contextOverrides.addAll(<Type, dynamic>{
|
||||
@@ -254,10 +244,6 @@ class FlutterCommandRunner extends CommandRunner<void> {
|
||||
await globals.flutterVersion.checkFlutterVersionFreshness();
|
||||
}
|
||||
|
||||
if (topLevelResults.wasParsed('packages')) {
|
||||
globalPackagesPath = globals.fs.path.normalize(globals.fs.path.absolute(topLevelResults['packages'] as String));
|
||||
}
|
||||
|
||||
// See if the user specified a specific device.
|
||||
globals.deviceManager.specifiedDeviceId = topLevelResults['device-id'] as String;
|
||||
|
||||
|
||||
@@ -47,13 +47,16 @@ class LocalEngineLocator {
|
||||
final UserMessages _userMessages;
|
||||
|
||||
/// Returns the engine build path of a local engine if one is located, otherwise `null`.
|
||||
Future<EngineBuildPaths> findEnginePath(String engineSourcePath, String localEngine) async {
|
||||
Future<EngineBuildPaths> findEnginePath(String engineSourcePath, String localEngine, String packagePath) async {
|
||||
engineSourcePath ??= _platform.environment[kFlutterEngineEnvironmentVariableName];
|
||||
|
||||
if (engineSourcePath == null && localEngine != null) {
|
||||
try {
|
||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||
_fileSystem.file(globalPackagesPath),
|
||||
_fileSystem.file(
|
||||
// TODO(jonahwilliams): update to package_config
|
||||
packagePath ?? _fileSystem.path.join('.packages'),
|
||||
),
|
||||
logger: _logger,
|
||||
throwOnError: false,
|
||||
);
|
||||
|
||||
@@ -281,7 +281,7 @@ Directory _templateDirectoryInPackage(String name, FileSystem fileSystem) {
|
||||
Future<Directory> _templateImageDirectory(String name, FileSystem fileSystem, Logger logger) async {
|
||||
final String toolPackagePath = fileSystem.path.join(
|
||||
Cache.flutterRoot, 'packages', 'flutter_tools');
|
||||
final String packageFilePath = fileSystem.path.join(toolPackagePath, kPackagesFileName);
|
||||
final String packageFilePath = fileSystem.path.join(toolPackagePath, '.dart_tool', 'package_config.json');
|
||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||
fileSystem.file(packageFilePath),
|
||||
logger: logger,
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:coverage/coverage.dart' as coverage;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:vm_service/vm_service.dart' as vm_service;
|
||||
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/process.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../dart/package_map.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../vmservice.dart';
|
||||
|
||||
@@ -17,9 +17,10 @@ import 'watcher.dart';
|
||||
|
||||
/// A class that's used to collect coverage data during tests.
|
||||
class CoverageCollector extends TestWatcher {
|
||||
CoverageCollector({this.libraryPredicate, this.verbose = true});
|
||||
CoverageCollector({this.libraryPredicate, this.verbose = true, @required this.packagesPath});
|
||||
|
||||
final bool verbose;
|
||||
final String packagesPath;
|
||||
Map<String, Map<int, int>> _globalHitmap;
|
||||
bool Function(String) libraryPredicate;
|
||||
|
||||
@@ -66,7 +67,7 @@ class CoverageCollector extends TestWatcher {
|
||||
_logMessage('($observatoryUri): collected coverage data; merging...');
|
||||
_addHitmap(await coverage.createHitmap(
|
||||
data['coverage'] as List<Map<String, dynamic>>,
|
||||
packagesPath: globalPackagesPath,
|
||||
packagesPath: packagesPath,
|
||||
checkIgnoredLines: true,
|
||||
));
|
||||
_logMessage('($observatoryUri): done merging coverage data into global coverage map.');
|
||||
@@ -102,7 +103,7 @@ class CoverageCollector extends TestWatcher {
|
||||
_logMessage('pid $pid ($observatoryUri): collected coverage data; merging...');
|
||||
_addHitmap(await coverage.createHitmap(
|
||||
data['coverage'] as List<Map<String, dynamic>>,
|
||||
packagesPath: globalPackagesPath,
|
||||
packagesPath: packagesPath,
|
||||
checkIgnoredLines: true,
|
||||
));
|
||||
_logMessage('pid $pid ($observatoryUri): done merging coverage data into global coverage map.');
|
||||
@@ -116,12 +117,13 @@ class CoverageCollector extends TestWatcher {
|
||||
Future<String> finalizeCoverage({
|
||||
coverage.Formatter formatter,
|
||||
Directory coverageDirectory,
|
||||
String packagesPath,
|
||||
}) async {
|
||||
if (_globalHitmap == null) {
|
||||
return null;
|
||||
}
|
||||
if (formatter == null) {
|
||||
final coverage.Resolver resolver = coverage.Resolver(packagesPath: globalPackagesPath);
|
||||
final coverage.Resolver resolver = coverage.Resolver(packagesPath: packagesPath);
|
||||
final String packagePath = globals.fs.currentDirectory.path;
|
||||
final List<String> reportOn = coverageDirectory == null
|
||||
? <String>[globals.fs.path.join(packagePath, 'lib')]
|
||||
|
||||
@@ -377,7 +377,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
int ourTestCount,
|
||||
) async {
|
||||
_packageConfig ??= await loadPackageConfigWithLogging(
|
||||
globals.fs.file(globalPackagesPath),
|
||||
globals.fs.file(buildInfo.packagesPath),
|
||||
logger: globals.logger,
|
||||
);
|
||||
globals.printTrace('test $ourTestCount: starting test $testPath');
|
||||
@@ -446,7 +446,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
final Process process = await _startProcess(
|
||||
shellPath,
|
||||
mainDart,
|
||||
packages: globalPackagesPath,
|
||||
packages: buildInfo.packagesPath,
|
||||
enableObservatory: enableObservatory,
|
||||
startPaused: startPaused,
|
||||
disableServiceAuthCodes: disableServiceAuthCodes,
|
||||
|
||||
@@ -90,7 +90,7 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
}
|
||||
|
||||
final Future<PackageConfig> _packagesFuture = loadPackageConfigWithLogging(
|
||||
globals.fs.file(globalPackagesPath),
|
||||
globals.fs.file(globals.fs.path.join('.dart_tool', 'package_config.json')),
|
||||
logger: globals.logger,
|
||||
);
|
||||
|
||||
@@ -864,7 +864,7 @@ class TestGoldenComparator {
|
||||
shellPath,
|
||||
'--disable-observatory',
|
||||
'--non-interactive',
|
||||
'--packages=$globalPackagesPath',
|
||||
'--packages=${globals.fs.path.join('.dart_tool', 'package_config.json')}',
|
||||
output,
|
||||
];
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../build_info.dart';
|
||||
import '../dart/package_map.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../web/compile.dart';
|
||||
@@ -178,11 +177,6 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
||||
buildInfo: buildInfo,
|
||||
);
|
||||
|
||||
// Make the global packages path absolute.
|
||||
// (Makes sure it still works after we change the current directory.)
|
||||
globalPackagesPath =
|
||||
globals.fs.path.normalize(globals.fs.path.absolute(globalPackagesPath));
|
||||
|
||||
// Call package:test's main method in the appropriate directory.
|
||||
final Directory saved = globals.fs.currentDirectory;
|
||||
try {
|
||||
|
||||
@@ -107,7 +107,7 @@ class TestCompiler {
|
||||
initializeFromDill: testFilePath,
|
||||
unsafePackageSerialization: false,
|
||||
dartDefines: buildInfo.dartDefines,
|
||||
packagesPath: globalPackagesPath,
|
||||
packagesPath: buildInfo.packagesPath,
|
||||
extraFrontEndOptions: buildInfo.extraFrontEndOptions,
|
||||
platform: globals.platform,
|
||||
testCompilation: true,
|
||||
@@ -129,7 +129,7 @@ class TestCompiler {
|
||||
}
|
||||
if (_packageConfig == null) {
|
||||
_packageConfig ??= await loadPackageConfigWithLogging(
|
||||
globals.fs.file(globalPackagesPath),
|
||||
globals.fs.file(buildInfo.packagesPath),
|
||||
logger: globals.logger,
|
||||
);
|
||||
// Compilation will fail if there is no flutter_test dependency, since
|
||||
|
||||
Reference in New Issue
Block a user