(root)/
Python-3.12.0/
PC/
layout/
support/
props.py
       1  """
       2  Provides .props file.
       3  """
       4  
       5  import os
       6  
       7  from .constants import *
       8  
       9  __all__ = ["get_props_layout"]
      10  
      11  PYTHON_PROPS_NAME = "python.props"
      12  
      13  PROPS_DATA = {
      14      "PYTHON_TAG": VER_DOT,
      15      "PYTHON_VERSION": os.getenv("PYTHON_NUSPEC_VERSION"),
      16      "PYTHON_PLATFORM": os.getenv("PYTHON_PROPS_PLATFORM"),
      17      "PYTHON_TARGET": "",
      18  }
      19  
      20  if not PROPS_DATA["PYTHON_VERSION"]:
      21      PROPS_DATA["PYTHON_VERSION"] = "{}.{}{}{}".format(
      22          VER_DOT, VER_MICRO, "-" if VER_SUFFIX else "", VER_SUFFIX
      23      )
      24  
      25  PROPS_DATA["PYTHON_TARGET"] = "_GetPythonRuntimeFilesDependsOn{}{}_{}".format(
      26      VER_MAJOR, VER_MINOR, PROPS_DATA["PYTHON_PLATFORM"]
      27  )
      28  
      29  PROPS_TEMPLATE = r"""<?xml version="1.0" encoding="utf-8"?>
      30  <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      31    <PropertyGroup Condition="$(Platform) == '{PYTHON_PLATFORM}'">
      32      <PythonHome Condition="$(PythonHome) == ''">$([System.IO.Path]::GetFullPath("$(MSBuildThisFileDirectory)\..\..\tools"))</PythonHome>
      33      <PythonInclude>$(PythonHome)\include</PythonInclude>
      34      <PythonLibs>$(PythonHome)\libs</PythonLibs>
      35      <PythonTag>{PYTHON_TAG}</PythonTag>
      36      <PythonVersion>{PYTHON_VERSION}</PythonVersion>
      37  
      38      <IncludePythonExe Condition="$(IncludePythonExe) == ''">true</IncludePythonExe>
      39      <IncludeLib2To3 Condition="$(IncludeLib2To3) == ''">false</IncludeLib2To3>
      40      <IncludeVEnv Condition="$(IncludeVEnv) == ''">false</IncludeVEnv>
      41  
      42      <GetPythonRuntimeFilesDependsOn>{PYTHON_TARGET};$(GetPythonRuntimeFilesDependsOn)</GetPythonRuntimeFilesDependsOn>
      43    </PropertyGroup>
      44  
      45    <ItemDefinitionGroup Condition="$(Platform) == '{PYTHON_PLATFORM}'">
      46      <ClCompile>
      47        <AdditionalIncludeDirectories>$(PythonInclude);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      48        <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
      49      </ClCompile>
      50      <Link>
      51        <AdditionalLibraryDirectories>$(PythonLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
      52      </Link>
      53    </ItemDefinitionGroup>
      54  
      55    <Target Name="GetPythonRuntimeFiles" Returns="@(PythonRuntime)" DependsOnTargets="$(GetPythonRuntimeFilesDependsOn)" />
      56  
      57    <Target Name="{PYTHON_TARGET}" Returns="@(PythonRuntime)">
      58      <ItemGroup>
      59        <_PythonRuntimeExe Include="$(PythonHome)\python*.dll" />
      60        <_PythonRuntimeExe Include="$(PythonHome)\python*.exe" Condition="$(IncludePythonExe) == 'true'" />
      61        <_PythonRuntimeExe>
      62          <Link>%(Filename)%(Extension)</Link>
      63        </_PythonRuntimeExe>
      64        <_PythonRuntimeDlls Include="$(PythonHome)\DLLs\*.pyd" />
      65        <_PythonRuntimeDlls Include="$(PythonHome)\DLLs\*.dll" />
      66        <_PythonRuntimeDlls>
      67          <Link>DLLs\%(Filename)%(Extension)</Link>
      68        </_PythonRuntimeDlls>
      69        <_PythonRuntimeLib Include="$(PythonHome)\Lib\**\*" Exclude="$(PythonHome)\Lib\**\*.pyc;$(PythonHome)\Lib\site-packages\**\*" />
      70        <_PythonRuntimeLib Remove="$(PythonHome)\Lib\lib2to3\**\*" Condition="$(IncludeLib2To3) != 'true'" />
      71        <_PythonRuntimeLib Remove="$(PythonHome)\Lib\ensurepip\**\*" Condition="$(IncludeVEnv) != 'true'" />
      72        <_PythonRuntimeLib Remove="$(PythonHome)\Lib\venv\**\*" Condition="$(IncludeVEnv) != 'true'" />
      73        <_PythonRuntimeLib>
      74          <Link>Lib\%(RecursiveDir)%(Filename)%(Extension)</Link>
      75        </_PythonRuntimeLib>
      76        <PythonRuntime Include="@(_PythonRuntimeExe);@(_PythonRuntimeDlls);@(_PythonRuntimeLib)" />
      77      </ItemGroup>
      78  
      79      <Message Importance="low" Text="Collected Python runtime from $(PythonHome):%0D%0A@(PythonRuntime->'  %(Link)','%0D%0A')" />
      80    </Target>
      81  </Project>
      82  """
      83  
      84  
      85  def get_props_layout(ns):
      86      if ns.include_all or ns.include_props:
      87          # TODO: Filter contents of props file according to included/excluded items
      88          d = dict(PROPS_DATA)
      89          if not d.get("PYTHON_PLATFORM"):
      90              d["PYTHON_PLATFORM"] = {
      91                  "win32": "Win32",
      92                  "amd64": "X64",
      93                  "arm32": "ARM",
      94                  "arm64": "ARM64",
      95              }[ns.arch]
      96          props = PROPS_TEMPLATE.format_map(d)
      97          yield "python.props", ("python.props", props.encode("utf-8"))