From 563f20279ea55e98a9830987c482564ad4cb7d70 Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Wed, 15 Jul 2020 08:43:51 +0900 Subject: [PATCH] Add support for development with VC16(Visual Studio 2019). MSToolsVersion parameter of BuildAll.ps1 and of regress.ps1 are deprecated. --- winbuild/BuildAll.ps1 | 22 +++-- winbuild/MSProgram-Get.psm1 | 148 ++++++++++++++++++++++----------- winbuild/pgenlist.vcxproj | 2 +- winbuild/pgxalib.vcxproj | 2 +- winbuild/platformbuild.vcxproj | 7 +- winbuild/psqlodbc.vcxproj | 2 +- winbuild/psqlsetup.vcxproj | 2 +- winbuild/regress.ps1 | 14 ++-- winbuild/regress_one.vcxproj | 2 +- 9 files changed, 130 insertions(+), 71 deletions(-) diff --git a/winbuild/BuildAll.ps1 b/winbuild/BuildAll.ps1 index fd27ddb..3deed98 100755 --- a/winbuild/BuildAll.ps1 +++ b/winbuild/BuildAll.ps1 @@ -17,11 +17,13 @@ Specify when you'd like to build installers after building drivers. .PARAMETER Toolset MSBuild PlatformToolset is determined automatically unless this - option is specified. Currently "v100", "Windows7.1SDK", "v110", - "v110_xp", "v120", "v120_xp", "v140" or "v140_xp" is available. + option is specified. Currently "v90", "v100", "Windows7.1SDK", + "v110", "v110_xp", "v120", "v120_xp", "v140" , "v140_xp", "v141", + "v141_xp" or "v142" is available. .PARAMETER MSToolsVersion - MSBuild ToolsVersion is detemrined automatically unless this - option is specified. Currently "4.0", "12.0" or "14.0" is available. + This option is deprecated. MSBuild ToolsVersion is detemrined + automatically unless this option is specified. Currently "4.0", + "12.0" or "14.0" is available. .PARAMETER Configuration Specify "Release"(default) or "Debug". .PARAMETER BuildConfigPath @@ -58,7 +60,7 @@ Param( [ValidateSet("Win32", "x64", "both")] [string]$Platform="both", [string]$Toolset, -[ValidateSet("", "4.0", "12.0", "14.0", "15.0")] +[ValidateSet("", "4.0", "12.0", "14.0")] [string]$MSToolsVersion, [ValidateSet("Debug", "Release")] [String]$Configuration="Release", @@ -98,7 +100,7 @@ function buildPlatform([xml]$configInfo, [string]$Platform) $BUILD_MACROS = $BUILD_MACROS -replace '"', '`"' $macroList = iex "write-output $BUILD_MACROS" } - & ${msbuildexe} ./platformbuild.vcxproj /tv:$MSToolsVersion "/p:Platform=$Platform;Configuration=$Configuration;PlatformToolset=${Toolset}" /t:$target /p:VisualStudioVersion=${VCVersion} /p:DRIVERVERSION=$DRIVERVERSION /p:PG_INC=$PG_INC /p:PG_LIB=$PG_LIB /p:PG_BIN=$PG_BIN $macroList + & ${msbuildexe} ./platformbuild.vcxproj /tv:$MSToolsV "/p:Platform=$Platform;Configuration=$Configuration;PlatformToolset=${Toolset}" /t:$target /p:VisualStudioVersion=${VCVersion} /p:DRIVERVERSION=$DRIVERVERSION /p:PG_INC=$PG_INC /p:PG_LIB=$PG_LIB /p:PG_BIN=$PG_BIN $macroList } $scriptPath = (Split-Path $MyInvocation.MyCommand.Path) @@ -110,7 +112,9 @@ $path_save = ${env:PATH} Import-Module ${scriptPath}\MSProgram-Get.psm1 try { - $msbuildexe=Find-MSBuild ([ref]$VCVersion) ([ref]$MSToolsVersion) ([ref]$Toolset) $configInfo + $rtnArray=Find-MSBuild ([ref]$VCVersion) ($MSToolsVersion) ([ref]$Toolset) $configInfo + $msbuildexe=$rtnArray[0] + $MSToolsV=$rtnArray[1] } catch [Exception] { if ("$_.Exception.Message" -ne "") { Write-Host $_.Exception.Message -ForegroundColor Red @@ -161,14 +165,14 @@ try { $configInfo.Configuration.BuildResult.Date=[string](Get-Date) $configInfo.Configuration.BuildResult.VisualStudioVersion=$VCVersion $configInfo.Configuration.BuildResult.PlatformToolset=$Toolset - $configInfo.Configuration.BuildResult.ToolsVersion=$MSToolsVersion + $configInfo.Configuration.BuildResult.ToolsVersion=$MSToolsV $configInfo.Configuration.BuildResult.Platform=$Platform } } else { $resultText="failed" } SaveConfiguration $configInfo - Write-Host "ToolsVersion=$MSToolsVersion VisualStudioVersion=$VCVersion PlatformToolset=$Toolset Platform=$Platform $resultText`n" + Write-Host "VisualStudioVersion=$VCVersion(ToolsVersion=$MSToolsV) PlatformToolset=$Toolset Platform=$Platform $resultText`n" # # build installers as well # diff --git a/winbuild/MSProgram-Get.psm1 b/winbuild/MSProgram-Get.psm1 index 3b4839c..4e9711d 100644 --- a/winbuild/MSProgram-Get.psm1 +++ b/winbuild/MSProgram-Get.psm1 @@ -6,7 +6,7 @@ function Find-MSBuild Param([Parameter(Mandatory=$true)] [ref]$VCVersion, [Parameter(Mandatory=$true)] - [ref]$MSToolsVersion, + $MSToolsVersion, [Parameter(Mandatory=$true)] [ref]$Toolset, [Parameter(Mandatory=$true)] @@ -14,12 +14,11 @@ function Find-MSBuild $msbuildexe="" $VisualStudioVersion=$VCVersion.Value - $MSToolsVersionv=$MSToolsVersion.Value $Toolsetv=$Toolset.Value $WSDK71Set="Windows7.1SDK" - $refnum="" Write-Debug "VCVersion=$VCVersionv $env:VisualStudioVersion" + [int]$toolsnum=0 # # Determine VisualStudioVersion # @@ -38,10 +37,13 @@ function Find-MSBuild } } } + $refnum="" # neither C++ nor SDK prompt if ("$VisualStudioVersion" -eq "") { if ((Find-VSDir 15) -ne "") { # VC15 is installed (current official) $VisualStudioVersion = "15.0" + } elseif ((Find-VSDir 16) -ne "") { # VC16 is installed + $VisualStudioVersion = "16.0" } elseif ("${env:VS140COMNTOOLS}" -ne "") { # VC14 is installed $VisualStudioVersion = "14.0" } elseif ("${env:VS120COMNTOOLS}" -ne "") { # VC12 is installed @@ -53,43 +55,45 @@ function Find-MSBuild } else { throw "Visual Studio >= 10.0 not found" } - } elseif ([int]::TryParse($VisualStudioVersion, [ref]$refnum)) { + } + if ([int]::TryParse($VisualStudioVersion, [ref]$refnum)) { $VisualStudioVersion="${refnum}.0" } # Check VisualStudioVersion and prepare for ToolsVersion switch ($VisualStudioVersion) { - "10.0" { $tv = "4.0" } - "11.0" { $tv = "4.0" } - "12.0" { $tv = "12.0" } - "14.0" { $tv = "14.0" } - "15.0" { $tv = "15.0" } + "10.0" { $toolsout = 4 } + "11.0" { $toolsout = 4 } + "12.0" { $toolsout = 12 } + "14.0" { $toolsout = 14 } + "15.0" { $toolsout = 15 } + "16.0" { $toolsout = 16 } default { throw "Selected Visual Stuidio is Version ${VisualStudioVersion}. Please use VC10 or later"} } # # Determine ToolsVersion # - if ("$MSToolsVersionv" -eq "") { - $MSToolsVersionv=$env:ToolsVersion - } - if ("$MSToolsVersionv" -eq "") { - $MSToolsVersionv = $tv - [int]::TryParse($MSToolsVersionv, [ref]$refnum) | Out-Null - if ("$MSToolsVersionv" -match "^(\d+)") { - $refnum = $matches[1] + [int]$toolsnum=$toolsout + if ("$MSToolsVersion" -eq "") { + $MSToolsVersion=$env:ToolsVersion + } + if ("$MSToolsVersion" -ne "") { + if ([int]::TryParse($MSToolsVersion, [ref]$refnum)) { + $toolsout=[int]$refnum } - } elseif ([int]::TryParse($MSToolsVersionv, [ref]$refnum)) { - $MSToolsVersionv="${refnum}.0" + } + if ($toolsnum -lt 12) { + $toolsnum=$toolsout } # # Determine MSBuild executable # - Write-Debug "ToolsVersion=$MSToolsVersionv VisualStudioVersion=$VisualStudioVersion" + Write-Debug "ToolsVersion=$MSToolsVersion VisualStudioVersion=$VisualStudioVersion" try { $msbver = msbuild.exe /ver /nologo if ("$msbver" -match "^(\d+)\.(\d+)") { $major1 = [int] $matches[1] $minor1 = [int] $matches[2] - if ($MSToolsVersionv -match "^(\d+)\.(\d+)") { + if ($MSToolsVersion -match "^(\d+)\.(\d+)") { $bavail = $false $major2 = [int] $matches[1] $minor2 = [int] $matches[2] @@ -108,18 +112,18 @@ function Find-MSBuild } } catch {} if ("$msbuildexe" -eq "") { - if ([int]$refnum -gt 14) { # VC15 ~ VC?? - $msbuildexe = msbfind_15_xx $MSToolsVersionv + if ($toolsnum -gt 14) { # VC15 ~ VC16 + $msbuildexe = msbfind_15_xx $toolsnum } else { # VC10 ~ VC14 - $msbuildexe = msbfind_10_14 $MSToolsVersionv - if ($refnum -eq 4) { + $msbuildexe = msbfind_10_14 "${toolsnum}.0" + if ($toolsnum -eq 4) { if ((Find-VSDir $VisualStudioVersion) -eq "") { - throw "MSBuild VisualStudioVersion $VisualStudioVersion not Found" + throw "MSBuild ${toolsnum}.0 found but VisualStudioVersion $VisualStudioVersion not Found" } } } if ("$msbuildexe" -eq "") { - throw "MSBuild ToolsVersion $MSToolsVersionv not Found" + throw "MSBuild ToolsVersion ${toolsnum}.0 not Found" } } # @@ -144,6 +148,7 @@ function Find-MSBuild "12.0" {$Toolsetv="v120_xp"} "14.0" {$Toolsetv="v140_xp"} "15.0" {$Toolsetv="v141_xp"} + "16.0" {$Toolsetv="v142"} } } # avoid a bug of Windows7.1SDK PlatformToolset @@ -152,10 +157,16 @@ function Find-MSBuild } # $VCVersion.value=$VisualStudioVersion - $MSToolsVersion.value=$MSToolsVersionv $Toolset.value=$Toolsetv - return $msbuildexe + if ("$MSToolsVersion" -eq "") { + if ([int]$toolsout -gt 15) { + $MSToolsVersion="Current" + } else { + $MSToolsVersion="${toolsout}.0" + } + } + return $msbuildexe, $MSToolsVersion } # find msbuild.exe for VC10 ~ VC14 @@ -187,7 +198,7 @@ function msbfind_10_14 return "${msbindir}msbuild" } -# find msbuild.exe for VC15 ~ VC?? +# find msbuild.exe for VC15 ~ VC16 function msbfind_15_xx { [CmdletBinding()] @@ -195,11 +206,10 @@ function msbfind_15_xx Param([Parameter(Mandatory=$true)] [string]$toolsver) - $vsdir = Find-VSDir $toolsver - if ("$vsdir" -eq "") { - return "" - } - return "${vsdir}MSBuild\$toolsver\Bin\MSBuild.exe" +# via vssetup module + $vsdir = find_vs_installation $toolsver +# vssetup module is unavailable + return find_default_msbuild_path $toolsver $vsdir } $dumpbinexe = "" @@ -209,7 +219,7 @@ function Find-Dumpbin { [CmdletBinding()] - Param([int]$CurMaxVC = 15) + Param([int]$CurMaxVC = 16) if ("$dumpbinexe" -ne "") { if ("$addPath" -ne "") { @@ -228,7 +238,7 @@ function Find-Dumpbin # $dumpbinexe="$env:DUMPBINEXE" if ($dumpbinexe -eq "") { $searching = $true - for ($i = $CurMaxVc; $searching -and ($i -ge 14); $i--) # VC15 ~ VC?? + for ($i = $CurMaxVc; $searching -and ($i -ge 14); $i--) # VC15 ~ VC16 { $vsdir = Find-VSDir $i if ("$vsdir" -ne "") { @@ -350,7 +360,7 @@ function Find-VSDir if ((env_vcversion_no) -eq $vcversion_no) { return $env:VSINSTALLDIR } - if ($vcversion_no -gt 14) { # VC15 ~ VC?? + if ($vcversion_no -gt 14) { # VC15 ~ VC16 return find_vsdir_15_xx ${vcversion_no} } else { # VC10 ~ VC14 $comntools = [environment]::getenvironmentvariable("VS${vcversion_no}0COMNTOOLS") @@ -363,15 +373,15 @@ function Find-VSDir [bool]$vssetup_available = $true $vssetup = $null - -# find VS dir for VC15 ~ VC?? -function find_vsdir_15_xx +# find vs installation path for VC15 ~ VC16 +function find_vs_installation { [CmdletBinding()] Param([Parameter(Mandatory=$true)] [string]$toolsver) + $vsdir = "" # vssetup module is available? if ($vssetup_available -and ($vsseup -eq $null)) { try { @@ -384,19 +394,59 @@ function find_vsdir_15_xx if ($vssetup -ne $null) { $lslist = @($vssetup | where-object { $_.InstallationVersion.Major -eq $toolsnum } | foreach-object { $_.InstallationPath }) if ($lslist.Count -gt 0) { - return $lslist[0] + "\" + $vsdir = $lslist[0] } - return "" } -# vssetup module is unavailable - if ($env:PROCESSOR_ARCHITECTURE -eq "x86") { - $pgmfs = "$env:ProgramFiles" + return $vsdir +} + +$vsarray = @{VC15 = "2017"; VC16 = "2019"} +# find VS dir for VC15 ~ VC16 +function find_default_msbuild_path +{ + [CmdletBinding()] + + Param([Parameter(Mandatory=$true)] + [string]$toolsver, + [string]$vsdir) + + if ($vsdir -eq "") + { + $toolsnum = [int]$toolsver + if ($env:PROCESSOR_ARCHITECTURE -eq "x86") { + $pgmfs = "$env:ProgramFiles" + } else { + $pgmfs = "${env:ProgramFiles(x86)}" + } + $vsverdir = $vsarray["VC$toolsnum"] + $lslist = @(Get-ChildItem "$pgmfs\Microsoft Visual Studio\$vsverdir\*\MSBuild\*\Bin\MSBuild.exe" -ErrorAction SilentlyContinue) } else { - $pgmfs = "${env:ProgramFiles(x86)}" + $lslist = @(Get-ChildItem "$vsdir\MSBuild\*\Bin\MSBuild.exe" -ErrorAction SilentlyContinue) } - $lslist = @(Get-ChildItem "$pgmfs\Microsoft Visual Studio\*\*\MSBuild\$toolsnum.0\Bin\MSBuild.exe" -ErrorAction SilentlyContinue) if ($lslist.Count -gt 0) { - return (Split-Path (Split-Path (Split-Path (Split-Path $lslist[0].FullName -Parent) -Parent) -Parent) -Parent) + "\" + return $lslist[0].FullName + } + + return "" +} + +# find VS dir for VC15 ~ VC16 +function find_vsdir_15_xx +{ + [CmdletBinding()] + + Param([Parameter(Mandatory=$true)] + [string]$toolsver) + +# via vssetup module + $vsdir = find_vs_installation $toolsver + if ($vsdir -ne "") { + return $vsdir + } +# vssetup module is unavailable + $msbpath = find_default_msbuild_path $toolsver $vsdir + if ($msbpath -ne "") { + return (Split-Path (Split-Path (Split-Path (Split-Path $msbpath -Parent) -Parent) -Parent) -Parent) + "\" } return "" diff --git a/winbuild/pgenlist.vcxproj b/winbuild/pgenlist.vcxproj index 8561c5b..4bca4fd 100755 --- a/winbuild/pgenlist.vcxproj +++ b/winbuild/pgenlist.vcxproj @@ -1,5 +1,5 @@ - + Debug diff --git a/winbuild/pgxalib.vcxproj b/winbuild/pgxalib.vcxproj index e59e571..f1a1675 100755 --- a/winbuild/pgxalib.vcxproj +++ b/winbuild/pgxalib.vcxproj @@ -1,5 +1,5 @@ - + Debug diff --git a/winbuild/platformbuild.vcxproj b/winbuild/platformbuild.vcxproj index 1009049..e08aadc 100755 --- a/winbuild/platformbuild.vcxproj +++ b/winbuild/platformbuild.vcxproj @@ -28,6 +28,9 @@ + @@ -52,8 +55,8 @@ Properties="Configuration=$(Configuration);srcPath=$(srcPath)"/> + Text="PG_BIN isn't set%0D%0ACouldn't build psqlsetup." + Condition="'($PG_BIN)'==''"/> diff --git a/winbuild/psqlodbc.vcxproj b/winbuild/psqlodbc.vcxproj index b1770a3..5d1d9e8 100755 --- a/winbuild/psqlodbc.vcxproj +++ b/winbuild/psqlodbc.vcxproj @@ -1,5 +1,5 @@ - + Debug diff --git a/winbuild/psqlsetup.vcxproj b/winbuild/psqlsetup.vcxproj index bfdcc2b..8ff6cb4 100644 --- a/winbuild/psqlsetup.vcxproj +++ b/winbuild/psqlsetup.vcxproj @@ -1,5 +1,5 @@ - + Debug diff --git a/winbuild/regress.ps1 b/winbuild/regress.ps1 index 7a34a4a..b5e1f85 100644 --- a/winbuild/regress.ps1 +++ b/winbuild/regress.ps1 @@ -23,9 +23,9 @@ option is specified. Currently "v100", "Windows7.1SDK", "v110", "v110_xp", "v120", "v120_xp", "v140" or "v140_xp" is available. .PARAMETER MSToolsVersion - MSBuild ToolsVersion is detemrined automatically unless this - option is specified. Currently "4.0", "12.0", "14.0" or "15.0" is - available. + This option is deprecated. MSBuild ToolsVersion is detemrined + automatically unless this option is specified. Currently "4.0", + "12.0" or "14.0" is available. .PARAMETER Configuration Specify "Release"(default) or "Debug". .PARAMETER BuildConfigPath @@ -70,7 +70,7 @@ Param( [ValidateSet("Win32", "x64", "both")] [string]$Platform="both", [string]$Toolset, -[ValidateSet("", "4.0", "12.0", "14.0", "15.0")] +[ValidateSet("", "4.0", "12.0", "14.0")] [string]$MSToolsVersion, [ValidateSet("Debug", "Release")] [String]$Configuration="Release", @@ -339,7 +339,9 @@ $objbase = GetObjbase "$scriptPath\.." $pushdir = GetObjbase "$scriptPath" Import-Module ${scriptPath}\MSProgram-Get.psm1 -$msbuildexe=Find-MSBuild ([ref]$VCVersion) ([ref]$MSToolsVersion) ([ref]$Toolset) $configInfo +$rtnArray=Find-MSBuild ([ref]$VCVersion) ($MSToolsVersion) ([ref]$Toolset) $configInfo +$msbuildexe=$rtnArray[0] +$MSToolsV=$rtnArray[1] write-host "vcversion=$VCVersion toolset=$Toolset" Remove-Module MSProgram-Get @@ -379,7 +381,7 @@ if ("$SpecificDsn" -ne "") { } foreach ($pl in $pary) { cd $scriptPath - & ${msbuildexe} ${vcxfile} /tv:$MSToolsVersion "/p:Platform=$pl;Configuration=$Configuration;PlatformToolset=${Toolset}" /t:$vcx_target /p:VisualStudioVersion=${VCVersion} /p:scriptPath=${scriptPath} /Verbosity:minimal + & ${msbuildexe} ${vcxfile} /tv:$MSToolsV "/p:Platform=$pl;Configuration=$Configuration;PlatformToolset=${Toolset}" /t:$vcx_target /p:VisualStudioVersion=${VCVersion} /p:scriptPath=${scriptPath} /Verbosity:minimal if ($LASTEXITCODE -ne 0) { throw "`nCompile error" } diff --git a/winbuild/regress_one.vcxproj b/winbuild/regress_one.vcxproj index 4660f40..df5f436 100755 --- a/winbuild/regress_one.vcxproj +++ b/winbuild/regress_one.vcxproj @@ -1,5 +1,5 @@ - + Debug -- 2.39.5