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
91d6c972
Unverified
Commit
91d6c972
authored
Apr 27, 2021
by
Emmanuel Garcia
Committed by
GitHub
Apr 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug when resolving entrypoint against package config (#81248)
parent
0866005f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
201 additions
and
108 deletions
+201
-108
dart_plugin_registrant.dart
.../lib/src/build_system/targets/dart_plugin_registrant.dart
+2
-3
dart_plugin_registrant_test.dart
...ard/build_system/targets/dart_plugin_registrant_test.dart
+199
-105
No files found.
packages/flutter_tools/lib/src/build_system/targets/dart_plugin_registrant.dart
View file @
91d6c972
...
...
@@ -45,9 +45,8 @@ class DartPluginRegistrantTarget extends Target {
final
String
targetFile
=
environment
.
defines
[
kTargetFile
]
??
environment
.
fileSystem
.
path
.
join
(
'lib'
,
'main.dart'
);
final
File
mainFile
=
environment
.
fileSystem
.
file
(
targetFile
);
final
Uri
mainFileUri
=
mainFile
.
uri
;
assert
(
packagesFile
.
path
!=
null
);
final
String
mainUri
=
packageConfig
.
toPackageUri
(
mainFileUri
)?.
toString
();
final
Uri
mainFileUri
=
mainFile
.
absolute
.
uri
;
final
String
mainUri
=
packageConfig
.
toPackageUri
(
mainFileUri
)?.
toString
()
??
mainFileUri
.
toString
();
final
File
newMainDart
=
environment
.
projectDir
.
childDirectory
(
'.dart_tool'
)
.
childDirectory
(
'flutter_build'
)
...
...
packages/flutter_tools/test/general.shard/build_system/targets/dart_plugin_registrant_test.dart
View file @
91d6c972
...
...
@@ -16,7 +16,7 @@ import '../../../src/common.dart';
import
'../../../src/context.dart'
;
const
String
_kEmptyPubspecFile
=
'''
name:
app_without_plugins
name:
path_provider_example
dependencies:
flutter:
...
...
@@ -27,6 +27,12 @@ const String _kEmptyPackageJson = '''
{
"configVersion": 2,
"packages": [
{
"name": "path_provider_example",
"rootUri": "../",
"packageUri": "lib/",
"languageVersion": "2.12"
}
]
}
'''
;
...
...
@@ -66,53 +72,6 @@ dependencies:
path_provider_linux: 1.0.0
'''
;
const
String
_kLinuxRegistrant
=
'//
\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.12
\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
'
'
\n
'
'@pragma(
\'
vm:entry-point
\'
)
\n
'
'class _PluginRegistrant {
\n
'
'
\n
'
' @pragma(
\'
vm:entry-point
\'
)
\n
'
' static void register() {
\n
'
' if (Platform.isLinux) {
\n
'
' try {
\n
'
' PathProviderLinux.registerWith();
\n
'
' } catch (err) {
\n
'
' print(
\n
'
'
\'
`path_provider_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
'
' } else if (Platform.isWindows) {
\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
'
''
;
const
String
_kSamplePluginPubspec
=
'''
name: path_provider_linux
description: linux implementation of the path_provider plugin
...
...
@@ -161,35 +120,36 @@ void main() {
});
testUsingContext
(
"doesn't generate generated_main.dart if there aren't Dart plugins"
,
()
async
{
final
Directory
projectDir
=
fileSystem
.
directory
(
'project'
)..
createSync
();
final
Environment
environment
=
Environment
.
test
(
fileSystem
.
currentDirectory
,
projectDir:
fileSystem
.
directory
(
'project'
)..
createSync
()
,
projectDir:
projectDir
,
artifacts:
null
,
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
processManager:
FakeProcessManager
.
any
(),
defines:
<
String
,
String
>{
kTargetFile:
projectDir
.
childDirectory
(
'lib'
).
childFile
(
'main.dart'
).
absolute
.
path
,
},
generateDartPluginRegistry:
true
);
final
File
config
=
environment
.
projectDir
projectDir
.
childDirectory
(
'.dart_tool'
)
.
childFile
(
'package_config.json'
)
;
config
.
createSync
(
recursive:
true
);
config
.
writeAsStringSync
(
_kSamplePackageJson
);
.
childFile
(
'package_config.json'
)
..
createSync
(
recursive:
true
)
.
.
writeAsStringSync
(
_kSamplePackageJson
);
final
File
pubspec
=
environment
.
projectDir
.
childFile
(
'pubspec.yaml'
);
pubspec
.
createSync
();
projectDir
.
childFile
(
'pubspec.yaml'
).
createSync
();
final
File
packages
=
environment
.
projectDir
.
childFile
(
'.packages'
);
packages
.
createSync
();
projectDir
.
childFile
(
'.packages'
).
createSync
();
final
FlutterProject
testProject
=
FlutterProject
.
fromDirectoryTest
(
projectDir
);
await
DartPluginRegistrantTarget
.
test
(
testProject
).
build
(
environment
);
final
File
generatedMain
=
environment
.
projectDir
final
File
generatedMain
=
projectDir
.
childDirectory
(
'.dart_tool'
)
.
childDirectory
(
'flutter_build'
)
.
childFile
(
'generated_main.dart'
);
final
FlutterProject
testProject
=
FlutterProject
.
fromDirectoryTest
(
environment
.
projectDir
);
await
DartPluginRegistrantTarget
.
test
(
testProject
).
build
(
environment
);
expect
(
generatedMain
.
existsSync
(),
isFalse
);
});
...
...
@@ -207,76 +167,119 @@ void main() {
},
generateDartPluginRegistry:
true
);
final
File
config
=
projectDir
projectDir
.
childDirectory
(
'.dart_tool'
)
.
childFile
(
'package_config.json'
)
;
config
.
createSync
(
recursive:
true
);
config
.
writeAsStringSync
(
_kSamplePackageJson
);
.
childFile
(
'package_config.json'
)
..
createSync
(
recursive:
true
)
.
.
writeAsStringSync
(
_kSamplePackageJson
);
final
File
pubspec
=
projectDir
.
childFile
(
'pubspec.yaml'
);
pubspec
.
createSync
();
pubspec
.
writeAsStringSync
(
_kSamplePubspecFile
);
projectDir
.
childFile
(
'pubspec.yaml'
).
writeAsStringSync
(
_kSamplePubspecFile
);
final
File
packages
=
projectDir
.
childFile
(
'.packages'
);
packages
.
createSync
();
packages
.
writeAsStringSync
(
_kSamplePackagesFile
);
projectDir
.
childFile
(
'.packages'
).
writeAsStringSync
(
_kSamplePackagesFile
);
final
File
generatedMain
=
projectDir
.
childDirectory
(
'.dart_tool'
)
.
childDirectory
(
'flutter_build'
)
.
childFile
(
'generated_main.dart'
);
generatedMain
.
createSync
(
recursive:
true
);
projectDir
.
childDirectory
(
'lib'
).
childFile
(
'main.dart'
).
createSync
(
recursive:
true
);
final
File
mainEntrypoint
=
projectDir
.
childDirectory
(
'lib'
).
childFile
(
'main.dart'
);
mainEntrypoint
.
createSync
(
recursive:
true
);
final
File
pluginPubspec
=
environment
.
fileSystem
.
currentDirectory
.
childDirectory
(
'path_provider_linux'
).
childFile
(
'pubspec.yaml'
);
pluginPubspec
.
createSync
(
recursive:
true
);
pluginPubspec
.
writeAsStringSync
(
_kSamplePluginPubspec
);
environment
.
fileSystem
.
currentDirectory
.
childDirectory
(
'path_provider_linux'
)
.
childFile
(
'pubspec.yaml'
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
_kSamplePluginPubspec
);
final
FlutterProject
testProject
=
FlutterProject
.
fromDirectoryTest
(
environment
.
projectDir
);
final
FlutterProject
testProject
=
FlutterProject
.
fromDirectoryTest
(
projectDir
);
await
DartPluginRegistrantTarget
.
test
(
testProject
).
build
(
environment
);
final
File
generatedMain
=
projectDir
.
childDirectory
(
'.dart_tool'
)
.
childDirectory
(
'flutter_build'
)
.
childFile
(
'generated_main.dart'
);
final
String
mainContent
=
generatedMain
.
readAsStringSync
();
expect
(
mainContent
,
equals
(
_kLinuxRegistrant
));
expect
(
mainContent
,
equals
(
'//
\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.12
\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
'
'
\n
'
'@pragma(
\'
vm:entry-point
\'
)
\n
'
'class _PluginRegistrant {
\n
'
'
\n
'
' @pragma(
\'
vm:entry-point
\'
)
\n
'
' static void register() {
\n
'
' if (Platform.isLinux) {
\n
'
' try {
\n
'
' PathProviderLinux.registerWith();
\n
'
' } catch (err) {
\n
'
' print(
\n
'
'
\'
`path_provider_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
'
' } else if (Platform.isWindows) {
\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
'
''
),
);
});
testUsingContext
(
'removes generated_main.dart if plugins are removed from pubspec.yaml'
,
()
async
{
final
Directory
projectDir
=
fileSystem
.
directory
(
'project'
)..
createSync
();
final
Environment
environment
=
Environment
.
test
(
fileSystem
.
currentDirectory
,
projectDir:
fileSystem
.
directory
(
'project'
)..
createSync
()
,
projectDir:
projectDir
,
artifacts:
null
,
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
processManager:
FakeProcessManager
.
any
(),
defines:
<
String
,
String
>{
kTargetFile:
projectDir
.
childDirectory
(
'lib'
).
childFile
(
'main.dart'
).
absolute
.
path
,
},
generateDartPluginRegistry:
true
);
final
File
config
=
environment
.
projectDir
final
File
config
=
projectDir
.
childDirectory
(
'.dart_tool'
)
.
childFile
(
'package_config.json'
)
;
config
.
createSync
(
recursive:
true
);
config
.
writeAsStringSync
(
_kSamplePackageJson
);
.
childFile
(
'package_config.json'
)
..
createSync
(
recursive:
true
)
.
.
writeAsStringSync
(
_kSamplePackageJson
);
final
File
pubspec
=
environment
.
projectDir
.
childFile
(
'pubspec.yaml'
);
pubspec
.
createSync
();
pubspec
.
writeAsStringSync
(
_kSamplePubspecFile
);
final
File
pubspec
=
projectDir
.
childFile
(
'pubspec.yaml'
)..
writeAsStringSync
(
_kSamplePubspecFile
);
final
File
packages
=
environment
.
projectDir
.
childFile
(
'.packages'
);
packages
.
createSync
();
packages
.
writeAsStringSync
(
_kSamplePackagesFile
);
final
File
packages
=
projectDir
.
childFile
(
'.packages'
)..
writeAsStringSync
(
_kSamplePackagesFile
);
final
File
generatedMain
=
environment
.
projectDir
environment
.
fileSystem
.
currentDirectory
.
childDirectory
(
'path_provider_linux'
)
.
childFile
(
'pubspec.yaml'
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
_kSamplePluginPubspec
);
final
File
generatedMain
=
projectDir
.
childDirectory
(
'.dart_tool'
)
.
childDirectory
(
'flutter_build'
)
.
childFile
(
'generated_main.dart'
);
final
File
pluginPubspec
=
environment
.
fileSystem
.
currentDirectory
.
childDirectory
(
'path_provider_linux'
)
.
childFile
(
'pubspec.yaml'
);
pluginPubspec
.
createSync
(
recursive:
true
);
pluginPubspec
.
writeAsStringSync
(
_kSamplePluginPubspec
);
final
FlutterProject
testProject
=
FlutterProject
.
fromDirectoryTest
(
environment
.
projectDir
);
final
FlutterProject
testProject
=
FlutterProject
.
fromDirectoryTest
(
projectDir
);
await
DartPluginRegistrantTarget
.
test
(
testProject
).
build
(
environment
);
expect
(
generatedMain
.
existsSync
(),
isTrue
);
...
...
@@ -288,5 +291,96 @@ void main() {
await
DartPluginRegistrantTarget
.
test
(
testProject
).
build
(
environment
);
expect
(
generatedMain
.
existsSync
(),
isFalse
);
});
testUsingContext
(
'target file is outside the current project package'
,
()
async
{
final
Directory
projectDir
=
fileSystem
.
directory
(
'project'
)..
createSync
();
final
Environment
environment
=
Environment
.
test
(
fileSystem
.
currentDirectory
,
projectDir:
projectDir
,
artifacts:
null
,
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
processManager:
FakeProcessManager
.
any
(),
defines:
<
String
,
String
>{
kTargetFile:
fileSystem
.
directory
(
'root'
).
childFile
(
'external.dart'
).
absolute
.
path
,
},
generateDartPluginRegistry:
true
);
projectDir
.
childDirectory
(
'.dart_tool'
)
.
childFile
(
'package_config.json'
)
.
writeAsStringSync
(
_kSamplePackageJson
);
projectDir
.
childFile
(
'pubspec.yaml'
).
writeAsStringSync
(
_kSamplePubspecFile
);
projectDir
.
childFile
(
'.packages'
).
writeAsStringSync
(
_kSamplePackagesFile
);
projectDir
.
childDirectory
(
'lib'
).
childFile
(
'main.dart'
).
createSync
(
recursive:
true
);
environment
.
fileSystem
.
currentDirectory
.
childDirectory
(
'path_provider_linux'
)
.
childFile
(
'pubspec.yaml'
)
.
writeAsStringSync
(
_kSamplePluginPubspec
);
final
FlutterProject
testProject
=
FlutterProject
.
fromDirectoryTest
(
projectDir
);
await
DartPluginRegistrantTarget
.
test
(
testProject
).
build
(
environment
);
final
File
generatedMain
=
projectDir
.
childDirectory
(
'.dart_tool'
)
.
childDirectory
(
'flutter_build'
)
.
childFile
(
'generated_main.dart'
);
final
String
mainContent
=
generatedMain
.
readAsStringSync
();
expect
(
mainContent
,
equals
(
'//
\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.12
\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
'
'
\n
'
'@pragma(
\'
vm:entry-point
\'
)
\n
'
'class _PluginRegistrant {
\n
'
'
\n
'
' @pragma(
\'
vm:entry-point
\'
)
\n
'
' static void register() {
\n
'
' if (Platform.isLinux) {
\n
'
' try {
\n
'
' PathProviderLinux.registerWith();
\n
'
' } catch (err) {
\n
'
' print(
\n
'
'
\'
`path_provider_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
'
' } else if (Platform.isWindows) {
\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
'
''
),
);
});
});
}
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