Reland "Load parent package config" (#153754)

Reverts flutter/flutter#153752
Relands https://github.com/flutter/flutter/pull/150850

Now with attached g3fix
This commit is contained in:
Sigurd Meldgaard
2024-08-20 15:30:46 +02:00
committed by GitHub
parent 990b80aafd
commit a9daf58829
55 changed files with 615 additions and 393 deletions

View File

@@ -95,7 +95,7 @@ void main() {
// Sets up the minimal mock project files necessary to look like a Flutter project.
void createCoreMockProjectFiles() {
fileSystem.file('pubspec.yaml').createSync();
fileSystem.file('.packages').createSync();
fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true);
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
}

View File

@@ -75,7 +75,7 @@ void main() {
expect(projectUnderTest.flutterPluginsFile, isNot(exists));
expect(projectUnderTest.flutterPluginsDependenciesFile, isNot(exists));
expect(projectUnderTest.packagesFile, isNot(exists));
expect(projectUnderTest.directory.childFile('.packages'), isNot(exists));
expect(xcodeProjectInterpreter.workspaces, const <CleanWorkspaceCall>[
CleanWorkspaceCall('/ios/Runner.xcworkspace', 'Runner', false),
@@ -231,7 +231,7 @@ FlutterProject setupProjectUnderTest(Directory currentDirectory, bool setupXcode
projectUnderTest.macos.hostAppRoot.childDirectory('Runner.xcworkspace').createSync(recursive: true);
}
projectUnderTest.dartTool.createSync(recursive: true);
projectUnderTest.packagesFile.createSync(recursive: true);
projectUnderTest.directory.childFile('.packages').createSync(recursive: true);
projectUnderTest.android.ephemeralDirectory.createSync(recursive: true);
projectUnderTest.ios.ephemeralDirectory.createSync(recursive: true);

View File

@@ -117,8 +117,9 @@ void main() {
await commandRunner.run(<String>['get', targetDirectory.path]);
final FlutterProject rootProject = FlutterProject.fromDirectory(targetDirectory);
expect(rootProject.packageConfigFile.existsSync(), true);
expect(await rootProject.packageConfigFile.readAsString(), '{"configVersion":2,"packages":[]}');
final File packageConfigFile = rootProject.dartTool.childFile('package_config.json');
expect(packageConfigFile.existsSync(), true);
expect(packageConfigFile.readAsStringSync(), '{"configVersion":2,"packages":[]}');
}, overrides: <Type, Generator>{
Pub: () => pub,
ProcessManager: () => FakeProcessManager.any(),

View File

@@ -72,7 +72,7 @@ void main() {
testUsingContext('does not support --no-sound-null-safety by default', () async {
fileSystem.file('lib/main.dart').createSync(recursive: true);
fileSystem.file('pubspec.yaml').createSync();
fileSystem.file('.packages').createSync();
fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true);
final TestRunCommandThatOnlyValidates command = TestRunCommandThatOnlyValidates();
await expectLater(
@@ -96,7 +96,7 @@ void main() {
testUsingContext('supports --no-sound-null-safety with an overridden NonNullSafeBuilds', () async {
fileSystem.file('lib/main.dart').createSync(recursive: true);
fileSystem.file('pubspec.yaml').createSync();
fileSystem.file('.packages').createSync();
fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true);
final FakeDevice device = FakeDevice(isLocalEmulator: true, platformType: PlatformType.android);
@@ -118,7 +118,7 @@ void main() {
testUsingContext('does not support "--use-application-binary" and "--fast-start"', () async {
fileSystem.file('lib/main.dart').createSync(recursive: true);
fileSystem.file('pubspec.yaml').createSync();
fileSystem.file('.packages').createSync();
fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true);
final RunCommand command = RunCommand();
await expectLater(
@@ -143,8 +143,14 @@ void main() {
testUsingContext('Walks upward looking for a pubspec.yaml and succeeds if found', () async {
fileSystem.file('pubspec.yaml').createSync();
fileSystem.file('.packages')
.writeAsStringSync('\n');
fileSystem.file('.dart_tool/package_config.json')
..createSync(recursive: true)
..writeAsStringSync('''
{
"packages": [],
"configVersion": 2
}
''');
fileSystem.file('lib/main.dart')
.createSync(recursive: true);
fileSystem.currentDirectory = fileSystem.directory('a/b/c')
@@ -208,8 +214,16 @@ void main() {
fs.currentDirectory.childFile('pubspec.yaml')
.writeAsStringSync('name: flutter_app');
fs.currentDirectory.childFile('.packages')
.writeAsStringSync('# Generated by pub on 2019-11-25 12:38:01.801784.');
fs.currentDirectory
.childDirectory('.dart_tool')
.childFile('package_config.json')
..createSync(recursive: true)
..writeAsStringSync('''
{
"packages": [],
"configVersion": 2
}
''');
final Directory libDir = fs.currentDirectory.childDirectory('lib');
libDir.createSync();
final File mainFile = libDir.childFile('main.dart');
@@ -904,7 +918,14 @@ void main() {
setUp(() {
fileSystem.file('lib/main.dart').createSync(recursive: true);
fileSystem.file('pubspec.yaml').createSync();
fileSystem.file('.packages').createSync();
fileSystem.file('.dart_tool/package_config.json')
..createSync(recursive: true)
..writeAsStringSync('''
{
"packages": [],
"configVersion": 2
}
''');
final FakeDevice device = FakeDevice(isLocalEmulator: true, platformType: PlatformType.android);
testDeviceManager.devices = <Device>[device];
});
@@ -951,7 +972,7 @@ void main() {
testUsingContext('throws a ToolExit when value includes delimiter characters', () async {
fileSystem.file('lib/main.dart').createSync(recursive: true);
fileSystem.file('pubspec.yaml').createSync();
fileSystem.file('.packages').createSync();
fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true);
final RunCommand command = RunCommand();
await expectLater(

View File

@@ -24,7 +24,9 @@ import 'package:flutter_tools/src/commands/packages.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:unified_analytics/unified_analytics.dart';
import 'package:yaml/yaml.dart';
import '../../integration.shard/test_utils.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fake_process_manager.dart';
@@ -315,6 +317,68 @@ flutter:
),
});
testUsingContext('get fetches packages for a workspace', () async {
tempDir.childFile('pubspec.yaml').writeAsStringSync('''
name: workspace
environment:
sdk: ^3.5.0-0
workspace:
- flutter_project
''');
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=module']);
final File pubspecFile = fileSystem.file(
fileSystem.path.join(
projectPath,
'pubspec.yaml',
),
);
final YamlMap pubspecYaml = loadYaml(pubspecFile.readAsStringSync()) as YamlMap;
final Map<String, Object?> pubspec = <String, Object?>{
...pubspecYaml.value.cast<String, Object?>(),
'resolution': 'workspace',
'environment': <String, Object?>{
...(pubspecYaml['environment'] as YamlMap).value.cast<String, Object?>(),
'sdk': '^3.5.0-0',
}
};
pubspecFile.writeAsStringSync(jsonEncode(pubspec));
await runCommandIn(projectPath, 'get');
expect(mockStdio.stdout.writes.map(utf8.decode),
allOf(
// The output of pub changed, adding backticks around the directory name.
// These regexes are tolerant of the backticks being present or absent.
contains(matches(RegExp(r'Resolving dependencies in .+' + RegExp.escape(tempDir.basename) + r'`?\.\.\.'))),
contains(matches(RegExp(r'\+ flutter 0\.0\.0 from sdk flutter'))),
contains(matches(RegExp(r'Changed \d+ dependencies in .+' + RegExp.escape(tempDir.basename) + r'`?!'))),
),
);
expectDependenciesResolved(tempDir.path);
expectZeroPluginsInjected(projectPath);
expect(
analyticsTimingEventExists(
sentEvents: fakeAnalytics.sentEvents,
workflow: 'pub',
variableName: 'get',
label: 'success',
),
true,
);
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
Pub: () => Pub.test(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
Analytics: () => fakeAnalytics,
});
testUsingContext('get generates normal files when l10n.yaml has synthetic-package: false', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=module']);

View File

@@ -32,7 +32,7 @@ void main() {
);
await bundle.build(
packagesPath: '.packages',
packageConfigPath: '.packages',
flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
flavor: flavor,
);

View File

@@ -59,7 +59,7 @@ $fontsSection
String expectedAssetManifest,
) async {
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
for (final String packageName in packages) {
for (final String packageFont in packageFonts) {
@@ -110,7 +110,7 @@ $fontsSection
writePubspecFile('p/p/pubspec.yaml', 'test_package');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(bundle.entries.keys, unorderedEquals(<String>['AssetManifest.bin',
'AssetManifest.json', 'FontManifest.json', 'NOTICES.Z']));
}, overrides: <Type, Generator>{

View File

@@ -78,7 +78,7 @@ $assetsSection
) async {
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
for (final String packageName in packages) {
for (final String asset in assets) {
@@ -138,7 +138,7 @@ $assetsSection
writePubspecFile('p/p/pubspec.yaml', 'test_package');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(bundle.entries.keys, unorderedEquals(
<String>['NOTICES.Z', 'AssetManifest.json', 'AssetManifest.bin', 'FontManifest.json']));
const String expectedAssetManifest = '{}';
@@ -164,7 +164,7 @@ $assetsSection
writeAssets('p/p/', assets);
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(bundle.entries.keys, unorderedEquals(
<String>['NOTICES.Z', 'AssetManifest.json', 'AssetManifest.bin', 'FontManifest.json']));
const String expectedAssetManifest = '{}';
@@ -618,7 +618,7 @@ $assetsSection
writeAssets('p/p/', assetsOnDisk);
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(bundle.entries['AssetManifest.json'], isNull,
reason: 'Invalid pubspec.yaml should not generate AssetManifest.json' );
@@ -698,7 +698,7 @@ $assetsSection
);
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
ProcessManager: () => FakeProcessManager.any(),

View File

@@ -39,7 +39,7 @@ void main() {
testUsingContext('nonempty', () async {
final AssetBundle ab = AssetBundleFactory.instance.createBundle();
expect(await ab.build(packagesPath: '.packages'), 0);
expect(await ab.build(packageConfigPath: '.packages'), 0);
expect(ab.entries.length, greaterThan(0));
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
@@ -53,7 +53,7 @@ void main() {
..writeAsStringSync('');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(bundle.entries.keys,
unorderedEquals(<String>['AssetManifest.json', 'AssetManifest.bin'])
);
@@ -104,7 +104,7 @@ flutter:
}
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(bundle.entries.keys, unorderedEquals(<String>[
'AssetManifest.json',
@@ -132,7 +132,7 @@ flutter:
- assets/foo/
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(bundle.entries.keys, unorderedEquals(<String>['AssetManifest.json',
'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt']));
// Simulate modifying the files by updating the filestat time manually.
@@ -141,7 +141,7 @@ flutter:
..setLastModifiedSync(packageFile.lastModifiedSync().add(const Duration(hours: 1)));
expect(bundle.needsBuild(), true);
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(bundle.entries.keys, unorderedEquals(<String>['AssetManifest.json',
'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt',
'assets/foo/fizz.txt']));
@@ -163,7 +163,7 @@ flutter:
''');
globals.fs.file('.packages').createSync();
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(bundle.entries.keys, unorderedEquals(<String>['AssetManifest.json',
'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt']));
expect(bundle.needsBuild(), false);
@@ -185,7 +185,7 @@ name: example''')
// asset manifest and not updated. This is due to the devfs not
// supporting file deletion.
expect(bundle.needsBuild(), true);
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(bundle.entries.keys, unorderedEquals(<String>['AssetManifest.json',
'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt']));
}, overrides: <Type, Generator>{
@@ -210,7 +210,7 @@ flutter:
''');
globals.fs.file('.packages').createSync();
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(bundle.entries.keys, unorderedEquals(<String>['AssetManifest.json',
'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt']));
expect(bundle.needsBuild(), false);
@@ -244,7 +244,7 @@ flutter:
platform: globals.platform,
splitDeferredAssets: true,
).createBundle();
await bundle.build(packagesPath: '.packages', deferredComponentsEnabled: true);
await bundle.build(packageConfigPath: '.packages', deferredComponentsEnabled: true);
expect(bundle.entries.keys, unorderedEquals(<String>['AssetManifest.json',
'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt']));
expect(bundle.deferredComponentsEntries.length, 1);
@@ -275,7 +275,7 @@ flutter:
- assets/wild/
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(bundle.entries.keys, unorderedEquals(<String>['assets/foo/bar.txt',
'assets/bar/barbie.txt', 'assets/wild/dash.txt', 'AssetManifest.json',
'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z']));
@@ -311,7 +311,7 @@ flutter:
platform: globals.platform,
splitDeferredAssets: true,
).createBundle();
await bundle.build(packagesPath: '.packages', deferredComponentsEnabled: true);
await bundle.build(packageConfigPath: '.packages', deferredComponentsEnabled: true);
expect(bundle.entries.keys, unorderedEquals(<String>['assets/foo/bar.txt',
'AssetManifest.json', 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z']));
expect(bundle.deferredComponentsEntries.length, 1);
@@ -324,7 +324,7 @@ flutter:
..setLastModifiedSync(packageFile.lastModifiedSync().add(const Duration(hours: 1)));
expect(bundle.needsBuild(), true);
await bundle.build(packagesPath: '.packages', deferredComponentsEnabled: true);
await bundle.build(packageConfigPath: '.packages', deferredComponentsEnabled: true);
expect(bundle.entries.keys, unorderedEquals(<String>['assets/foo/bar.txt',
'AssetManifest.json', 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z']));
@@ -366,7 +366,7 @@ flutter:
expect(
() => bundle.build(
packagesPath: '.packages',
packageConfigPath: '.packages',
flutterProject: FlutterProject.fromDirectoryTest(
fileSystem.currentDirectory,
),
@@ -418,7 +418,7 @@ flutter:
expect(
() => bundle.build(
packagesPath: '.packages',
packageConfigPath: '.packages',
flutterProject: FlutterProject.fromDirectoryTest(
fileSystem.currentDirectory,
),
@@ -459,7 +459,7 @@ flutter:
);
await bundle.build(
packagesPath: '.packages',
packageConfigPath: '.packages',
flutterProject: FlutterProject.fromDirectoryTest(
fileSystem.currentDirectory,
),
@@ -468,7 +468,7 @@ flutter:
expect(bundle.entries['my-asset.txt']!.content.isModified, isTrue);
await bundle.build(
packagesPath: '.packages',
packageConfigPath: '.packages',
flutterProject: FlutterProject.fromDirectoryTest(
fileSystem.currentDirectory,
),
@@ -487,7 +487,7 @@ flutter:
''');
await bundle.build(
packagesPath: '.packages',
packageConfigPath: '.packages',
flutterProject: FlutterProject.fromDirectoryTest(
fileSystem.currentDirectory,
),
@@ -513,7 +513,7 @@ flutter:
..writeAsStringSync('');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages', targetPlatform: TargetPlatform.web_javascript);
await bundle.build(packageConfigPath: '.packages', targetPlatform: TargetPlatform.web_javascript);
expect(bundle.entries.keys,
unorderedEquals(<String>[
@@ -552,7 +552,7 @@ flutter:
).createSync(recursive: true);
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages', targetPlatform: TargetPlatform.web_javascript);
await bundle.build(packageConfigPath: '.packages', targetPlatform: TargetPlatform.web_javascript);
expect(bundle.entries.keys,
unorderedEquals(<String>[
@@ -629,13 +629,13 @@ assets:
- assets/foo/bar.txt
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
final AssetBundleEntry? assetManifest = bundle.entries['AssetManifest.json'];
final AssetBundleEntry? fontManifest = bundle.entries['FontManifest.json'];
final AssetBundleEntry? license = bundle.entries['NOTICES'];
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(assetManifest, bundle.entries['AssetManifest.json']);
expect(fontManifest, bundle.entries['FontManifest.json']);
@@ -660,7 +660,7 @@ flutter:
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(packagesPath: '.packages'), 0);
expect(await bundle.build(packageConfigPath: '.packages'), 0);
expect(bundle.additionalDependencies.single.path, contains('DOES_NOT_EXIST_RERUN_FOR_WILDCARD'));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
@@ -682,7 +682,7 @@ flutter:
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(packagesPath: '.packages'), 0);
expect(await bundle.build(packageConfigPath: '.packages'), 0);
expect(bundle.additionalDependencies, isEmpty);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
@@ -726,7 +726,7 @@ flutter:
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(packagesPath: '.packages'), 0);
expect(await bundle.build(packageConfigPath: '.packages'), 0);
await writeBundle(
output,
@@ -779,7 +779,7 @@ flutter:
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(packagesPath: '.packages', targetPlatform: TargetPlatform.web_javascript), 0);
expect(await bundle.build(packageConfigPath: '.packages', targetPlatform: TargetPlatform.web_javascript), 0);
await writeBundle(
output,
@@ -867,7 +867,7 @@ flutter:
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(packagesPath: '.packages', targetPlatform: TargetPlatform.web_javascript), 0);
expect(await bundle.build(packageConfigPath: '.packages', targetPlatform: TargetPlatform.web_javascript), 0);
await writeBundle(
output,
@@ -916,7 +916,7 @@ flutter:
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
globals.fs.file('foo/bar/fizz.txt').createSync(recursive: true);
expect(await bundle.build(packagesPath: '.packages'), 0);
expect(await bundle.build(packageConfigPath: '.packages'), 0);
expect(bundle.additionalDependencies, isEmpty);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
@@ -950,7 +950,7 @@ flutter:
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
globals.fs.file('foo/bar/fizz.txt').createSync(recursive: true);
await bundle.build(packagesPath: '.packages');
await bundle.build(packageConfigPath: '.packages');
expect(bundle.entries.keys, unorderedEquals(<String>['packages/foo/bar/fizz.txt',
'AssetManifest.json', 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z']));
@@ -993,7 +993,7 @@ flutter:
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(packagesPath: '.packages'), 1);
expect(await bundle.build(packageConfigPath: '.packages'), 1);
expect(testLogger.errorText, contains('This asset was included from package foo'));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
@@ -1016,7 +1016,7 @@ flutter:
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(packagesPath: '.packages'), 1);
expect(await bundle.build(packageConfigPath: '.packages'), 1);
expect(testLogger.errorText, isNot(contains('This asset was included from')));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
@@ -1050,7 +1050,7 @@ flutter:
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(packagesPath: '.packages'), 0);
expect(await bundle.build(packageConfigPath: '.packages'), 0);
expect((bundle.entries['FontManifest.json']!.content as DevFSStringContent).string, '[]');
expect((bundle.entries['AssetManifest.json']!.content as DevFSStringContent).string, '{}');
expect(testLogger.errorText, contains(
@@ -1087,7 +1087,7 @@ flutter:
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(packagesPath: '.packages'), 0);
expect(await bundle.build(packageConfigPath: '.packages'), 0);
expect(bundle.entries.keys, unorderedEquals(<String>['assets/foo.txt',
'AssetManifest.json', 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z']));
}, overrides: <Type, Generator>{
@@ -1122,7 +1122,7 @@ flutter:
globals.fs.file('assets/zebra.jpg').createSync();
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(packagesPath: '.packages'), 0);
expect(await bundle.build(packageConfigPath: '.packages'), 0);
expect((bundle.entries['FontManifest.json']!.content as DevFSStringContent).string, '[]');
// The assets from deferred components and regular assets
// are both included in alphabetical order

View File

@@ -99,7 +99,7 @@ ${assets.map((String entry) => ' - $entry').join('\n')}
);
await bundle.build(
packagesPath: '.packages',
packageConfigPath: '.packages',
flutterProject: FlutterProject.fromDirectoryTest(fs.currentDirectory),
);
@@ -154,7 +154,7 @@ ${assets.map((String entry) => ' - $entry').join('\n')}
);
await bundle.build(
packagesPath: '.packages',
packageConfigPath: '.packages',
flutterProject: FlutterProject.fromDirectoryTest(fs.currentDirectory),
);
@@ -210,7 +210,7 @@ ${assets.map((String entry) => ' - $entry').join('\n')}
);
await bundle.build(
packagesPath: '.packages',
packageConfigPath: '.packages',
flutterProject: FlutterProject.fromDirectoryTest(fs.currentDirectory),
);
@@ -256,7 +256,7 @@ ${assets.map((String entry) => ' - $entry').join('\n')}
);
await bundle.build(
packagesPath: '.packages',
packageConfigPath: '.packages',
flutterProject: FlutterProject.fromDirectoryTest(fs.currentDirectory),
);
@@ -328,7 +328,7 @@ flutter:
);
await bundle.build(
packagesPath: '.packages',
packageConfigPath: '.packages',
flutterProject: FlutterProject.fromDirectoryTest(fs.currentDirectory),
);

View File

@@ -115,7 +115,7 @@ dependencies:
''');
await assetBundle.build(
packagesPath: packagesPath,
packageConfigPath: packagesPath,
manifestPath: manifestPath,
flutterProject: FlutterProject.fromDirectoryTest(fileSystem.directory('main')),
);
@@ -155,7 +155,7 @@ dependencies:
await assetBundle.build(
manifestPath: manifestPath, // file doesn't exist
packagesPath: packagesPath,
packageConfigPath: packagesPath,
flutterProject: FlutterProject.fromDirectoryTest(fileSystem.file(manifestPath).parent),
);
@@ -203,7 +203,7 @@ dependencies:
);
await assetBundle.build(
packagesPath: '.packages',
packageConfigPath: '.packages',
targetPlatform: TargetPlatform.android_arm,
flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
);
@@ -248,7 +248,7 @@ dependencies:
);
await assetBundle.build(
packagesPath: '.packages',
packageConfigPath: '.packages',
targetPlatform: TargetPlatform.web_javascript,
flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
);

View File

@@ -33,7 +33,7 @@ const List<String> _kDart2WasmLinuxArgs = <String> [
'Artifact.engineDartBinary.TargetPlatform.web_javascript',
'compile',
'wasm',
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--extra-compiler-option=--platform=HostArtifact.webPlatformKernelFolder/dart2wasm_platform.dill',
'--extra-compiler-option=--delete-tostring-package-uri=dart:ui',
'--extra-compiler-option=--delete-tostring-package-uri=package:flutter',
@@ -53,9 +53,21 @@ void main() {
setUp(() {
testbed = Testbed(setup: () {
globals.fs.file('.packages')
globals.fs.directory('.dart_tool').childFile('package_config.json')
..createSync(recursive: true)
..writeAsStringSync('foo:foo/lib/\n');
..writeAsStringSync('''
{
"configVersion": 2,
"packages": [
{
"name": "foo",
"rootUri": "../foo/",
"packageUri": "lib/",
"languageVersion": "2.7"
}
]
}
''');
globals.fs.currentDirectory.childDirectory('bar').createSync();
processManager = FakeProcessManager.empty();
globals.fs.file('bin/cache/flutter_web_sdk/flutter_js/flutter.js')
@@ -395,7 +407,7 @@ void main() {
'--no-source-maps',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
]
@@ -440,7 +452,7 @@ void main() {
'--no-source-maps',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
]
@@ -484,7 +496,7 @@ void main() {
'--no-source-maps',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
]
@@ -527,7 +539,7 @@ void main() {
'--no-source-maps',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
]
@@ -569,7 +581,7 @@ void main() {
'--no-source-maps',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
]
@@ -612,7 +624,7 @@ void main() {
'--no-source-maps',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
]
@@ -655,7 +667,7 @@ void main() {
'--no-source-maps',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
]
@@ -697,7 +709,7 @@ void main() {
'--no-source-maps',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
], onRun: (_) {
@@ -751,7 +763,7 @@ void main() {
'--no-source-maps',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
]
@@ -794,7 +806,7 @@ void main() {
'-DFLUTTER_WEB_CANVASKIT_URL=https://www.gstatic.com/flutter-canvaskit/abcdefghijklmnopqrstuvwxyz/',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
]
@@ -836,7 +848,7 @@ void main() {
'--no-source-maps',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
]
@@ -883,7 +895,7 @@ void main() {
'--enable-asserts',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
]
@@ -929,7 +941,7 @@ void main() {
'--no-source-maps',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
]
@@ -974,7 +986,7 @@ void main() {
'--no-source-maps',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=.dart_tool/package_config.json',
'--packages=/.dart_tool/package_config.json',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
]

View File

@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:convert';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/dart/package_map.dart';
@@ -34,7 +36,10 @@ void main() {
..flutterPluginsFile = directory.childFile('.flutter-plugins')
..flutterPluginsDependenciesFile = directory.childFile('.flutter-plugins-dependencies')
..dartPluginRegistrant = directory.childFile('dart_plugin_registrant.dart');
flutterProject.directory.childFile('.packages').createSync(recursive: true);
flutterProject.directory
.childDirectory('.dart_tool')
.childFile('package_config.json')
.createSync(recursive: true);
});
group('resolvePlatformImplementation', () {
@@ -1492,6 +1497,26 @@ void main() {
});
}
void addToPackageConfig(
FlutterProject project,
String name,
Directory packageDir) {
final File packageConfigFile = project.directory
.childDirectory('.dart_tool')
.childFile('package_config.json');
final Map<String, Object?> packageConfig =
jsonDecode(packageConfigFile.readAsStringSync()) as Map<String, Object?>;
(packageConfig['packages']! as List<Object?>).add(<String, Object?>{
'name': name,
'rootUri': packageDir.uri.toString(),
'packageUri': 'lib/',
});
packageConfigFile.writeAsStringSync(jsonEncode(packageConfig));
}
void createFakeDartPlugins(
FakeFlutterProject flutterProject,
FakeFlutterManifest flutterManifest,
@@ -1499,20 +1524,23 @@ void createFakeDartPlugins(
Map<String, String> plugins,
) {
final Directory fakePubCache = fs.systemTempDirectory.childDirectory('cache');
final File packagesFile = flutterProject.directory
.childFile('.packages');
if (packagesFile.existsSync()) {
packagesFile.deleteSync();
}
packagesFile.createSync(recursive: true);
flutterProject.directory
.childDirectory('.dart_tool')
.childFile('package_config.json')
..deleteSync(recursive: true)
..createSync(recursive: true)
..writeAsStringSync('''
{
"packages": [],
"configVersion": 2
}
''');
for (final MapEntry<String, String> entry in plugins.entries) {
final String name = fs.path.basename(entry.key);
final Directory pluginDirectory = fakePubCache.childDirectory(name);
packagesFile.writeAsStringSync(
'$name:file://${pluginDirectory.childFile('lib').uri}\n',
mode: FileMode.writeOnlyAppend,
);
addToPackageConfig(flutterProject, name, pluginDirectory);
pluginDirectory.childFile('pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync(entry.value);

View File

@@ -948,7 +948,7 @@ class FakeBundle extends AssetBundle {
Future<int> build({
String manifestPath = defaultManifestPath,
String? assetDirPath,
String? packagesPath,
String? packageConfigPath,
bool deferredComponentsEnabled = false,
TargetPlatform? targetPlatform,
String? flavor,

View File

@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:convert';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
@@ -756,6 +758,27 @@ duplicate symbol '_$s29plugin_1_name23PluginNamePluginC9setDouble3key5valueySS_S
});
}
void addToPackageConfig(
FlutterProject flutterProject,
String name,
Directory packageDir,
) {
final File packageConfigFile = flutterProject.directory
.childDirectory('.dart_tool')
.childFile('package_config.json');
final Map<String, Object?> packageConfig =
jsonDecode(packageConfigFile.readAsStringSync()) as Map<String, Object?>;
(packageConfig['packages']! as List<Object?>).add(<String, Object?>{
'name': name,
'rootUri': packageDir.uri.toString(),
'packageUri': 'lib/',
});
packageConfigFile.writeAsStringSync(jsonEncode(packageConfig));
}
void createFakePlugins(
FlutterProject flutterProject,
FileSystem fileSystem,
@@ -772,13 +795,17 @@ void createFakePlugins(
''';
final Directory fakePubCache = fileSystem.systemTempDirectory.childDirectory('cache');
final File packagesFile = flutterProject.directory.childFile('.packages')
..createSync(recursive: true);
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json')
..createSync(recursive: true)
..writeAsStringSync('''
{
"packages": [],
"configVersion": 2
}
''');
for (final String name in pluginNames) {
final Directory pluginDirectory = fakePubCache.childDirectory(name);
packagesFile.writeAsStringSync(
'$name:${pluginDirectory.childFile('lib').uri}\n',
mode: FileMode.writeOnlyAppend);
addToPackageConfig(flutterProject, name, pluginDirectory);
pluginDirectory.childFile('pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync(pluginYamlTemplate.replaceAll('PLUGIN_CLASS', name));

View File

@@ -165,6 +165,7 @@ class FakeHotRunnerNativeAssetsBuilder implements HotRunnerNativeAssetsBuilder {
required Uri projectUri,
required FileSystem fileSystem,
required List<FlutterDevice> flutterDevices,
required String packageConfigPath,
required PackageConfig packageConfig,
required Logger logger,
}) {

View File

@@ -469,18 +469,18 @@ void main() {
await fileSystem.file('/some/path/to/llvm-ar').create();
await fileSystem.file('/some/path/to/ld.lld').create();
final File packagesFile = fileSystem
final File packageConfigFile = fileSystem
.directory(projectUri)
.childDirectory('.dart_tool')
.childFile('package_config.json');
await packagesFile.parent.create();
await packagesFile.create();
await packageConfigFile.parent.create();
await packageConfigFile.create();
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
packagesFile,
packageConfigFile,
logger: environment.logger,
);
final NativeAssetsBuildRunner runner =
NativeAssetsBuildRunnerImpl(projectUri, packageConfig, fileSystem, logger);
NativeAssetsBuildRunnerImpl(projectUri, packageConfigFile.path, packageConfig, fileSystem, logger);
final CCompilerConfigImpl result = await runner.cCompilerConfig;
expect(result.compiler, Uri.file('/some/path/to/clang'));
});

View File

@@ -497,18 +497,19 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault
return;
}
final File packagesFile = fileSystem
final File packageConfigFile = fileSystem
.directory(projectUri)
.childDirectory('.dart_tool')
.childFile('package_config.json');
await packagesFile.parent.create();
await packagesFile.create();
await packageConfigFile.parent.create();
await packageConfigFile.create();
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
packagesFile,
packageConfigFile,
logger: environment.logger,
);
final NativeAssetsBuildRunner runner = NativeAssetsBuildRunnerImpl(
projectUri,
packageConfigFile.path,
packageConfig,
fileSystem,
logger,

View File

@@ -491,18 +491,19 @@ void main() {
fileSystem.directory(r'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\bin\Hostx64\x64');
await msvcBinDir.create(recursive: true);
final File packagesFile = fileSystem
final File packageConfigFile = fileSystem
.directory(projectUri)
.childDirectory('.dart_tool')
.childFile('package_config.json');
await packagesFile.parent.create();
await packagesFile.create();
await packageConfigFile.parent.create();
await packageConfigFile.create();
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
packagesFile,
packageConfigFile,
logger: environment.logger,
);
final NativeAssetsBuildRunner runner = NativeAssetsBuildRunnerImpl(
projectUri,
packageConfigFile.path,
packageConfig,
fileSystem,
logger,

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:convert';
import 'package:file/file.dart';
import 'package:file/memory.dart';
@@ -35,7 +36,14 @@ void main() {
..web = FakeWebProject()
..windows = FakeWindowsProject()
..linux = FakeLinuxProject();
flutterProject.directory.childFile('.packages').createSync(recursive: true);
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json')
..createSync(recursive: true)
..writeAsStringSync('''
{
"packages": [],
"configVersion": 2
}
''');
}
setUp(() async {
@@ -60,17 +68,25 @@ void main() {
''';
final Directory fakePubCache = fileSystem.systemTempDirectory.childDirectory('cache');
final File packagesFile = flutterProject.directory.childFile('.packages')
final File packageConfigFile = flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json')
..createSync(recursive: true);
final Map<String, Object?> packageConfig = <String, Object?>{
'packages': <Object?>[],
'configVersion': 2,
};
for (final String name in pluginNames) {
final Directory pluginDirectory = fakePubCache.childDirectory(name);
packagesFile.writeAsStringSync(
'$name:${pluginDirectory.childFile('lib').uri}\n',
mode: FileMode.writeOnlyAppend);
(packageConfig['packages']! as List<Object?>).add(<String, Object?>{
'name': name,
'rootUri': pluginDirectory.uri.toString(),
'packageUri': 'lib/',
});
pluginDirectory.childFile('pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync(pluginYamlTemplate.replaceAll('PLUGIN_CLASS', name));
}
packageConfigFile.writeAsStringSync(jsonEncode(packageConfig));
}
group('for iOS', () {

View File

@@ -330,12 +330,13 @@ void main() {
group('Update xcconfig', () {
testUsingContext('includes Pod config in xcconfig files, if the user manually added Pod dependencies without using Flutter plugins', () async {
final FlutterProject projectUnderTest = setupProjectUnderTest();
fileSystem.file(fileSystem.path.join('project', 'foo', '.packages'))
..createSync(recursive: true)
..writeAsStringSync('\n');
final File packageConfigFile = fileSystem.file(
fileSystem.path.join('project', '.dart_tool', 'package_config.json'),
);
packageConfigFile.createSync(recursive: true);
packageConfigFile.writeAsStringSync('{"configVersion":2,"packages":[]}');
projectUnderTest.ios.podfile..createSync()..writeAsStringSync('Custom Podfile');
projectUnderTest.ios.podfileLock..createSync()..writeAsStringSync('Podfile.lock from user executed `pod install`');
projectUnderTest.packagesFile..createSync()..writeAsStringSync('');
projectUnderTest.ios.xcodeConfigFor('Debug')
..createSync(recursive: true)
..writeAsStringSync('Existing debug config');

View File

@@ -175,9 +175,33 @@ void main() {
// Add basic properties to the Flutter project and subprojects
setUpProject(fs);
flutterProject.directory.childFile('.packages').createSync(recursive: true);
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json')
..createSync(recursive: true)
..writeAsStringSync('''
{
"packages": [],
"configVersion": 2
}
''');
});
void addToPackageConfig(String name, Directory packageDir) {
final File packageConfigFile = flutterProject.directory
.childDirectory('.dart_tool')
.childFile('package_config.json');
final Map<String, Object?> packageConfig =
jsonDecode(packageConfigFile.readAsStringSync()) as Map<String, Object?>;
(packageConfig['packages']! as List<Object?>).add(<String, Object?>{
'name': name,
'rootUri': packageDir.uri.toString(),
'packageUri': 'lib/',
});
packageConfigFile.writeAsStringSync(jsonEncode(packageConfig));
}
// Makes fake plugin packages for each plugin, adds them to flutterProject,
// and returns their directories.
//
@@ -208,16 +232,20 @@ void main() {
final List<Directory> directories = <Directory>[];
final Directory fakePubCache = fileSystem.systemTempDirectory.childDirectory('cache');
final File packagesFile = flutterProject.directory.childFile('.packages')
..createSync(recursive: true);
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json')
..createSync(recursive: true)
..writeAsStringSync('''
{
"packages": [],
"configVersion": 2
}
''');
for (final String nameOrPath in pluginNamesOrPaths) {
final String name = fileSystem.path.basename(nameOrPath);
final Directory pluginDirectory = (nameOrPath == name)
? fakePubCache.childDirectory(name)
: fileSystem.directory(nameOrPath);
packagesFile.writeAsStringSync(
'$name:${pluginDirectory.childFile('lib').uri}\n',
mode: FileMode.writeOnlyAppend);
addToPackageConfig(name, pluginDirectory);
pluginDirectory.childFile('pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync(pluginYamlTemplate.replaceAll('PLUGIN_CLASS', sentenceCase(camelCase(name))));
@@ -231,6 +259,8 @@ void main() {
return createFakePlugins(fileSystem, <String>['some_plugin'])[0];
}
void createNewJavaPlugin1() {
final Directory pluginUsingJavaAndNewEmbeddingDir =
fs.systemTempDirectory.createTempSync('flutter_plugin_using_java_and_new_embedding_dir.');
@@ -251,13 +281,7 @@ flutter:
.childFile('UseNewEmbedding.java')
..createSync(recursive: true)
..writeAsStringSync('import io.flutter.embedding.engine.plugins.FlutterPlugin;');
flutterProject.directory
.childFile('.packages')
.writeAsStringSync(
'plugin1:${pluginUsingJavaAndNewEmbeddingDir.childDirectory('lib').uri}\n',
mode: FileMode.append,
);
addToPackageConfig('plugin1', pluginUsingJavaAndNewEmbeddingDir);
}
Directory createPluginWithInvalidAndroidPackage() {
@@ -282,12 +306,7 @@ flutter:
..createSync(recursive: true)
..writeAsStringSync('import io.flutter.embedding.engine.plugins.FlutterPlugin;');
flutterProject.directory
.childFile('.packages')
.writeAsStringSync(
'plugin1:${pluginUsingJavaAndNewEmbeddingDir.childDirectory('lib').uri}\n',
mode: FileMode.append,
);
addToPackageConfig('plugin1', pluginUsingJavaAndNewEmbeddingDir);
return pluginUsingJavaAndNewEmbeddingDir;
}
@@ -316,12 +335,7 @@ flutter:
'registerWith(Irrelevant registrar)\n'
);
flutterProject.directory
.childFile('.packages')
.writeAsStringSync(
'plugin4:${pluginUsingJavaAndNewEmbeddingDir.childDirectory('lib').uri}',
mode: FileMode.append,
);
addToPackageConfig('plugin4', pluginUsingJavaAndNewEmbeddingDir);
}
Directory createLegacyPluginWithDependencies({
@@ -345,12 +359,7 @@ dependencies:
.childFile('pubspec.yaml')
.writeAsStringSync(' $dependency:\n', mode: FileMode.append);
}
flutterProject.directory
.childFile('.packages')
.writeAsStringSync(
'$name:${pluginDirectory.childDirectory('lib').uri}\n',
mode: FileMode.append,
);
addToPackageConfig(name, pluginDirectory);
return pluginDirectory;
}
@@ -381,12 +390,7 @@ dependencies:
.childFile('pubspec.yaml')
.writeAsStringSync(' $dependency:\n', mode: FileMode.append);
}
flutterProject.directory
.childFile('.packages')
.writeAsStringSync(
'$name:${pluginDirectory.childDirectory('lib').uri}\n',
mode: FileMode.append,
);
addToPackageConfig(name, pluginDirectory);
return pluginDirectory;
}
@@ -912,11 +916,7 @@ dependencies:
.childFile('web_plugin.dart')
.createSync(recursive: true);
flutterProject.directory
.childFile('.packages')
.writeAsStringSync('''
web_plugin_with_nested:${webPluginWithNestedFile.childDirectory('lib').uri}
''');
addToPackageConfig('web_plugin_with_nested', webPluginWithNestedFile);
final Directory destination = flutterProject.directory.childDirectory('lib');
await injectBuildTimePluginFiles(flutterProject, webPlatform: true, destination: destination);

View File

@@ -7,7 +7,6 @@ import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/multi_root_file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/run_hot.dart';
import 'package:package_config/package_config.dart';
@@ -25,13 +24,20 @@ void main() {
platform: FakePlatform(),
logger: BufferLogger.test(),
);
fileSystem.file('.packages').writeAsStringSync('\n');
fileSystem.file('.dart_tool/package_config.json')
..createSync(recursive: true)
..writeAsStringSync('''
{
"packages": [],
"configVersion": 2
}
''');
expect(
(await projectFileInvalidator.findInvalidated(
lastCompiled: null,
urisToMonitor: <Uri>[],
packagesPath: '.packages',
packagesPath: '.dart_tool/package_config.json',
asyncScanning: asyncScanning,
packageConfig: PackageConfig.empty,
)).uris,
@@ -46,13 +52,20 @@ void main() {
platform: FakePlatform(),
logger: BufferLogger.test(),
);
fileSystem.file('.packages').writeAsStringSync('\n');
fileSystem.file('.dart_tool/package_config.json')
..createSync(recursive: true)
..writeAsStringSync('''
{
"packages": [],
"configVersion": 2
}
''');
expect(
(await projectFileInvalidator.findInvalidated(
lastCompiled: inFuture,
urisToMonitor: <Uri>[],
packagesPath: '.packages',
packagesPath: '.dart_tool/package_config.json',
asyncScanning: asyncScanning,
packageConfig: PackageConfig.empty,
)).uris,
@@ -67,13 +80,20 @@ void main() {
platform: FakePlatform(),
logger: BufferLogger.test(),
);
fileSystem.file('.packages').writeAsStringSync('\n');
fileSystem.file('.dart_tool/package_config.json')
..createSync(recursive: true)
..writeAsStringSync('''
{
"packages": [],
"configVersion": 2
}
''');
expect(
(await projectFileInvalidator.findInvalidated(
lastCompiled: inFuture,
urisToMonitor: <Uri>[Uri.parse('/not-there-anymore'),],
packagesPath: '.packages',
packagesPath: '.dart_tool/package_config.json',
asyncScanning: asyncScanning,
packageConfig: PackageConfig.empty,
)).uris,
@@ -81,89 +101,6 @@ void main() {
);
});
testWithoutContext('Picks up changes to the .packages file and updates package_config.json, asyncScanning: $asyncScanning', () async {
final DateTime past = DateTime.now().subtract(const Duration(seconds: 1));
final FileSystem fileSystem = MemoryFileSystem.test();
const PackageConfig packageConfig = PackageConfig.empty;
final ProjectFileInvalidator projectFileInvalidator = ProjectFileInvalidator(
fileSystem: fileSystem,
platform: FakePlatform(),
logger: BufferLogger.test(),
);
fileSystem.file('.packages')
.writeAsStringSync('\n');
fileSystem.file('.dart_tool/package_config.json')
..createSync(recursive: true)
..writeAsStringSync(json.encode(<String, Object>{
'configVersion': 2,
'packages': <Object>[],
}));
final InvalidationResult invalidationResult = await projectFileInvalidator.findInvalidated(
lastCompiled: null,
urisToMonitor: <Uri>[],
packagesPath: '.packages',
asyncScanning: asyncScanning,
packageConfig: packageConfig,
);
expect(invalidationResult.uris, isEmpty);
fileSystem.file('.packages').setLastModifiedSync(DateTime.now());
final InvalidationResult secondInvalidation = await projectFileInvalidator.findInvalidated(
lastCompiled: past,
urisToMonitor: <Uri>[],
packagesPath: '.packages',
asyncScanning: asyncScanning,
packageConfig: packageConfig,
);
expect(secondInvalidation.uris, unorderedEquals(<Uri>[
Uri.parse('.packages'),
Uri.parse('.dart_tool/package_config.json'),
]));
});
testWithoutContext('Picks up changes to the .packages file and updates PackageConfig, asyncScanning: $asyncScanning', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
const PackageConfig packageConfig = PackageConfig.empty;
final ProjectFileInvalidator projectFileInvalidator = ProjectFileInvalidator(
fileSystem: fileSystem,
platform: FakePlatform(),
logger: BufferLogger.test(),
);
fileSystem.file('.packages')
.writeAsStringSync('\n');
final InvalidationResult invalidationResult = await projectFileInvalidator.findInvalidated(
lastCompiled: null,
urisToMonitor: <Uri>[],
packagesPath: '.packages',
asyncScanning: asyncScanning,
packageConfig: packageConfig,
);
// Initial package config is re-used.
expect(invalidationResult.packageConfig, packageConfig);
fileSystem.file('.packages')
.writeAsStringSync('foo:lib/\n');
final DateTime packagesUpdated = fileSystem.statSync('.packages')
.modified;
final InvalidationResult nextInvalidationResult = await projectFileInvalidator
.findInvalidated(
lastCompiled: packagesUpdated.subtract(const Duration(seconds: 1)),
urisToMonitor: <Uri>[],
packagesPath: '.packages',
asyncScanning: asyncScanning,
packageConfig: PackageConfig.empty,
);
expect(nextInvalidationResult.uris, contains(Uri.parse('.packages')));
// The PackageConfig should have been recreated too
expect(nextInvalidationResult.packageConfig,
isNot(invalidationResult.packageConfig));
});
testWithoutContext('Works with MultiRootFileSystem uris, asyncScanning: $asyncScanning', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final FileSystem multiRootFileSystem = MultiRootFileSystem(
@@ -187,7 +124,7 @@ void main() {
Uri.parse('file:///file2'),
Uri.parse('scheme:///file3'),
],
packagesPath: '.packages',
packagesPath: '.dart_tool/package_config.json',
asyncScanning: asyncScanning,
packageConfig: PackageConfig.empty,
)).uris,

View File

@@ -35,8 +35,6 @@ Future<String> createProject(Directory temp, { List<String>? arguments }) async
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', ...arguments, projectPath]);
// Create `.packages` since it's not created when the flag `--no-pub` is passed.
globals.fs.file(globals.fs.path.join(projectPath, '.packages')).createSync();
return projectPath;
}