Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
2bdbe723
Unverified
Commit
2bdbe723
authored
Oct 20, 2021
by
Emmanuel Garcia
Committed by
GitHub
Oct 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewire all Dart entrypoints when the Dart plugin registrant is used. (#91856)
parent
43bbdd08
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
209 additions
and
0 deletions
+209
-0
flutter_plugins.dart
packages/flutter_tools/lib/src/flutter_plugins.dart
+3
-0
dart_plugin_registrant_test.dart
...ard/build_system/targets/dart_plugin_registrant_test.dart
+6
-0
dart_plugin_test.dart
...es/flutter_tools/test/general.shard/dart_plugin_test.dart
+200
-0
No files found.
packages/flutter_tools/lib/src/flutter_plugins.dart
View file @
2bdbe723
...
...
@@ -685,6 +685,9 @@ const String _dartPluginRegistryForNonWebTemplate = '''
// @dart = {{dartLanguageVersion}}
// When `{{mainEntrypoint}}` defines `main`, that definition is shadowed by the definition below.
export
'{{mainEntrypoint}}'
;
import
'{{mainEntrypoint}}'
as
entrypoint
;
import
'dart:io'
;
// flutter_ignore: dart_io_import.
{{
#android
}}
...
...
packages/flutter_tools/test/general.shard/build_system/targets/dart_plugin_registrant_test.dart
View file @
2bdbe723
...
...
@@ -243,6 +243,9 @@ void main() {
'
\n
'
'// @dart = 2.12
\n
'
'
\n
'
'// When `package:path_provider_example/main.dart` defines `main`, that definition is shadowed by the definition below.
\n
'
"export 'package:path_provider_example/main.dart';
\n
"
'
\n
'
"import 'package:path_provider_example/main.dart' as entrypoint;
\n
"
"import 'dart:io'; // flutter_ignore: dart_io_import.
\n
"
"import 'package:path_provider_linux/path_provider_linux.dart';
\n
"
...
...
@@ -382,6 +385,9 @@ void main() {
'
\n
'
'// @dart = 2.12
\n
'
'
\n
'
'// When `file:///root/external.dart` defines `main`, that definition is shadowed by the definition below.
\n
'
"export 'file:///root/external.dart';
\n
"
'
\n
'
"import 'file:///root/external.dart' as entrypoint;
\n
"
"import 'dart:io'; // flutter_ignore: dart_io_import.
\n
"
"import 'package:path_provider_linux/path_provider_linux.dart';
\n
"
...
...
packages/flutter_tools/test/general.shard/dart_plugin_test.dart
View file @
2bdbe723
...
...
@@ -599,6 +599,9 @@ void main() {
'
\n
'
'// @dart = 2.8
\n
'
'
\n
'
'// When `package:app/main.dart` defines `main`, that definition is shadowed by the definition below.
\n
'
"export 'package:app/main.dart';
\n
"
'
\n
'
"import 'package:app/main.dart' as entrypoint;
\n
"
"import 'dart:io'; // flutter_ignore: dart_io_import.
\n
"
"import 'package:url_launcher_android/url_launcher_android.dart';
\n
"
...
...
@@ -699,6 +702,203 @@ void main() {
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
});
testUsingContext
(
'Rewires entrypoints'
,
()
async
{
flutterProject
.
isModule
=
true
;
createFakeDartPlugins
(
flutterProject
,
flutterManifest
,
fs
,
<
String
,
String
>{
'url_launcher_android'
:
'''
flutter:
plugin:
implements: url_launcher
platforms:
android:
dartPluginClass: AndroidPlugin
'''
,
'url_launcher_ios'
:
'''
flutter:
plugin:
implements: url_launcher
platforms:
ios:
dartPluginClass: IosPlugin
'''
,
'url_launcher_macos'
:
'''
flutter:
plugin:
implements: url_launcher
platforms:
macos:
dartPluginClass: MacOSPlugin
'''
,
'url_launcher_linux'
:
'''
flutter:
plugin:
implements: url_launcher
platforms:
linux:
dartPluginClass: LinuxPlugin
'''
,
'url_launcher_windows'
:
'''
flutter:
plugin:
implements: url_launcher
platforms:
windows:
dartPluginClass: WindowsPlugin
'''
,
'awesome_macos'
:
'''
flutter:
plugin:
implements: awesome
platforms:
macos:
dartPluginClass: AwesomeMacOS
'''
});
final
Directory
libDir
=
flutterProject
.
directory
.
childDirectory
(
'lib'
);
libDir
.
createSync
(
recursive:
true
);
final
File
mainFile
=
libDir
.
childFile
(
'main.dart'
);
mainFile
.
writeAsStringSync
(
'''
// @dart = 2.8
void main() {
}
@pragma('
vm:
entry
-
point
')
void dream() => run(interactive: false);
@pragma('
vm:
entry
-
point
', foobar)
void dreamWithFlags() => run(interactive: false);
'''
);
final
PackageConfig
packageConfig
=
await
loadPackageConfigWithLogging
(
flutterProject
.
directory
.
childDirectory
(
'.dart_tool'
).
childFile
(
'package_config.json'
),
logger:
globals
.
logger
,
throwOnError:
false
,
);
await
generateMainDartWithPluginRegistrant
(
flutterProject
,
packageConfig
,
'package:app/main.dart'
,
mainFile
,
throwOnPluginPubspecError:
true
,
);
expect
(
flutterProject
.
dartPluginRegistrant
.
readAsStringSync
(),
'//
\n
'
'// Generated file. Do not edit.
\n
'
'// This file is generated from template in file `flutter_tools/lib/src/flutter_plugins.dart`.
\n
'
'//
\n
'
'
\n
'
'// @dart = 2.8
\n
'
'
\n
'
'// When `package:app/main.dart` defines `main`, that definition is shadowed by the definition below.
\n
'
"export 'package:app/main.dart';
\n
"
'
\n
'
"import 'package:app/main.dart' as entrypoint;
\n
"
"import 'dart:io'; // flutter_ignore: dart_io_import.
\n
"
"import 'package:url_launcher_android/url_launcher_android.dart';
\n
"
"import 'package:url_launcher_ios/url_launcher_ios.dart';
\n
"
"import 'package:url_launcher_linux/url_launcher_linux.dart';
\n
"
"import 'package:awesome_macos/awesome_macos.dart';
\n
"
"import 'package:url_launcher_macos/url_launcher_macos.dart';
\n
"
"import 'package:url_launcher_windows/url_launcher_windows.dart';
\n
"
'
\n
'
"@pragma('vm:entry-point')
\n
"
'class _PluginRegistrant {
\n
'
'
\n
'
" @pragma('vm:entry-point')
\n
"
' static void register() {
\n
'
' if (Platform.isAndroid) {
\n
'
' try {
\n
'
' AndroidPlugin.registerWith();
\n
'
' } catch (err) {
\n
'
' print(
\n
'
" '`url_launcher_android` threw an error:
\
$err
. '
\n
"
" 'The app may not function as expected until you remove this plugin from pubspec.yaml'
\n
"
' );
\n
'
' rethrow;
\n
'
' }
\n
'
'
\n
'
' } else if (Platform.isIOS) {
\n
'
' try {
\n
'
' IosPlugin.registerWith();
\n
'
' } catch (err) {
\n
'
' print(
\n
'
" '`url_launcher_ios` threw an error:
\
$err
. '
\n
"
" 'The app may not function as expected until you remove this plugin from pubspec.yaml'
\n
"
' );
\n
'
' rethrow;
\n
'
' }
\n
'
'
\n
'
' } else if (Platform.isLinux) {
\n
'
' try {
\n
'
' LinuxPlugin.registerWith();
\n
'
' } catch (err) {
\n
'
' print(
\n
'
" '`url_launcher_linux` threw an error:
\
$err
. '
\n
"
" 'The app may not function as expected until you remove this plugin from pubspec.yaml'
\n
"
' );
\n
'
' rethrow;
\n
'
' }
\n
'
'
\n
'
' } else if (Platform.isMacOS) {
\n
'
' try {
\n
'
' AwesomeMacOS.registerWith();
\n
'
' } catch (err) {
\n
'
' print(
\n
'
" '`awesome_macos` threw an error:
\
$err
. '
\n
"
" 'The app may not function as expected until you remove this plugin from pubspec.yaml'
\n
"
' );
\n
'
' rethrow;
\n
'
' }
\n
'
'
\n
'
' try {
\n
'
' MacOSPlugin.registerWith();
\n
'
' } catch (err) {
\n
'
' print(
\n
'
" '`url_launcher_macos` threw an error:
\
$err
. '
\n
"
" 'The app may not function as expected until you remove this plugin from pubspec.yaml'
\n
"
' );
\n
'
' rethrow;
\n
'
' }
\n
'
'
\n
'
' } else if (Platform.isWindows) {
\n
'
' try {
\n
'
' WindowsPlugin.registerWith();
\n
'
' } catch (err) {
\n
'
' print(
\n
'
" '`url_launcher_windows` threw an error:
\
$err
. '
\n
"
" 'The app may not function as expected until you remove this plugin from pubspec.yaml'
\n
"
' );
\n
'
' rethrow;
\n
'
' }
\n
'
'
\n
'
' }
\n
'
' }
\n
'
'
\n
'
'}
\n
'
'
\n
'
'typedef _UnaryFunction = dynamic Function(List<String> args);
\n
'
'typedef _NullaryFunction = dynamic Function();
\n
'
'
\n
'
'void main(List<String> args) {
\n
'
' if (entrypoint.main is _UnaryFunction) {
\n
'
' (entrypoint.main as _UnaryFunction)(args);
\n
'
' } else {
\n
'
' (entrypoint.main as _NullaryFunction)();
\n
'
' }
\n
'
'}
\n
'
,
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
});
testUsingContext
(
'Plugin without platform support throws tool exit'
,
()
async
{
flutterProject
.
isModule
=
false
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment