From 6543328d657a52e7b4a96c8f1dd8a9a6f7fbf71e Mon Sep 17 00:00:00 2001
From: Nehal J Wani <nehaljw.kkd1@gmail.com>
Date: Sat, 24 Nov 2018 20:38:02 -0600
Subject: [PATCH 10/25] Unvendor openssl

Co-authored-by: Isuru Fernando <isuruf@gmail.com>
---
 PCbuild/_ssl.vcxproj         |  3 --
 PCbuild/_ssl.vcxproj.filters |  3 --
 PCbuild/openssl.props        | 10 ++-----
 PCbuild/openssl.vcxproj      | 56 ------------------------------------
 PCbuild/python.props         |  1 +
 PCbuild/python.vcxproj       |  3 ++
 PCbuild/pythonw.vcxproj      |  3 ++
 7 files changed, 9 insertions(+), 70 deletions(-)

diff --git a/PCbuild/_ssl.vcxproj b/PCbuild/_ssl.vcxproj
index 4907f49b66..b2c23d5e8c 100644
--- a/PCbuild/_ssl.vcxproj
+++ b/PCbuild/_ssl.vcxproj
@@ -99,9 +99,6 @@
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClCompile Include="..\Modules\_ssl.c" />
-    <ClCompile Include="$(opensslIncludeDir)\applink.c">
-      <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;$(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="..\PC\python_nt.rc" />
diff --git a/PCbuild/_ssl.vcxproj.filters b/PCbuild/_ssl.vcxproj.filters
index 716a69a41a..8aef9e03fc 100644
--- a/PCbuild/_ssl.vcxproj.filters
+++ b/PCbuild/_ssl.vcxproj.filters
@@ -12,9 +12,6 @@
     <ClCompile Include="..\Modules\_ssl.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="$(opensslIncludeDir)\applink.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="..\PC\python_nt.rc">
diff --git a/PCbuild/openssl.props b/PCbuild/openssl.props
index a7e16793c7..f7e9be4d11 100644
--- a/PCbuild/openssl.props
+++ b/PCbuild/openssl.props
@@ -2,10 +2,10 @@
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemDefinitionGroup>
     <ClCompile>
-      <AdditionalIncludeDirectories>$(opensslIncludeDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>$(condaDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
-      <AdditionalLibraryDirectories>$(opensslOutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <AdditionalLibraryDirectories>$(condaDir)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <AdditionalDependencies>ws2_32.lib;libcrypto.lib;libssl.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
@@ -20,10 +20,4 @@
     <_SSLDLL Include="$(opensslOutDir)\libssl$(_DLLSuffix).dll" />
     <_SSLDLL Include="$(opensslOutDir)\libssl$(_DLLSuffix).pdb" />
   </ItemGroup>
-  <Target Name="_CopySSLDLL" Inputs="@(_SSLDLL)" Outputs="@(_SSLDLL->'$(OutDir)%(Filename)%(Extension)')" AfterTargets="Build">
-    <Copy SourceFiles="@(_SSLDLL)" DestinationFolder="$(OutDir)" />
-  </Target>
-  <Target Name="_CleanSSLDLL" BeforeTargets="Clean">
-    <Delete Files="@(_SSLDLL->'$(OutDir)%(Filename)%(Extension)')" TreatErrorsAsWarnings="true" />
-  </Target>
 </Project>
\ No newline at end of file
diff --git a/PCbuild/openssl.vcxproj b/PCbuild/openssl.vcxproj
index 0da6f67495..17eee400eb 100644
--- a/PCbuild/openssl.vcxproj
+++ b/PCbuild/openssl.vcxproj
@@ -60,64 +60,8 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <Import Project="pyproject.props" />
 
-  <PropertyGroup>
-    <IntDir>$(opensslDir)\tmp$(Bitness)dll</IntDir>
-    <OutDir>$(opensslOutDir)</OutDir>
-    <NMakeBuildCommandLine>setlocal
-set VCINSTALLDIR=$(VCInstallDir)
-if not exist "$(IntDir.TrimEnd('\'))" mkdir "$(IntDir.TrimEnd('\'))"
-cd /D "$(IntDir.TrimEnd('\'))"
-$(Perl) "$(opensslDir)\configure" $(OpenSSLPlatform) no-asm
-nmake
-</NMakeBuildCommandLine>
-  </PropertyGroup>
-
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
 
-  <Target Name="_PatchUplink" BeforeTargets="Build">
-    <PropertyGroup>
-      <Uplink>$(opensslDir)\ms\uplink.c</Uplink>
-      <BeforePatch>((h = GetModuleHandle(NULL)) == NULL)</BeforePatch>
-      <AfterPatch>((h = GetModuleHandleA("_ssl.pyd")) == NULL) if ((h = GetModuleHandleA("_ssl_d.pyd")) == NULL) if ((h = GetModuleHandle(NULL)) == NULL /*patched*/)</AfterPatch>
-    </PropertyGroup>
-    <Error Text="Cannot find $(Uplink)" Condition="!Exists($(Uplink))" />
-    <PropertyGroup>
-      <_Original>$([System.IO.File]::ReadAllText($(Uplink)))</_Original>
-      <_Patched>$(_Original.Replace($(BeforePatch), $(AfterPatch)))</_Patched>
-      <IsPatched>false</IsPatched>
-      <IsPatched Condition="$(_Patched) == $(_Original)">true</IsPatched>
-    </PropertyGroup>
-    <Message Text="$(Uplink) is already patched" Importance="normal" Condition="$(IsPatched)" />
-    <Message Text="Patching $(Uplink)" Importance="high" Condition="!$(IsPatched)" />
-    <WriteLinesToFile File="$(Uplink)"
-                      Lines="$(_Patched)"
-                      Overwrite="true"
-                      Encoding="ASCII"
-                      Condition="!$(IsPatched)" />
-  </Target>
-
-  <Target Name="_CopyToOutput" AfterTargets="Build">
-    <ItemGroup>
-      <_Built Include="$(opensslDir)\LICENSE" />
-      <_Built Include="$(IntDir)\libcrypto.lib;$(IntDir)\libcrypto-*.dll;$(IntDir)\libcrypto-*.pdb" />
-      <_Built Include="$(IntDir)\libssl.lib;$(IntDir)\libssl-*.dll;$(IntDir)\libssl-*.pdb" />
-      <_AppLink Include="$(opensslDir)\ms\applink.c" />
-      <_Include Include="$(opensslDir)\Include\openssl\*.h" />
-      <_Include Include="$(IntDir)\include\openssl\*.h" />
-    </ItemGroup>
-    <MakeDir Directories="$(opensslOutDir)\include\openssl" />
-    <Copy SourceFiles="@(_Built)" DestinationFolder="$(opensslOutDir)" />
-    <Copy SourceFiles="@(_AppLink)" DestinationFolder="$(opensslOutDir)\include" />
-    <Copy SourceFiles="@(_Include)" DestinationFolder="$(opensslOutDir)\include\openssl" />
-  </Target>
-
-  <Target Name="SignFiles" AfterTargets="Build" Condition="$(_SignCommand) != ''">
-    <ItemGroup>
-      <FilesToSign Include="$(opensslOutDir)\lib*.dll" />
-    </ItemGroup>
-    <Exec Command="$(_SignCommand) %(FilesToSign.FullPath)" ContinueOnError="true" />
-  </Target>
-
   <Target Name="Clean" />
   <Target Name="CleanAll">
     <Delete Files="$(TargetPath);$(BuildPath)$(tclDLLName)" />
diff --git a/PCbuild/python.props b/PCbuild/python.props
index 1f9b0e7736..19caa9e3d3 100644
--- a/PCbuild/python.props
+++ b/PCbuild/python.props
@@ -57,6 +57,7 @@
   <!-- Directories of external projects. tcltk is handled in tcltk.props -->
   <PropertyGroup>
     <ExternalsDir Condition="$(ExternalsDir) == ''">$(EXTERNALS_DIR)</ExternalsDir>
+    <condaDir>$(LIBRARY_PREFIX)\</condaDir>
     <ExternalsDir Condition="$(ExternalsDir) == ''">$([System.IO.Path]::GetFullPath(`$(PySourcePath)externals`))</ExternalsDir>
     <ExternalsDir Condition="!HasTrailingSlash($(ExternalsDir))">$(ExternalsDir)\</ExternalsDir>
   </PropertyGroup>
diff --git a/PCbuild/python.vcxproj b/PCbuild/python.vcxproj
index b6dcf14823..3481ed3d47 100644
--- a/PCbuild/python.vcxproj
+++ b/PCbuild/python.vcxproj
@@ -105,6 +105,9 @@
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\Programs\python.c" />
+    <ClCompile Include="$(condaDir)include\openssl\applink.c">
+      <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;$(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="pythoncore.vcxproj">
diff --git a/PCbuild/pythonw.vcxproj b/PCbuild/pythonw.vcxproj
index e7216dec3a..247ea10d5c 100644
--- a/PCbuild/pythonw.vcxproj
+++ b/PCbuild/pythonw.vcxproj
@@ -97,6 +97,9 @@
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\PC\WinMain.c" />
+    <ClCompile Include="$(condaDir)include\openssl\applink.c">
+      <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;$(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="pythoncore.vcxproj">
