From 837b3163d1d3a857df1e2ac1367ff3f08b744115 Mon Sep 17 00:00:00 2001 From: Matthias Vill Date: Mon, 26 Oct 2020 14:26:23 +0100 Subject: [PATCH 1/3] Replace CreateAssemblyGenerator.exe by CreateAssemblyGenerator.ps1 --- Build/Build.ssmssqlproj | 4 +- Build/CreateAssemblyGenerator.exe | Bin 8192 -> 0 bytes Build/CreateAssemblyGenerator.ps1 | 111 ++++++++++++++++++++++++++++++ Build/tSQLt.build.xml | 82 ++++++++++++++++------ 4 files changed, 175 insertions(+), 22 deletions(-) delete mode 100644 Build/CreateAssemblyGenerator.exe create mode 100644 Build/CreateAssemblyGenerator.ps1 diff --git a/Build/Build.ssmssqlproj b/Build/Build.ssmssqlproj index 00d157469..44dafa35a 100644 --- a/Build/Build.ssmssqlproj +++ b/Build/Build.ssmssqlproj @@ -131,11 +131,11 @@ ChangeSigningKey_ReadMe.txt - + - CreateAssemblyGenerator.exe + CreateAssemblyGenerator.ps1 diff --git a/Build/CreateAssemblyGenerator.exe b/Build/CreateAssemblyGenerator.exe deleted file mode 100644 index b48385a8bf9a2e26e26868325e9b1e0c612b4d82..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8192 zcmeHMYiu0Xbw2ah+11Kgo0LO6=?qtvLsRBzSCk!DmTXcaB{N=9l(?2Hn}#&Id$}BI zcV;~^OOYy4$VehLO=8$dV88-gv_hN2C=fVE(xi>sCP9DH1_C(!(FYo!w$Y+V0LMsx z1VIzn{mz}4eOOeS2LdEO?sCpOuY2yf=iIrE;p{_Ckw!#1p10p7`YLKJ;}ZU2a1r9n zd;cy&U)u1kp|2{%Zw-}}ZQpEqZq2hAX2o(GH!#b>^jeN-JLc5!1+(E+MQ+ok^v#j! z`Dvn}qR|s0+a8H~dzDmWqmn1O5u9|$eRK@9iDw)S0~3`R`VCC_&oy1d13njx#y>)I zgZ%5%5gDq`R@gnx_&CvD8WFR*I!kmN=vNCwJG=SshMPpGE}azUd%NgdAXWp=&CLLi z$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o zEr0uE{(9}bGmG!c;Q`s^owLKld)}M=_v)ZVeE8$J| za28u_))Y>~t>Tb;ID3ET=;(ngZ~jizs=JOjoLv)s_MW>pr8lJy#fN$mCLI58w&gho z{mL?~+Wu(6u6VBRE(N0%w{g(&8@ZK2)@)dgy(Ih~-i2j4Bp>~WOn@rk$p ztm)vkemFb3hEEf?_{sZR&T2NZdqWF>*YX3tR{fIx?90k_=-U^S7QR%hMKm~`c&r6K zMHLsi6?_V)3ICV0Iu=_sQ95?8nN?bR-z;VrcoVz6x5xKGd)q;P!lAu!hVJg<{14b~DFS%G@NWmIcb#{BOFjL;?C)R% F{vXvSgC+m~ diff --git a/Build/CreateAssemblyGenerator.ps1 b/Build/CreateAssemblyGenerator.ps1 new file mode 100644 index 000000000..f45fcdc9d --- /dev/null +++ b/Build/CreateAssemblyGenerator.ps1 @@ -0,0 +1,111 @@ +param([Parameter(Mandatory = $true)][string]$dllPath, + [Parameter(Mandatory = $true)][string]$templatePath, + [Parameter(Mandatory = $true)][string]$assemblyPattern, + [string]$thumbPrintPattern, + [int]$maxLength = 0, + [string]$separator = "'+$( [Environment]::NewLine )'") + +$ErrorActionPreference = 'Stop' + +class Generator +{ + static + [string] + GetHexStringFromBytes([byte[]]$dllBytes) + { + $stringBuilder = [System.Text.StringBuilder]::new('0x', $dllBytes.Length * 2 + 2) + + foreach ($dllByte in $dllBytes) + { + $stringBuilder.Append($dllByte.ToString('X2')) + } + + return $stringBuilder.ToString() + } + + static + [byte[]] + GetBytesFromDll([string]$dllPath) + { + return (Get-Content -Path $dllPath -AsByteStream -Raw) + } + + static + [string] + GetTemplateFile([string]$templatePath) + { + return (Get-Content -Path $templatePath -Raw) + } + + static + [string] + GetTemplate([string]$templatePath, + [string]$assemblyPattern, + [string]$thumbPrintPattern) + { + $template = [Generator]::GetTemplateFile($templatePath) + if ($template -notmatch $assemblyPattern) + { + throw "The specified template file [" + $templatePath + "] did not contain the specified assembly pattern [" + $assemblyPattern + "]!" + } + + if (![string]::IsNullOrEmpty($thumbPrintPattern) -and $template -notmatch $thumbPrintPattern) + { + throw "The specified template file [" + $templatePath + "] did not contain the specified thumbprint pattern [" + $thumbPrintPattern + "]!" + } + return $template + } + + static + [byte[]] + GetAssemblyBytes([string]$dllPath) + { + $bytesFromDll = [Generator]::GetBytesFromDll($dllPath) + if ($bytesFromDll.Length -eq 0) + { + throw "The DLL specified [" + $dllPath + "] for generating the CREATE ASSEMBLY statement was empty" + } + return $bytesFromDll + } + + static + [string] + Wrap([string]$hexString, + [int] $maxLength, + [string] $separator) + { + if ($maxLength -le 0 -or $hexString.Length -le $maxLength) + { + return $hexString + } + + $separator = $separator -replace '\\n', [Environment]::NewLine + $stringBuilder = [System.Text.StringBuilder]::new($hexString.Length + [int][Math]::Floor($hexString.Length / $maxLength) * $separator.Length) + + $stringBuilder.Append($hexString, 0, $maxLength); + for ($i = $maxLength; $i -lt $hexString.Length; $i += $maxLength) { + $stringBuilder.Append($separator) + $stringBuilder.Append($hexString, $i,[Math]::Min($maxLength, $hexString.Length - $i)) + } + + return $stringBuilder.ToString() + } +} + +$template = [Generator]::GetTemplate($templatePath, $assemblyPattern, $thumbPrintPattern) +$assemblyBytes = [Generator]::GetAssemblyBytes($dllPath) + +if (![string]::IsNullOrEmpty($thumbPrintPattern)) +{ + $thumbPrint = [Generator]::GetHexStringFromBytes([System.Reflection.Assembly]::Load($assemblyBytes).GetName().GetPublicKeyToken()) + $template = $template -replace $thumbPrintPattern, $thumbPrint +} + +if (![string]::IsNullOrEmpty($assemblyPattern)) +{ + $hexString = [Generator]::GetHexStringFromBytes($assemblyBytes) + $assembly = [Generator]::Wrap($hexString, $maxLength, $separator) + $template = $template -replace $assemblyPattern, $assembly +} + +Write-Host $template diff --git a/Build/tSQLt.build.xml b/Build/tSQLt.build.xml index 0b3046c09..c45c3bb83 100644 --- a/Build/tSQLt.build.xml +++ b/Build/tSQLt.build.xml @@ -112,24 +112,50 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + @@ -291,15 +317,31 @@ - - - + + + + + + + + + + + - - - + + + + + + + + + + + From 91980cd5679c577b53184767a61ade5f5faaf18b Mon Sep 17 00:00:00 2001 From: Matthias Vill Date: Mon, 26 Oct 2020 15:51:08 +0100 Subject: [PATCH 2/3] Indent outputted scripts for better readability --- Build/tSQLt.build.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Build/tSQLt.build.xml b/Build/tSQLt.build.xml index c45c3bb83..2988e0f11 100644 --- a/Build/tSQLt.build.xml +++ b/Build/tSQLt.build.xml @@ -132,6 +132,9 @@ + + + @@ -155,6 +158,9 @@ + + + From 56aea07251c19e09a53a1da453b6648c9c82319c Mon Sep 17 00:00:00 2001 From: Matthias Vill Date: Sun, 1 Nov 2020 15:15:35 +0100 Subject: [PATCH 3/3] Use powershell instead of pwsh on windows (should be preinstalled since Windows 7) --- Build/tSQLt.build.xml | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Build/tSQLt.build.xml b/Build/tSQLt.build.xml index 2988e0f11..0ba00acc5 100644 --- a/Build/tSQLt.build.xml +++ b/Build/tSQLt.build.xml @@ -2,8 +2,20 @@ Build tSQLt + + + + - + + + + + + + + + - + @@ -138,7 +150,7 @@ - + @@ -323,7 +335,7 @@ - + @@ -337,7 +349,7 @@ - +