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
7eb1035a
Unverified
Commit
7eb1035a
authored
Feb 04, 2022
by
stuartmorgan
Committed by
GitHub
Feb 04, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restructure Windows plugin template (#93511)
parent
8a95d42b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
102 additions
and
52 deletions
+102
-52
CMakeLists.txt.tmpl
...r_tools/templates/plugin/windows.tmpl/CMakeLists.txt.tmpl
+9
-3
pluginClassSnakeCase_c_api.h.tmpl
...nclude/projectName.tmpl/pluginClassSnakeCase_c_api.h.tmpl
+4
-4
pluginClassSnakeCase.cpp.tmpl
...mplates/plugin/windows.tmpl/pluginClassSnakeCase.cpp.tmpl
+3
-26
pluginClassSnakeCase.h.tmpl
...templates/plugin/windows.tmpl/pluginClassSnakeCase.h.tmpl
+32
-0
pluginClassSnakeCase_c_api.cpp.tmpl
...s/plugin/windows.tmpl/pluginClassSnakeCase_c_api.cpp.tmpl
+12
-0
pubspec.yaml.tmpl
...s/flutter_tools/templates/plugin_shared/pubspec.yaml.tmpl
+1
-1
template_manifest.json
packages/flutter_tools/templates/template_manifest.json
+3
-1
create_test.dart
...tter_tools/test/commands.shard/permeable/create_test.dart
+38
-17
No files found.
packages/flutter_tools/templates/plugin/windows.tmpl/CMakeLists.txt.tmpl
View file @
7eb1035a
...
...
@@ -12,12 +12,18 @@ project(${PROJECT_NAME} LANGUAGES CXX)
# not be changed
set(PLUGIN_NAME "{{projectName}}_plugin")
# Any new source files that you add to the plugin should be added here.
list(APPEND PLUGIN_SOURCES
"{{pluginClassSnakeCase}}.cpp"
"{{pluginClassSnakeCase}}.h"
)
# Define the plugin library target. Its name must not be changed (see comment
# on PLUGIN_NAME above).
#
# Any new source files that you add to the plugin should be added here.
add_library(${PLUGIN_NAME} SHARED
"{{pluginClassSnakeCase}}.cpp"
"include/{{projectName}}/{{pluginClassSnakeCase}}_c_api.h"
"{{pluginClassSnakeCase}}_c_api.cpp"
${PLUGIN_SOURCES}
)
# Apply a standard set of build settings that are configured in the
...
...
packages/flutter_tools/templates/plugin/windows.tmpl/include/projectName.tmpl/pluginClassSnakeCase.h.tmpl
→
packages/flutter_tools/templates/plugin/windows.tmpl/include/projectName.tmpl/pluginClassSnakeCase
_c_api
.h.tmpl
View file @
7eb1035a
#ifndef FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_H_
#define FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_H_
#ifndef FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_
C_API_
H_
#define FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_
C_API_
H_
#include <flutter_plugin_registrar.h>
...
...
@@ -13,11 +13,11 @@
extern "C" {
#endif
FLUTTER_PLUGIN_EXPORT void {{pluginClass}}RegisterWithRegistrar(
FLUTTER_PLUGIN_EXPORT void {{pluginClass}}
CApi
RegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar);
#if defined(__cplusplus)
} // extern "C"
#endif
#endif // FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_H_
#endif // FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_
C_API_
H_
packages/flutter_tools/templates/plugin/windows.tmpl/pluginClassSnakeCase.cpp.tmpl
View file @
7eb1035a
#include "
include/{{projectName}}/
{{pluginClassSnakeCase}}.h"
#include "{{pluginClassSnakeCase}}.h"
// This must be included before many other Windows headers.
#include <windows.h>
...
...
@@ -10,26 +10,10 @@
#include <flutter/plugin_registrar_windows.h>
#include <flutter/standard_method_codec.h>
#include <map>
#include <memory>
#include <sstream>
namespace {
class {{pluginClass}} : public flutter::Plugin {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
{{pluginClass}}();
virtual ~{{pluginClass}}();
private:
// Called when a method is called on this plugin's channel from Dart.
void HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
};
namespace {{projectName}} {
// static
void {{pluginClass}}::RegisterWithRegistrar(
...
...
@@ -72,11 +56,4 @@ void {{pluginClass}}::HandleMethodCall(
}
}
} // namespace
void {{pluginClass}}RegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar) {
{{pluginClass}}::RegisterWithRegistrar(
flutter::PluginRegistrarManager::GetInstance()
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
}
} // namespace {{projectName}}
packages/flutter_tools/templates/plugin/windows.tmpl/pluginClassSnakeCase.h.tmpl
0 → 100644
View file @
7eb1035a
#ifndef FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_H_
#define FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_H_
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
#include <memory>
namespace {{projectName}} {
class {{pluginClass}} : public flutter::Plugin {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
{{pluginClass}}();
virtual ~{{pluginClass}}();
// Disallow copy and assign.
{{pluginClass}}(const {{pluginClass}}&) = delete;
{{pluginClass}}& operator=(const {{pluginClass}}&) = delete;
private:
// Called when a method is called on this plugin's channel from Dart.
void HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
};
} // namespace {{projectName}}
#endif // FLUTTER_PLUGIN_{{pluginClassCapitalSnakeCase}}_H_
packages/flutter_tools/templates/plugin/windows.tmpl/pluginClassSnakeCase_c_api.cpp.tmpl
0 → 100644
View file @
7eb1035a
#include "include/{{projectName}}/{{pluginClassSnakeCase}}_c_api.h"
#include <flutter/plugin_registrar_windows.h>
#include "{{pluginClassSnakeCase}}.h"
void {{pluginClass}}CApiRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar) {
{{projectName}}::{{pluginClass}}::RegisterWithRegistrar(
flutter::PluginRegistrarManager::GetInstance()
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
}
packages/flutter_tools/templates/plugin_shared/pubspec.yaml.tmpl
View file @
7eb1035a
...
...
@@ -112,7 +112,7 @@ flutter:
{{/macos}}
{{#windows}}
windows:
pluginClass: {{pluginClass}}
pluginClass: {{pluginClass}}
CApi
{{/windows}}
{{#web}}
web:
...
...
packages/flutter_tools/templates/template_manifest.json
View file @
7eb1035a
...
...
@@ -333,8 +333,10 @@
"templates/plugin/README.md.tmpl"
,
"templates/plugin/test/projectName_test.dart.tmpl"
,
"templates/plugin/windows.tmpl/CMakeLists.txt.tmpl"
,
"templates/plugin/windows.tmpl/include/projectName.tmpl/pluginClassSnakeCase.h.tmpl"
,
"templates/plugin/windows.tmpl/include/projectName.tmpl/pluginClassSnakeCase
_c_api
.h.tmpl"
,
"templates/plugin/windows.tmpl/pluginClassSnakeCase.cpp.tmpl"
,
"templates/plugin/windows.tmpl/pluginClassSnakeCase.h.tmpl"
,
"templates/plugin/windows.tmpl/pluginClassSnakeCase_c_api.cpp.tmpl"
,
"templates/plugin/lib/projectName_web.dart.tmpl"
,
"templates/plugin_ffi/android.tmpl/build.gradle.tmpl"
,
...
...
packages/flutter_tools/test/commands.shard/permeable/create_test.dart
View file @
7eb1035a
...
...
@@ -1063,7 +1063,7 @@ void main() {
isNot
(
exists
));
validatePubspecForPlugin
(
projectDir:
projectDir
.
absolute
.
path
,
expectedPlatforms:
const
<
String
>[
'windows'
],
pluginClass:
'FlutterProjectPlugin'
,
],
pluginClass:
'FlutterProjectPlugin
CApi
'
,
unexpectedPlatforms:
<
String
>[
'some_platform'
]);
expect
(
logger
.
errorText
,
isNot
(
contains
(
_kNoPlatformsMessage
)));
},
overrides:
<
Type
,
Generator
>{
...
...
@@ -2539,21 +2539,33 @@ void main() {
final
Directory
platformDir
=
projectDir
.
childDirectory
(
'windows'
);
const
String
classFilenameBase
=
'foo_bar_baz_plugin'
;
const
String
headerName
=
'
$classFilenameBase
.h'
;
final
File
headerFile
=
platformDir
const
String
cApiHeaderName
=
'
${classFilenameBase}
_c_api.h'
;
const
String
pluginClassHeaderName
=
'
$classFilenameBase
.h'
;
final
File
cApiHeaderFile
=
platformDir
.
childDirectory
(
'include'
)
.
childDirectory
(
projectName
)
.
childFile
(
headerName
);
final
File
implFile
=
platformDir
.
childFile
(
'
$classFilenameBase
.cpp'
);
.
childFile
(
cApiHeaderName
);
final
File
cApiImplFile
=
platformDir
.
childFile
(
'
${classFilenameBase}
_c_api.cpp'
);
final
File
pluginClassHeaderFile
=
platformDir
.
childFile
(
pluginClassHeaderName
);
final
File
pluginClassImplFile
=
platformDir
.
childFile
(
'
$classFilenameBase
.cpp'
);
// Ensure that the files have the right names.
expect
(
headerFile
,
exists
);
expect
(
implFile
,
exists
);
// Ensure that the include is correct.
expect
(
implFile
.
readAsStringSync
(),
contains
(
headerName
));
expect
(
cApiHeaderFile
,
exists
);
expect
(
cApiImplFile
,
exists
);
expect
(
pluginClassHeaderFile
,
exists
);
expect
(
pluginClassImplFile
,
exists
);
// Ensure that the includes are correct.
expect
(
cApiImplFile
.
readAsLinesSync
(),
containsAllInOrder
(<
Matcher
>[
contains
(
'#include "include/
$projectName
/
$cApiHeaderName
"'
),
contains
(
'#include "
$pluginClassHeaderName
"'
),
]));
expect
(
pluginClassImplFile
.
readAsLinesSync
(),
contains
(
'#include "
$pluginClassHeaderName
"'
));
// Ensure that the plugin target name matches the post-processed version.
// Ensure that the CMake file has the right target and source values.
final
String
cmakeContents
=
platformDir
.
childFile
(
'CMakeLists.txt'
).
readAsStringSync
();
expect
(
cmakeContents
,
contains
(
'"
$classFilenameBase
.cpp"'
));
expect
(
cmakeContents
,
contains
(
'"
$classFilenameBase
.h"'
));
expect
(
cmakeContents
,
contains
(
'"
${classFilenameBase}
_c_api.cpp"'
));
expect
(
cmakeContents
,
contains
(
'"include/
$projectName
/
${classFilenameBase}
_c_api.h"'
));
expect
(
cmakeContents
,
contains
(
'set(PLUGIN_NAME "foo_BarBaz_plugin")'
));
},
overrides:
<
Type
,
Generator
>{
FeatureFlags:
()
=>
TestFeatureFlags
(
isWindowsEnabled:
true
),
...
...
@@ -2608,17 +2620,26 @@ void main() {
// If the project already ends in _plugin, it shouldn't be added again.
const
String
classFilenameBase
=
projectName
;
const
String
headerName
=
'
$classFilenameBase
.h'
;
final
File
headerFile
=
platformDir
const
String
cApiHeaderName
=
'
${classFilenameBase}
_c_api.h'
;
const
String
pluginClassHeaderName
=
'
$classFilenameBase
.h'
;
final
File
cApiHeaderFile
=
platformDir
.
childDirectory
(
'include'
)
.
childDirectory
(
projectName
)
.
childFile
(
headerName
);
final
File
implFile
=
platformDir
.
childFile
(
'
$classFilenameBase
.cpp'
);
.
childFile
(
cApiHeaderName
);
final
File
cApiImplFile
=
platformDir
.
childFile
(
'
${classFilenameBase}
_c_api.cpp'
);
final
File
pluginClassHeaderFile
=
platformDir
.
childFile
(
pluginClassHeaderName
);
final
File
pluginClassImplFile
=
platformDir
.
childFile
(
'
$classFilenameBase
.cpp'
);
// Ensure that the files have the right names.
expect
(
headerFile
,
exists
);
expect
(
implFile
,
exists
);
// Ensure that the include is correct.
expect
(
implFile
.
readAsStringSync
(),
contains
(
headerName
));
expect
(
cApiHeaderFile
,
exists
);
expect
(
cApiImplFile
,
exists
);
expect
(
pluginClassHeaderFile
,
exists
);
expect
(
pluginClassImplFile
,
exists
);
// Ensure that the includes are correct.
expect
(
cApiImplFile
.
readAsLinesSync
(),
containsAllInOrder
(<
Matcher
>[
contains
(
'#include "include/
$projectName
/
$cApiHeaderName
"'
),
contains
(
'#include "
$pluginClassHeaderName
"'
),
]));
expect
(
pluginClassImplFile
.
readAsLinesSync
(),
contains
(
'#include "
$pluginClassHeaderName
"'
));
// Ensure that the CMake file has the right target and source values.
final
String
cmakeContents
=
platformDir
.
childFile
(
'CMakeLists.txt'
).
readAsStringSync
();
expect
(
cmakeContents
,
contains
(
'"
$classFilenameBase
.cpp"'
));
...
...
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