]> granicus.if.org Git - python/commitdiff
Adds batch file for building nuget package, and includes libs folder
authorSteve Dower <steve.dower@microsoft.com>
Mon, 27 Jun 2016 16:54:03 +0000 (09:54 -0700)
committerSteve Dower <steve.dower@microsoft.com>
Mon, 27 Jun 2016 16:54:03 +0000 (09:54 -0700)
Tools/nuget/build.bat [new file with mode: 0644]
Tools/nuget/make_pkg.proj
Tools/nuget/make_zip.py

diff --git a/Tools/nuget/build.bat b/Tools/nuget/build.bat
new file mode 100644 (file)
index 0000000..3c953f7
--- /dev/null
@@ -0,0 +1,63 @@
+@echo off\r
+setlocal\r
+set D=%~dp0\r
+set PCBUILD=%D%..\..\PCBuild\\r
+\r
+set BUILDX86=\r
+set BUILDX64=\r
+set REBUILD=\r
+set OUTPUT=\r
+set PACKAGES=\r
+\r
+:CheckOpts\r
+if "%~1" EQU "-h" goto Help\r
+if "%~1" EQU "-x86" (set BUILDX86=1) && shift && goto CheckOpts\r
+if "%~1" EQU "-x64" (set BUILDX64=1) && shift && goto CheckOpts\r
+if "%~1" EQU "-r" (set REBUILD=-r) && shift && goto CheckOpts\r
+if "%~1" EQU "-o" (set OUTPUT="/p:OutputPath=%~2") && shift && shift && goto CheckOpts\r
+if "%~1" EQU "--out" (set OUTPUT="/p:OutputPath=%~2") && shift && shift && goto CheckOpts\r
+if "%~1" EQU "-p" (set PACKAGES=%PACKAGES% %~2) && shift && shift && goto CheckOpts\r
+\r
+if not defined BUILDX86 if not defined BUILDX64 (set BUILDX86=1) && (set BUILDX64=1)\r
+\r
+if not defined NUGET where nuget -q || echo Cannot find nuget.exe on PATH and NUGET is not set. && exit /B 1\r
+if not defined PYTHON set PYTHON=py -3\r
+\r
+@%PYTHON% -c "" >nul 2>nul\r
+@if errorlevel 1 (\r
+    %NUGET% install python -OutputDirectory "%D%obj" -ExcludeVersion -NonInteractive\r
+    set PYTHON="%D%obj\python\tools\python.exe"\r
+)\r
+\r
+call "%PCBUILD%env.bat" x86\r
+\r
+if defined PACKAGES set PACKAGES="/p:Packages=%PACKAGES%"\r
+\r
+if defined BUILDX86 (\r
+    if defined REBUILD ( call "%PCBUILD%build.bat" -e -r\r
+    ) else if not exist "%PCBUILD%python.exe" call "%PCBUILD%build.bat" -e\r
+    if errorlevel 1 goto :eof\r
+\r
+    msbuild "%D%make_pkg.proj" /p:Configuration=Release /p:Platform=x86 %OUTPUT% %PACKAGES%\r
+    if errorlevel 1 goto :eof\r
+)\r
+\r
+if defined BUILDX64 (\r
+    if defined REBUILD ( call "%PCBUILD%build.bat" -p x64 -e -r\r
+    ) else if not exist "%PCBUILD%amd64\python.exe" call "%PCBUILD%build.bat" -p x64 -e\r
+    if errorlevel 1 goto :eof\r
+\r
+    msbuild "%D%make_pkg.proj" /p:Configuration=Release /p:Platform=x64 %OUTPUT% %PACKAGES%\r
+    if errorlevel 1 goto :eof\r
+)\r
+\r
+exit /B 0\r
+\r
+:Help\r
+echo build.bat [-x86] [-x64] [--out DIR] [-r] [-h]\r
+echo.\r
+echo    -x86                Build x86 installers\r
+echo    -x64                Build x64 installers\r
+echo    -r                  Rebuild rather than incremental build\r
+echo    --out [DIR]         Override output directory\r
+echo    -h                  Show usage\r
index 26d900e5b4cea0f11d1f2cd2fcf52fa3a0d3f4c2..cb124abb5e815059550da98488ec5cc2ecab2199 100644 (file)
@@ -7,6 +7,7 @@
         <OutputPath Condition="$(OutputPath) == ''">$(MSBuildThisFileDirectory)</OutputPath>
         <OutputSuffix></OutputSuffix>
         <SupportSigning>false</SupportSigning>
+        <BuildForRelease Condition="$(BuildForRelease) == ''">true</BuildForRelease>
     </PropertyGroup>
 
     <Import Project="..\..\PCBuild\python.props" />
         <PythonArguments>$(PythonArguments) -s "$(PySourcePath.Trim('\'))" -t "$(IntermediateOutputPath)" -a $(ArchName)</PythonArguments>
         
         <PipArguments>"$(IntermediateOutputPath)\python.exe" -B -c "import sys; sys.path.append(r'$(PySourcePath)\Lib'); import ensurepip; ensurepip._main()"</PipArguments>
+        <PackageArguments Condition="$(Packages) != ''">"$(IntermediateOutputPath)\python.exe" -B -m pip install -U $(Packages)</PackageArguments>
         
         <NugetArguments>"$(Nuget)" pack "$(MSBuildThisFileDirectory)\$(OutputName).nuspec"</NugetArguments>
         <NugetArguments>$(NugetArguments) -BasePath "$(IntermediateOutputPath)"</NugetArguments>
-        <NugetArguments>$(NugetArguments) -OutputDirectory "$(OutputPath.Trim('\'))"</NugetArguments>
+        <NugetArguments>$(NugetArguments) -OutputDirectory "$(OutputPath.Trim(`\`))"</NugetArguments>
         <NugetArguments>$(NugetArguments) -Version "$(NuspecVersion)"</NugetArguments>
         <NugetArguments>$(NugetArguments) -NoPackageAnalysis -NonInteractive</NugetArguments>
     </PropertyGroup>
@@ -42,6 +44,7 @@
         <Exec Command="$(CleanCommand)" />
         <Exec Command="$(PythonArguments)" />
         <Exec Command="$(PipArguments)" />
+        <Exec Command="$(PackageArguments)" Condition="$(PackageArguments) != ''" />
         <Exec Command="$(NugetArguments)" />
     </Target>
 
index 38b9590098c709a81bb2e14a762a3e721d5cd94d..af64323c9b1235aeb23c9308888763a94c30eeef 100644 (file)
@@ -14,9 +14,19 @@ from zipfile import ZipFile, ZIP_DEFLATED
 import subprocess
 
 TKTCL_RE = re.compile(r'^(_?tk|tcl).+\.(pyd|dll)', re.IGNORECASE)
-DEBUG_RE = re.compile(r'_d\.(pyd|dll|exe)$', re.IGNORECASE)
+DEBUG_RE = re.compile(r'_d\.(pyd|dll|exe|pdb|lib)$', re.IGNORECASE)
 PYTHON_DLL_RE = re.compile(r'python\d\d?\.dll$', re.IGNORECASE)
 
+DEBUG_FILES = {
+    '_ctypes_test',
+    '_testbuffer',
+    '_testcapi',
+    '_testimportmultiple',
+    '_testmultiphase',
+    'xxlimited',
+    'python3_dstub',
+}
+
 EXCLUDE_FROM_LIBRARY = {
     '__pycache__',
     'ensurepip',
@@ -25,12 +35,19 @@ EXCLUDE_FROM_LIBRARY = {
     'site-packages',
     'tkinter',
     'turtledemo',
+    'venv',
 }
 
 EXCLUDE_FILE_FROM_LIBRARY = {
     'bdist_wininst.py',
 }
 
+EXCLUDE_FILE_FROM_LIBS = {
+    'ssleay',
+    'libeay',
+    'python3stub',
+}
+
 def is_not_debug(p):
     if DEBUG_RE.search(p.name):
         return False
@@ -38,14 +55,7 @@ def is_not_debug(p):
     if TKTCL_RE.search(p.name):
         return False
 
-    return p.name.lower() not in {
-        '_ctypes_test.pyd',
-        '_testbuffer.pyd',
-        '_testcapi.pyd',
-        '_testimportmultiple.pyd',
-        '_testmultiphase.pyd',
-        'xxlimited.pyd',
-    }
+    return p.stem.lower() not in DEBUG_FILES
 
 def is_not_debug_or_python(p):
     return is_not_debug(p) and not PYTHON_DLL_RE.search(p.name)
@@ -69,6 +79,12 @@ def include_in_lib(p):
     suffix = p.suffix.lower()
     return suffix not in {'.pyc', '.pyo', '.exe'}
 
+def include_in_libs(p):
+    if not is_not_debug(p):
+        return False
+
+    return p.stem.lower() not in EXCLUDE_FILE_FROM_LIBS
+
 def include_in_tools(p):
     if p.is_dir() and p.name.lower() in {'scripts', 'i18n', 'pynche', 'demo', 'parser'}:
         return True
@@ -84,6 +100,7 @@ FULL_LAYOUT = [
     ('include/', 'include', '*.h', None),
     ('include/', 'PC', 'pyconfig.h', None),
     ('Lib/', 'Lib', '**/*', include_in_lib),
+    ('libs/', 'PCBuild/$arch', '*.lib', include_in_libs),
     ('Tools/', 'Tools', '**/*', include_in_tools),
 ]
 
@@ -160,7 +177,7 @@ def main():
 
     source = ns.source or (Path(__file__).resolve().parent.parent.parent)
     out = ns.out
-    arch = "" if ns.arch == "win32" else ns.arch
+    arch = '' if ns.arch == 'win32' else ns.arch
     assert isinstance(source, Path)
     assert not out or isinstance(out, Path)
     assert isinstance(arch, str)