Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4969f5

Browse files
committed
Updates CRT installation for Windows installer.
Bundling versions of the CRT prior to 14.0 is no longer supported.
1 parent a473b9d commit e4969f5

11 files changed

Lines changed: 180 additions & 72 deletions

File tree

Tools/msi/bundle/Default.wxl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
<String Id="Uninstalling">Removing</String>
1212
<String Id="Uninstallation">Uninstall</String>
1313

14+
<String Id="ElevateForCRTInstall">You will be prompted for Administrator privileges to install a C Runtime Library update (KB2999226).
15+
16+
17+
Continue?</String>
18+
1419
<String Id="CancelButton">&amp;Cancel</String>
1520
<String Id="CloseButton">&amp;Close</String>
1621
<String Id="InstallHeader">Install [WixBundleName]</String>

Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
#include "pch.h"
1212

13-
static const LPCWSTR WIXBUNDLE_VARIABLE_ELEVATED = L"WixBundleElevated";
14-
1513
static const LPCWSTR PYBA_WINDOW_CLASS = L"PythonBA";
1614
static const LPCWSTR PYBA_VARIABLE_LAUNCH_TARGET_PATH = L"LaunchTarget";
1715
static const LPCWSTR PYBA_VARIABLE_LAUNCH_TARGET_ELEVATED_ID = L"LaunchTargetElevatedId";
@@ -232,7 +230,7 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
232230
void OnCommand(CONTROL_ID id) {
233231
LPWSTR defaultDir = nullptr;
234232
LPWSTR targetDir = nullptr;
235-
LONGLONG elevated;
233+
LONGLONG elevated, crtInstalled;
236234
BOOL checked;
237235
WCHAR wzPath[MAX_PATH] = { };
238236
BROWSEINFOW browseInfo = { };
@@ -320,6 +318,10 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
320318
ReleaseStr(targetDir);
321319
BalExitOnFailure(hr, "Failed to set install target directory");
322320

321+
if (!QueryElevateForCrtInstall()) {
322+
break;
323+
}
324+
323325
OnPlan(BOOTSTRAPPER_ACTION_INSTALL);
324326
break;
325327

@@ -352,6 +354,11 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
352354
ReleaseStr(targetDir);
353355
}
354356

357+
checked = ThemeIsControlChecked(_theme, ID_CUSTOM_INSTALL_ALL_USERS_CHECKBOX);
358+
if (!checked && !QueryElevateForCrtInstall()) {
359+
break;
360+
}
361+
355362
OnPlan(_command.action);
356363
break;
357364

@@ -2311,6 +2318,75 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
23112318
}
23122319
}
23132320

2321+
BOOL IsCrtInstalled() {
2322+
if (_crtInstalledToken > 0) {
2323+
return TRUE;
2324+
} else if (_crtInstalledToken == 0) {
2325+
return FALSE;
2326+
}
2327+
2328+
// Check whether at least CRT v10.0.9920.0 is available.
2329+
// It should only be installed as a Windows Update package, which means
2330+
// we don't need to worry about 32-bit/64-bit.
2331+
// However, since the WU package does not include vcruntime140.dll, we
2332+
// still install that ourselves.
2333+
LPCWSTR crtFile = L"api-ms-win-crt-runtime-l1-1-0.dll";
2334+
2335+
DWORD cbVer = GetFileVersionInfoSizeW(crtFile, nullptr);
2336+
if (!cbVer) {
2337+
_crtInstalledToken = 0;
2338+
return FALSE;
2339+
}
2340+
2341+
void *pData = malloc(cbVer);
2342+
if (!pData) {
2343+
_crtInstalledToken = 0;
2344+
return FALSE;
2345+
}
2346+
2347+
if (!GetFileVersionInfoW(crtFile, 0, cbVer, pData)) {
2348+
free(pData);
2349+
_crtInstalledToken = 0;
2350+
return FALSE;
2351+
}
2352+
2353+
VS_FIXEDFILEINFO *ffi;
2354+
UINT cb;
2355+
BOOL result = FALSE;
2356+
2357+
if (VerQueryValueW(pData, L"\\", (LPVOID*)&ffi, &cb) &&
2358+
ffi->dwFileVersionMS == 0x000A0000 && ffi->dwFileVersionLS >= 0x26C00000) {
2359+
result = TRUE;
2360+
}
2361+
2362+
free(pData);
2363+
_crtInstalledToken = result ? 1 : 0;
2364+
return result;
2365+
}
2366+
2367+
BOOL QueryElevateForCrtInstall() {
2368+
// Called to prompt the user that even though they think they won't need
2369+
// to elevate, they actually will because of the CRT install.
2370+
if (IsCrtInstalled()) {
2371+
// CRT is already installed - no need to prompt
2372+
return TRUE;
2373+
}
2374+
2375+
LONGLONG elevated;
2376+
HRESULT hr = BalGetNumericVariable(L"WixBundleElevated", &elevated);
2377+
if (SUCCEEDED(hr) && elevated) {
2378+
// Already elevated - no need to prompt
2379+
return TRUE;
2380+
}
2381+
2382+
LOC_STRING *locStr;
2383+
hr = LocGetString(_wixLoc, L"#(loc.ElevateForCRTInstall)", &locStr);
2384+
if (FAILED(hr)) {
2385+
BalLogError(hr, "Failed to get ElevateForCRTInstall string");
2386+
return FALSE;
2387+
}
2388+
return ::MessageBoxW(_hWnd, locStr->wzText, _theme->sczCaption, MB_YESNO) != IDNO;
2389+
}
23142390

23152391
HRESULT EvaluateConditions() {
23162392
HRESULT hr = S_OK;
@@ -2498,6 +2574,8 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
24982574
}
24992575
}
25002576

2577+
pEngine->SetVariableNumeric(L"CRTInstalled", IsCrtInstalled() ? 1 : 0);
2578+
25012579
_wixLoc = nullptr;
25022580
memset(&_bundle, 0, sizeof(_bundle));
25032581
memset(&_conditions, 0, sizeof(_conditions));
@@ -2525,6 +2603,8 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
25252603
_suppressRepair = FALSE;
25262604
_modifying = FALSE;
25272605

2606+
_crtInstalledToken = -1;
2607+
25282608
_overridableVariables = nullptr;
25292609
_taskbarList = nullptr;
25302610
_taskbarButtonCreatedMessage = UINT_MAX;
@@ -2606,6 +2686,8 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
26062686
BOOL _suppressRepair;
26072687
BOOL _modifying;
26082688

2689+
int _crtInstalledToken;
2690+
26092691
STRINGDICT_HANDLE _overridableVariables;
26102692

26112693
ITaskbarList3* _taskbarList;

Tools/msi/bundle/bundle.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<OutputName Condition="!$(BuildForRelease)">$(OutputName)-$(MajorVersionNumber).$(MinorVersionNumber).$(MicroVersionNumber).$(RevisionNumber)</OutputName>
1111
<OutputName Condition="$(Platform) == 'x64'">$(OutputName)-amd64</OutputName>
1212
<OutputName Condition="'$(OutputSuffix)' != ''">$(OutputName)-$(OutputSuffix)</OutputName>
13+
<OutputName Condition="'$(Configuration)' == 'Debug'">$(OutputName)-d</OutputName>
14+
<TargetName>$(OutputName)</TargetName>
1315

1416
<OutputPath>$(OutputPath)en-us\</OutputPath>
1517
<OutDir>$(OutputPath)</OutDir>
@@ -43,6 +45,7 @@
4345
<Content Include="SideBar.png" />
4446
</ItemGroup>
4547
<ItemGroup>
48+
<EmbeddedResource Include="bundle.wxl" />
4649
<WxlTemplate Include="*_en-US.wxl_template" />
4750
</ItemGroup>
4851
<ItemGroup>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<WixLocalization Culture="en-us" xmlns="http://schemas.microsoft.com/wix/2006/localization">
3-
<String Id="CompileAllDescription">Precompiling standard library</String>
3+
<String Id="CRTDescription">C Runtime Update (KB2999226)</String>
4+
<String Id="CompileAllDescription">Precompiling standard library</String>
45
</WixLocalization>

Tools/msi/bundle/packagegroups/crt.wxs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
33
<Fragment>
44
<PackageGroup Id="crt">
5+
<PackageGroupRef Id="crt_14.0_v6.0" />
6+
<PackageGroupRef Id="crt_14.0_v6.1" />
7+
<PackageGroupRef Id="crt_14.0_v6.2" />
8+
<PackageGroupRef Id="crt_14.0_v6.3" />
9+
510
<MsiPackage Id="crt_AllUsers"
611
SourceFile="crt.msi"
712
Compressed="$(var.CompressMSI)"
@@ -22,4 +27,42 @@
2227
</MsiPackage>
2328
</PackageGroup>
2429
</Fragment>
30+
31+
<?foreach ver in v6.0;v6.1;v6.2;v6.3 ?>
32+
<?if "$(var.ver)" = "v6.0" ?>
33+
<?define msuver=6.0 ?>
34+
<?elseif "$(var.ver)" = "v6.1" ?>
35+
<?define msuver=6.1 ?>
36+
<?elseif "$(var.ver)" = "v6.2" ?>
37+
<?define msuver=8-RT ?>
38+
<?elseif "$(var.ver)" = "v6.3" ?>
39+
<?define msuver=8.1 ?>
40+
<?else ?>
41+
<?error unknown version $(var.ver) ?>
42+
<?endif ?>
43+
44+
<Fragment>
45+
<PackageGroup Id="crt_14.0_$(var.ver)">
46+
<MsuPackage Id="crt_14.0_$(var.ver)_x86"
47+
KB="2999226"
48+
SourceFile="!(bindpath.redist)\Windows$(var.msuver)-KB2999226-x86.msu"
49+
DisplayName="!(loc.CRTDescription)"
50+
Description="!(loc.CRTDescription)"
51+
Compressed="$(var.CompressMSI)"
52+
DownloadUrl="$(var.DownloadUrl)"
53+
InstallCondition="not CRTInstalled and VersionNT = $(var.ver) and not VersionNT64 and (Include_core or Include_exe or Include_launcher or Include_pip)" />
54+
55+
<MsuPackage Id="crt_14.0_$(var.ver)_x64"
56+
KB="2999226"
57+
SourceFile="!(bindpath.redist)\Windows$(var.msuver)-KB2999226-x64.msu"
58+
DisplayName="!(loc.CRTDescription)"
59+
Description="!(loc.CRTDescription)"
60+
Compressed="$(var.CompressMSI)"
61+
DownloadUrl="$(var.DownloadUrl)"
62+
InstallCondition="not CRTInstalled and VersionNT64 = $(var.ver) and (Include_core or Include_exe or Include_launcher or Include_pip)" />
63+
</PackageGroup>
64+
</Fragment>
65+
66+
<?undef msuver ?>
67+
<?endforeach ?>
2568
</Wix>

Tools/msi/crt/crt.wixproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Import Project="..\msi.props" />
1111
<ItemGroup>
1212
<Compile Include="crt.wxs" />
13-
<Compile Include="crt_files.$(VisualStudioVersion).wxs" />
13+
<Compile Include="crt_files.wxs" />
1414
</ItemGroup>
1515
<ItemGroup>
1616
<EmbeddedResource Include="*.wxl" />

Tools/msi/crt/crt_files.12.0.wxs

Lines changed: 0 additions & 20 deletions
This file was deleted.

Tools/msi/crt/crt_files.14.0.wxs

Lines changed: 0 additions & 40 deletions
This file was deleted.

Tools/msi/crt/crt_files.wxs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
3+
<Fragment>
4+
<?if $(var.Platform)~=x64 ?>
5+
<?define vcruntime140Guid={B33258FD-750C-3B42-8BE4-535B48E97DB4}?>
6+
<?else ?>
7+
<?define vcruntime140Guid={E8E39D3B-4F35-36D8-B892-4B28336FE041}?>
8+
<?endif ?>
9+
<ComponentGroup Id="crt_files">
10+
<Component Id="vcruntime140.dll_LM" Directory="SystemInstallDirectory" Guid="$(var.vcruntime140Guid)" Shared="yes" SharedDllRefCount="yes">
11+
<Condition>ALLUSERS=1</Condition>
12+
<File Id="vcruntime140.dll_LM" Source="!(bindpath.crt)\vcruntime140.dll" />
13+
</Component>
14+
<Component Id="vcruntime140.dll_CU" Directory="InstallDirectory" Guid="*">
15+
<Condition>NOT ALLUSERS=1</Condition>
16+
<File Id="vcruntime140.dll_CU" Source="!(bindpath.crt)\vcruntime140.dll" />
17+
</Component>
18+
</ComponentGroup>
19+
</Fragment>
20+
</Wix>

Tools/msi/msi.props

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="ReleaseUri">
33
<PropertyGroup>
4+
<TargetName>$(OutputName)</TargetName>
45
<DefineSolutionProperties>false</DefineSolutionProperties>
56
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
67
<SuppressIces>$(SuppressIces);ICE03;ICE57;ICE61</SuppressIces>
@@ -48,10 +49,8 @@
4849
<OutputPath Condition="!HasTrailingSlash($(OutputPath))">$(OutputPath)\</OutputPath>
4950
<OutDir>$(OutputPath)</OutDir>
5051
<ReuseCabinetCache>true</ReuseCabinetCache>
51-
<CRTModule Condition="'$(VisualStudioVersion)' == '12.0'">$(CommonProgramFiles)\Merge Modules\Microsoft_VC120_CRT_$(Platform).msm</CRTModule>
52-
<CRTModule Condition="'$(VisualStudioVersion)' == '14.0'">$(CommonProgramFiles)\Merge Modules\Microsoft_VC140_CRT_$(Platform).msm</CRTModule>
53-
<CRTRedist Condition="'$(VisualStudioVersion)' == '12.0'">$([System.IO.Path]::GetFullPath(`$(VS120COMNTOOLS)\..\..\VC\redist\$(Platform)\Microsoft.VC120.CRT`))</CRTRedist>
54-
<CRTRedist Condition="'$(VisualStudioVersion)' == '14.0'">$([System.IO.Path]::GetFullPath(`$(VS140COMNTOOLS)\..\..\VC\redist\$(Platform)\Microsoft.VC140.CRT`))</CRTRedist>
52+
<CRTRedist Condition="">$([System.IO.Path]::GetFullPath(`$(VS140COMNTOOLS)\..\..\VC\redist\$(Platform)\Microsoft.VC140.CRT`))</CRTRedist>
53+
<CRTRedist Condition="'$(CRTRedist)' != '' and !Exists($(CRTRedist))">$(MSBuildThisFileDirectory)\redist\$(Platform)</CRTRedist>
5554
<CRTRedist Condition="'$(CRTRedist)' != '' and !Exists($(CRTRedist))"></CRTRedist>
5655

5756
<RevisionNumber>$(ReleaseLevelNumber)</RevisionNumber>
@@ -72,9 +71,6 @@
7271
NextMajorVersionNumber=$(MajorVersionNumber).$([msbuild]::Add($(MinorVersionNumber), 1)).0.0;
7372
PyDebugExt=$(PyDebugExt);
7473
</DefineConstants>
75-
<DefineConstants Condition="'$(CRTModule)' != '' and Exists($(CRTModule))">
76-
$(DefineConstants);CRTModule=$(CRTModule);
77-
</DefineConstants>
7874
<DefineConstants Condition="'$(CRTRedist)' != ''">
7975
$(DefineConstants);CRTRedist=$(CRTRedist);
8076
</DefineConstants>
@@ -115,6 +111,9 @@
115111
<LinkerBindInputPaths Include="$(CRTRedist)" Condition="'$(CRTRedist)' != ''">
116112
<BindName>crt</BindName>
117113
</LinkerBindInputPaths>
114+
<LinkerBindInputPaths Include="$(MSBuildThisFileDirectory)\redist">
115+
<BindName>redist</BindName>
116+
</LinkerBindInputPaths>
118117
</ItemGroup>
119118

120119
<Target Name="_ValidateMsiProps" BeforeTargets="PrepareForBuild">

0 commit comments

Comments
 (0)