flutter/packages/flutter_tools/test/general.shard/windows/plugins_test.dart
Matan Lurey 78cfc1ae9b
Plugin.isDevDependency if exclusively in dev_dependencies (#157462)
Work towards https://github.com/flutter/flutter/issues/56591.

I explicitly want an LGTM from @andrewkolos @jmagman @jonahwilliams before merging.

---

After this PR, `<Plugin>.isDevDependency` is resolved based on the following logic, IFF:

- The plugin comes from a package _A_ listed in the app's package's `dev_dependencies: ...`
- The package _A_ is not a normal dependency of any transitive non-dev dependency of the app

See [`compute_dev_dependencies_test.dart`](51676093a3/packages/flutter_tools/test/general.shard/compute_dev_dependencies_test.dart) for probably the best specification of this behavior.

We (still) do not write the property to disk (i.e. it never makes it to `.flutter-plugins-dependencies`), so there is no impact to build artifacts at this time; that would come in a follow-up PR (and then follow-up follow-up PRs for the various build systems in both Gradle and Xcode to actually use that value to omit dependencies).

Some tests had to be updated; for the most part it was updating the default `ProcessManager` because a call to `dart pub deps --json` is now made in code that computes what plugins are available, but there should be no change in behavior.

_/cc @jonasfj @sigurdm for FYI only (we talked on an internal thread about this; see https://github.com/dart-lang/sdk/issues/56968)._

_/cc @camsim99 @cbracken @johnmccutchan for visibility on the change._
2024-11-07 18:09:22 +00:00

58 lines
2.0 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/template.dart';
import 'package:flutter_tools/src/flutter_plugins.dart';
import 'package:flutter_tools/src/isolated/mustache_template.dart';
import 'package:flutter_tools/src/platform_plugins.dart';
import 'package:flutter_tools/src/plugins.dart';
import 'package:flutter_tools/src/project.dart';
import '../../src/common.dart';
const TemplateRenderer renderer = MustacheTemplateRenderer();
void main() {
testWithoutContext('Win32 injects Win32 plugins', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
setUpProject(fileSystem);
final FlutterProject flutterProject = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
await writeWindowsPluginFiles(flutterProject, <Plugin>[
Plugin(
name: 'test',
path: 'foo',
defaultPackagePlatforms: const <String, String>{},
pluginDartClassPlatforms: const <String, DartPluginClassAndFilePair>{},
platforms: const <String, PluginPlatform>{
WindowsPlugin.kConfigKey: WindowsPlugin(
name: 'test',
pluginClass: 'Foo',
variants: <PluginPlatformVariant>{PluginPlatformVariant.win32},
),
},
dependencies: <String>[],
isDirectDependency: true,
isDevDependency: false,
),
], renderer);
final Directory managed = flutterProject.windows.managedDirectory;
expect(flutterProject.windows.generatedPluginCmakeFile, exists);
expect(managed.childFile('generated_plugin_registrant.h'), exists);
expect(
managed.childFile('generated_plugin_registrant.cc').readAsStringSync(),
contains('#include <test/foo.h>'),
);
});
}
void setUpProject(FileSystem fileSystem) {
fileSystem.file('pubspec.yaml').createSync();
}