| 
									
										
										
										
											2018-12-10 18:52:57 -08:00
										 |  |  | """
 | 
					
						
							|  |  |  | Provides .props file. | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .constants import * | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-14 08:29:20 -07:00
										 |  |  | __all__ = ["get_props_layout"] | 
					
						
							| 
									
										
										
										
											2018-12-10 18:52:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | PYTHON_PROPS_NAME = "python.props" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PROPS_DATA = { | 
					
						
							|  |  |  |     "PYTHON_TAG": VER_DOT, | 
					
						
							|  |  |  |     "PYTHON_VERSION": os.getenv("PYTHON_NUSPEC_VERSION"), | 
					
						
							|  |  |  |     "PYTHON_PLATFORM": os.getenv("PYTHON_PROPS_PLATFORM"), | 
					
						
							|  |  |  |     "PYTHON_TARGET": "", | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if not PROPS_DATA["PYTHON_VERSION"]: | 
					
						
							| 
									
										
										
										
											2019-11-20 09:30:47 -08:00
										 |  |  |     PROPS_DATA["PYTHON_VERSION"] = "{}.{}{}{}".format( | 
					
						
							|  |  |  |         VER_DOT, VER_MICRO, "-" if VER_SUFFIX else "", VER_SUFFIX | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-12-10 18:52:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | PROPS_DATA["PYTHON_TARGET"] = "_GetPythonRuntimeFilesDependsOn{}{}_{}".format( | 
					
						
							|  |  |  |     VER_MAJOR, VER_MINOR, PROPS_DATA["PYTHON_PLATFORM"] | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PROPS_TEMPLATE = r"""<?xml version="1.0" encoding="utf-8"?>
 | 
					
						
							| 
									
										
										
										
											2017-09-06 19:29:10 -07:00
										 |  |  | <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | 
					
						
							| 
									
										
										
										
											2018-12-10 18:52:57 -08:00
										 |  |  |   <PropertyGroup Condition="$(Platform) == '{PYTHON_PLATFORM}'"> | 
					
						
							| 
									
										
										
										
											2020-04-03 13:03:54 -07:00
										 |  |  |     <PythonHome Condition="$(PythonHome) == ''">$([System.IO.Path]::GetFullPath("$(MSBuildThisFileDirectory)\..\..\tools"))</PythonHome> | 
					
						
							| 
									
										
										
										
											2017-09-06 19:29:10 -07:00
										 |  |  |     <PythonInclude>$(PythonHome)\include</PythonInclude> | 
					
						
							|  |  |  |     <PythonLibs>$(PythonHome)\libs</PythonLibs> | 
					
						
							| 
									
										
										
										
											2018-12-10 18:52:57 -08:00
										 |  |  |     <PythonTag>{PYTHON_TAG}</PythonTag> | 
					
						
							|  |  |  |     <PythonVersion>{PYTHON_VERSION}</PythonVersion> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 19:29:10 -07:00
										 |  |  |     <IncludePythonExe Condition="$(IncludePythonExe) == ''">true</IncludePythonExe> | 
					
						
							|  |  |  |     <IncludeDistutils Condition="$(IncludeDistutils) == ''">false</IncludeDistutils> | 
					
						
							|  |  |  |     <IncludeLib2To3 Condition="$(IncludeLib2To3) == ''">false</IncludeLib2To3> | 
					
						
							|  |  |  |     <IncludeVEnv Condition="$(IncludeVEnv) == ''">false</IncludeVEnv> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:52:57 -08:00
										 |  |  |     <GetPythonRuntimeFilesDependsOn>{PYTHON_TARGET};$(GetPythonRuntimeFilesDependsOn)</GetPythonRuntimeFilesDependsOn> | 
					
						
							| 
									
										
										
										
											2017-09-06 19:29:10 -07:00
										 |  |  |   </PropertyGroup> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:52:57 -08:00
										 |  |  |   <ItemDefinitionGroup Condition="$(Platform) == '{PYTHON_PLATFORM}'"> | 
					
						
							| 
									
										
										
										
											2017-09-06 19:29:10 -07:00
										 |  |  |     <ClCompile> | 
					
						
							|  |  |  |       <AdditionalIncludeDirectories>$(PythonInclude);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | 
					
						
							|  |  |  |       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> | 
					
						
							|  |  |  |     </ClCompile> | 
					
						
							|  |  |  |     <Link> | 
					
						
							|  |  |  |       <AdditionalLibraryDirectories>$(PythonLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | 
					
						
							|  |  |  |     </Link> | 
					
						
							|  |  |  |   </ItemDefinitionGroup> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <Target Name="GetPythonRuntimeFiles" Returns="@(PythonRuntime)" DependsOnTargets="$(GetPythonRuntimeFilesDependsOn)" /> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:52:57 -08:00
										 |  |  |   <Target Name="{PYTHON_TARGET}" Returns="@(PythonRuntime)"> | 
					
						
							| 
									
										
										
										
											2017-09-06 19:29:10 -07:00
										 |  |  |     <ItemGroup> | 
					
						
							|  |  |  |       <_PythonRuntimeExe Include="$(PythonHome)\python*.dll" /> | 
					
						
							|  |  |  |       <_PythonRuntimeExe Include="$(PythonHome)\python*.exe" Condition="$(IncludePythonExe) == 'true'" /> | 
					
						
							|  |  |  |       <_PythonRuntimeExe> | 
					
						
							|  |  |  |         <Link>%(Filename)%(Extension)</Link> | 
					
						
							|  |  |  |       </_PythonRuntimeExe> | 
					
						
							|  |  |  |       <_PythonRuntimeDlls Include="$(PythonHome)\DLLs\*.pyd" /> | 
					
						
							|  |  |  |       <_PythonRuntimeDlls Include="$(PythonHome)\DLLs\*.dll" /> | 
					
						
							|  |  |  |       <_PythonRuntimeDlls> | 
					
						
							|  |  |  |         <Link>DLLs\%(Filename)%(Extension)</Link> | 
					
						
							|  |  |  |       </_PythonRuntimeDlls> | 
					
						
							|  |  |  |       <_PythonRuntimeLib Include="$(PythonHome)\Lib\**\*" Exclude="$(PythonHome)\Lib\**\*.pyc;$(PythonHome)\Lib\site-packages\**\*" /> | 
					
						
							|  |  |  |       <_PythonRuntimeLib Remove="$(PythonHome)\Lib\distutils\**\*" Condition="$(IncludeDistutils) != 'true'" /> | 
					
						
							|  |  |  |       <_PythonRuntimeLib Remove="$(PythonHome)\Lib\lib2to3\**\*" Condition="$(IncludeLib2To3) != 'true'" /> | 
					
						
							|  |  |  |       <_PythonRuntimeLib Remove="$(PythonHome)\Lib\ensurepip\**\*" Condition="$(IncludeVEnv) != 'true'" /> | 
					
						
							|  |  |  |       <_PythonRuntimeLib Remove="$(PythonHome)\Lib\venv\**\*" Condition="$(IncludeVEnv) != 'true'" /> | 
					
						
							|  |  |  |       <_PythonRuntimeLib> | 
					
						
							|  |  |  |         <Link>Lib\%(RecursiveDir)%(Filename)%(Extension)</Link> | 
					
						
							|  |  |  |       </_PythonRuntimeLib> | 
					
						
							|  |  |  |       <PythonRuntime Include="@(_PythonRuntimeExe);@(_PythonRuntimeDlls);@(_PythonRuntimeLib)" /> | 
					
						
							|  |  |  |     </ItemGroup> | 
					
						
							| 
									
										
										
										
											2018-12-10 18:52:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 19:29:10 -07:00
										 |  |  |     <Message Importance="low" Text="Collected Python runtime from $(PythonHome):%0D%0A@(PythonRuntime->'  %(Link)','%0D%0A')" /> | 
					
						
							|  |  |  |   </Target> | 
					
						
							|  |  |  | </Project> | 
					
						
							| 
									
										
										
										
											2018-12-10 18:52:57 -08:00
										 |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_props_layout(ns): | 
					
						
							|  |  |  |     if ns.include_all or ns.include_props: | 
					
						
							| 
									
										
										
										
											2019-06-14 08:29:20 -07:00
										 |  |  |         # TODO: Filter contents of props file according to included/excluded items | 
					
						
							| 
									
										
										
										
											2019-11-20 09:30:47 -08:00
										 |  |  |         d = dict(PROPS_DATA) | 
					
						
							|  |  |  |         if not d.get("PYTHON_PLATFORM"): | 
					
						
							|  |  |  |             d["PYTHON_PLATFORM"] = { | 
					
						
							|  |  |  |                 "win32": "Win32", | 
					
						
							|  |  |  |                 "amd64": "X64", | 
					
						
							|  |  |  |                 "arm32": "ARM", | 
					
						
							|  |  |  |                 "arm64": "ARM64", | 
					
						
							|  |  |  |             }[ns.arch] | 
					
						
							|  |  |  |         props = PROPS_TEMPLATE.format_map(d) | 
					
						
							| 
									
										
										
										
											2019-06-14 08:29:20 -07:00
										 |  |  |         yield "python.props", ("python.props", props.encode("utf-8")) |