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

Skip to content

Commit 96d97ec

Browse files
committed
Issue #15431: Add _freeze_importlib project to regenerate importlib.h on Windows.
Patch by Kristján Valur Jónsson.
1 parent 79b7ea1 commit 96d97ec

5 files changed

Lines changed: 241 additions & 4 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ Tests
256256
Build
257257
-----
258258

259+
- Issue #15431: Add _freeze_importlib project to regenerate importlib.h
260+
on Windows. Patch by Kristj�n Valur J�nsson.
261+
259262
- Issue #14197: For OS X framework builds, ensure links to the shared
260263
library are created with the proper ABI suffix.
261264

Modules/_freeze_importlib.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#include <stdio.h>
99
#include <sys/types.h>
1010
#include <sys/stat.h>
11+
#ifndef MS_WINDOWS
1112
#include <unistd.h>
13+
#endif
1214

1315

1416
/* To avoid a circular dependency on frozen.o, we create our own structure
@@ -19,9 +21,6 @@ static struct _frozen _PyImport_FrozenModules[] = {
1921
{0, 0, 0} /* sentinel */
2022
};
2123

22-
struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules;
23-
24-
2524
const char header[] = "/* Auto-generated by Modules/_freeze_importlib.c */";
2625

2726
int
@@ -35,6 +34,8 @@ main(int argc, char *argv[])
3534
unsigned char *data;
3635
PyObject *code, *marshalled;
3736

37+
PyImport_FrozenModules = _PyImport_FrozenModules;
38+
3839
if (argc != 3) {
3940
fprintf(stderr, "need to specify input and output paths\n");
4041
return 2;
@@ -89,7 +90,9 @@ main(int argc, char *argv[])
8990
data = (unsigned char *) PyBytes_AS_STRING(marshalled);
9091
data_size = PyBytes_GET_SIZE(marshalled);
9192

92-
outfile = fopen(outpath, "wb");
93+
/* Open the file in text mode. The hg checkout should be using the eol extension,
94+
which in turn should cause the existing file to use CRLF */
95+
outfile = fopen(outpath, "wt");
9396
if (outfile == NULL) {
9497
fprintf(stderr, "cannot open '%s' for writing\n", outpath);
9598
return 1;

PCbuild/_freeze_importlib.vcxproj

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Debug|x64">
9+
<Configuration>Debug</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Release|Win32">
13+
<Configuration>Release</Configuration>
14+
<Platform>Win32</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<ProjectGuid>{19C0C13F-47CA-4432-AFF3-799A296A4DDC}</ProjectGuid>
23+
<Keyword>Win32Proj</Keyword>
24+
<RootNamespace>_freeze_importlib</RootNamespace>
25+
</PropertyGroup>
26+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
27+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
28+
<ConfigurationType>Application</ConfigurationType>
29+
<UseDebugLibraries>true</UseDebugLibraries>
30+
<CharacterSet>Unicode</CharacterSet>
31+
</PropertyGroup>
32+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
33+
<ConfigurationType>Application</ConfigurationType>
34+
<UseDebugLibraries>true</UseDebugLibraries>
35+
<CharacterSet>Unicode</CharacterSet>
36+
</PropertyGroup>
37+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
38+
<ConfigurationType>Application</ConfigurationType>
39+
<UseDebugLibraries>false</UseDebugLibraries>
40+
<WholeProgramOptimization>true</WholeProgramOptimization>
41+
<CharacterSet>Unicode</CharacterSet>
42+
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
44+
<ConfigurationType>Application</ConfigurationType>
45+
<UseDebugLibraries>false</UseDebugLibraries>
46+
<WholeProgramOptimization>true</WholeProgramOptimization>
47+
<CharacterSet>Unicode</CharacterSet>
48+
</PropertyGroup>
49+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
50+
<ImportGroup Label="ExtensionSettings">
51+
</ImportGroup>
52+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
53+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
54+
<Import Project="pyproject.props" />
55+
<Import Project="debug.props" />
56+
</ImportGroup>
57+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
58+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
59+
<Import Project="pyproject.props" />
60+
<Import Project="debug.props" />
61+
<Import Project="x64.props" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
<Import Project="pyproject.props" />
66+
</ImportGroup>
67+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
68+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
69+
<Import Project="pyproject.props" />
70+
<Import Project="x64.props" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<LinkIncremental>true</LinkIncremental>
75+
</PropertyGroup>
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
77+
<LinkIncremental>true</LinkIncremental>
78+
</PropertyGroup>
79+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
80+
<LinkIncremental>false</LinkIncremental>
81+
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
83+
<LinkIncremental>false</LinkIncremental>
84+
</PropertyGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
86+
<ClCompile>
87+
<PrecompiledHeader>
88+
</PrecompiledHeader>
89+
<WarningLevel>Level3</WarningLevel>
90+
<Optimization>Disabled</Optimization>
91+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
92+
</ClCompile>
93+
<Link>
94+
<SubSystem>Console</SubSystem>
95+
<GenerateDebugInformation>true</GenerateDebugInformation>
96+
</Link>
97+
<PostBuildEvent>
98+
<Command>$(TargetPath) ..\Lib\importlib\_bootstrap.py ..\Python\importlib.h</Command>
99+
</PostBuildEvent>
100+
<PostBuildEvent>
101+
<Message>creating importlib.h</Message>
102+
</PostBuildEvent>
103+
</ItemDefinitionGroup>
104+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
105+
<ClCompile>
106+
<PrecompiledHeader>
107+
</PrecompiledHeader>
108+
<WarningLevel>Level3</WarningLevel>
109+
<Optimization>Disabled</Optimization>
110+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
111+
</ClCompile>
112+
<Link>
113+
<SubSystem>Console</SubSystem>
114+
<GenerateDebugInformation>true</GenerateDebugInformation>
115+
</Link>
116+
<PostBuildEvent>
117+
<Command>$(TargetPath) ..\Lib\importlib\_bootstrap.py ..\Python\importlib.h</Command>
118+
</PostBuildEvent>
119+
<PostBuildEvent>
120+
<Message>creating importlib.h</Message>
121+
</PostBuildEvent>
122+
</ItemDefinitionGroup>
123+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
124+
<ClCompile>
125+
<WarningLevel>Level3</WarningLevel>
126+
<PrecompiledHeader>
127+
</PrecompiledHeader>
128+
<Optimization>MaxSpeed</Optimization>
129+
<FunctionLevelLinking>true</FunctionLevelLinking>
130+
<IntrinsicFunctions>true</IntrinsicFunctions>
131+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
132+
</ClCompile>
133+
<Link>
134+
<SubSystem>Console</SubSystem>
135+
<GenerateDebugInformation>true</GenerateDebugInformation>
136+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
137+
<OptimizeReferences>true</OptimizeReferences>
138+
</Link>
139+
<PostBuildEvent>
140+
<Command>$(TargetPath) ..\Lib\importlib\_bootstrap.py ..\Python\importlib.h</Command>
141+
</PostBuildEvent>
142+
<PostBuildEvent>
143+
<Message>creating importlib.h</Message>
144+
</PostBuildEvent>
145+
</ItemDefinitionGroup>
146+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
147+
<ClCompile>
148+
<WarningLevel>Level3</WarningLevel>
149+
<PrecompiledHeader>
150+
</PrecompiledHeader>
151+
<Optimization>MaxSpeed</Optimization>
152+
<FunctionLevelLinking>true</FunctionLevelLinking>
153+
<IntrinsicFunctions>true</IntrinsicFunctions>
154+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
155+
</ClCompile>
156+
<Link>
157+
<SubSystem>Console</SubSystem>
158+
<GenerateDebugInformation>true</GenerateDebugInformation>
159+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
160+
<OptimizeReferences>true</OptimizeReferences>
161+
</Link>
162+
<PostBuildEvent>
163+
<Command>$(TargetPath) ..\Lib\importlib\_bootstrap.py ..\Python\importlib.h</Command>
164+
</PostBuildEvent>
165+
<PostBuildEvent>
166+
<Message>creating importlib.h</Message>
167+
</PostBuildEvent>
168+
</ItemDefinitionGroup>
169+
<ItemGroup>
170+
<ClCompile Include="..\Modules\_freeze_importlib.c" />
171+
</ItemGroup>
172+
<ItemGroup>
173+
<ProjectReference Include="pythoncore.vcxproj">
174+
<Project>{cf7ac3d1-e2df-41d2-bea6-1e2556cdea26}</Project>
175+
<Private>true</Private>
176+
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
177+
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
178+
<LinkLibraryDependencies>true</LinkLibraryDependencies>
179+
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
180+
</ProjectReference>
181+
</ItemGroup>
182+
<ItemGroup>
183+
<None Include="..\Lib\importlib\_bootstrap.py" />
184+
</ItemGroup>
185+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
186+
<ImportGroup Label="ExtensionTargets">
187+
</ImportGroup>
188+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="..\Modules\_freeze_importlib.c">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<None Include="..\Lib\importlib\_bootstrap.py">
24+
<Filter>Source Files</Filter>
25+
</None>
26+
</ItemGroup>
27+
</Project>

PCbuild/pcbuild.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pylauncher", "pylauncher.vc
7272
EndProject
7373
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pywlauncher", "pywlauncher.vcxproj", "{1D4B18D3-7C12-4ECB-9179-8531FF876CE6}"
7474
EndProject
75+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_freeze_importlib", "_freeze_importlib.vcxproj", "{19C0C13F-47CA-4432-AFF3-799A296A4DDC}"
76+
EndProject
7577
Global
7678
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7779
Debug|Win32 = Debug|Win32
@@ -600,6 +602,20 @@ Global
600602
{1D4B18D3-7C12-4ECB-9179-8531FF876CE6}.Release|Win32.Build.0 = Release|Win32
601603
{1D4B18D3-7C12-4ECB-9179-8531FF876CE6}.Release|x64.ActiveCfg = Release|Win32
602604
{1D4B18D3-7C12-4ECB-9179-8531FF876CE6}.Release|x64.Build.0 = Release|Win32
605+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.Debug|Win32.ActiveCfg = Debug|Win32
606+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.Debug|Win32.Build.0 = Debug|Win32
607+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.Debug|x64.ActiveCfg = Debug|x64
608+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.Debug|x64.Build.0 = Debug|x64
609+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.PGInstrument|Win32.ActiveCfg = Release|Win32
610+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.PGInstrument|Win32.Build.0 = Release|Win32
611+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.PGInstrument|x64.ActiveCfg = Release|Win32
612+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.PGUpdate|Win32.ActiveCfg = Release|Win32
613+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.PGUpdate|Win32.Build.0 = Release|Win32
614+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.PGUpdate|x64.ActiveCfg = Release|Win32
615+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.Release|Win32.ActiveCfg = Release|Win32
616+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.Release|Win32.Build.0 = Release|Win32
617+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.Release|x64.ActiveCfg = Release|x64
618+
{19C0C13F-47CA-4432-AFF3-799A296A4DDC}.Release|x64.Build.0 = Release|x64
603619
EndGlobalSection
604620
GlobalSection(SolutionProperties) = preSolution
605621
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)