From eaf3f8b4f78e2a6673e86db8eecb58e02f7eaa1f Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Thu, 17 Sep 2020 18:23:38 -0400 Subject: [PATCH] Add VERSIONINFO to the Windows template (#66025) Adds a VERSIONINFO to Runner.rc in the Windows app template, populated from the project creation metadata. Currently the version itself is hard-coded, but it is future-proofed to allow plumbing the actual version through at build time via preprocessor defines. --- .../runner/{Runner.rc => Runner.rc.tmpl} | 51 +++++++++++++++++++ .../templates/template_manifest.json | 2 +- .../commands.shard/permeable/create_test.dart | 19 +++++++ 3 files changed, 71 insertions(+), 1 deletion(-) rename packages/flutter_tools/templates/app/windows.tmpl/runner/{Runner.rc => Runner.rc.tmpl} (55%) diff --git a/packages/flutter_tools/templates/app/windows.tmpl/runner/Runner.rc b/packages/flutter_tools/templates/app/windows.tmpl/runner/Runner.rc.tmpl similarity index 55% rename from packages/flutter_tools/templates/app/windows.tmpl/runner/Runner.rc rename to packages/flutter_tools/templates/app/windows.tmpl/runner/Runner.rc.tmpl index 5b41a82a40..52b434289b 100644 --- a/packages/flutter_tools/templates/app/windows.tmpl/runner/Runner.rc +++ b/packages/flutter_tools/templates/app/windows.tmpl/runner/Runner.rc.tmpl @@ -54,6 +54,57 @@ END // remains consistent on all systems. IDI_APP_ICON ICON "resources\\app_icon.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#ifdef FLUTTER_BUILD_NUMBER +#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER +#else +#define VERSION_AS_NUMBER 1,0,0 +#endif + +#ifdef FLUTTER_BUILD_NAME +#define VERSION_AS_STRING #FLUTTER_BUILD_NAME +#else +#define VERSION_AS_STRING "1.0.0" +#endif + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VERSION_AS_NUMBER + PRODUCTVERSION VERSION_AS_NUMBER + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "CompanyName", "{{organization}}" "\0" + VALUE "FileDescription", "{{description}}" "\0" + VALUE "FileVersion", VERSION_AS_STRING "\0" + VALUE "InternalName", "{{projectName}}" "\0" + VALUE "LegalCopyright", "Copyright (C) {{year}} {{organization}}. All rights reserved." "\0" + VALUE "OriginalFilename", "{{projectName}}.exe" "\0" + VALUE "ProductName", "{{projectName}}" "\0" + VALUE "ProductVersion", VERSION_AS_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + #endif // English (United States) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/packages/flutter_tools/templates/template_manifest.json b/packages/flutter_tools/templates/template_manifest.json index 4e4fe4ce37..f3a1485754 100644 --- a/packages/flutter_tools/templates/template_manifest.json +++ b/packages/flutter_tools/templates/template_manifest.json @@ -130,7 +130,7 @@ "templates/app/windows.tmpl/runner/resource.h", "templates/app/windows.tmpl/runner/resources/app_icon.ico.img.tmpl", "templates/app/windows.tmpl/runner/runner.exe.manifest", - "templates/app/windows.tmpl/runner/Runner.rc", + "templates/app/windows.tmpl/runner/Runner.rc.tmpl", "templates/app/windows.tmpl/runner/run_loop.cpp", "templates/app/windows.tmpl/runner/run_loop.h", "templates/app/windows.tmpl/runner/utils.cpp", diff --git a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart index 7df4f1ef92..a22a2a5155 100755 --- a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart @@ -811,6 +811,25 @@ void main() { FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true), }); + testUsingContext('Windows has correct VERSIONINFO', () async { + Cache.flutterRoot = '../..'; + when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision); + when(mockFlutterVersion.channel).thenReturn(frameworkChannel); + + final CreateCommand command = CreateCommand(); + final CommandRunner runner = createTestCommandRunner(command); + + await runner.run(['create', '--no-pub', '--org', 'com.foo.bar', projectDir.path]); + + final File resourceFile = projectDir.childDirectory('windows').childDirectory('runner').childFile('Runner.rc'); + expect(resourceFile.existsSync(), true); + final String contents = resourceFile.readAsStringSync(); + expect(contents, contains('"CompanyName", "com.foo.bar"')); + expect(contents, contains('"ProductName", "flutter_project"')); + }, overrides: { + FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true), + }); + testUsingContext('app does not include Windows by default', () async { Cache.flutterRoot = '../..'; when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);