[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [win-pv-devel] [PATCH 1/2] Add PowerShell build scripts



> -----Original Message-----
> From: win-pv-devel [mailto:win-pv-devel-bounces@xxxxxxxxxxxxxxxxxxxx] On 
> Behalf Of Owen Smith
> Sent: 04 April 2019 16:11
> To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
> Cc: Owen Smith <owen.smith@xxxxxxxxxx>
> Subject: [win-pv-devel] [PATCH 1/2] Add PowerShell build scripts
> 
> * genfiles.ps1
>   Generate include/version.h and vs2017/xenbus.inf
>   This is intended to become a PreBuild step in the vcxproj
> * build.ps1
>   Wraps running MSBuild for x86/x64
>   This is intended to become the entry point to build
> * package.ps1
>   Coalesce the output from x86 and x64 package.vcxproj and generate the
>   resultant output zip file
>   This can be run directly from the build.ps1 script if required
> * symstore.ps1
>   Store symbols from build output on symbol server
> 
> Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
> ---
>  build.ps1           | 103 ++++++++++++++++++++++++++++++++++++++++++++++
>  genfiles.ps1        | 116 
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  include/version._h_ |  22 ++++++++++
>  package.ps1         |  69 +++++++++++++++++++++++++++++++
>  src/xenbus.inf      |   2 +-
>  symstore.ps1        |  45 ++++++++++++++++++++
>  6 files changed, 356 insertions(+), 1 deletion(-)
>  create mode 100644 build.ps1
>  create mode 100644 genfiles.ps1
>  create mode 100644 include/version._h_
>  create mode 100644 package.ps1
>  create mode 100644 symstore.ps1
> 
> diff --git a/build.ps1 b/build.ps1
> new file mode 100644
> index 0000000..a18292d
> --- /dev/null
> +++ b/build.ps1
> @@ -0,0 +1,103 @@
> +#
> +# Wrapper script for MSBuild
> +# Also creates the final package(s) (if specified) and bumps the build number
> +#
> +param(
> +     [string]$SolutionDir = "vs2017",
> +     [string]$DriverName = "xenbus",
> +     [string]$ConfigurationBase = "Windows 10",
> +     [switch]$Free,
> +     [switch]$Checked,
> +     [switch]$Sdv,
> +     [switch]$Package,
> +     [switch]$DontBumpBuild
> +)
> +
> +Function Run-MSBuild {
> +     param(
> +             [string]$SolutionDir,
> +             [string]$SolutionName,
> +             [string]$Configuration,
> +             [string]$Platform,
> +             [string]$Target = "Build",
> +             [string]$Inputs = ""
> +     )
> +
> +     $c=[string]::Format("/p:Configuration=`"{0}`"", $Configuration)
> +     $p=[string]::Format("/p:Platform=`"{0}`"", $Platform)
> +     $t=[string]::Format("/t:`"{0}`"", $Target)
> +     $s=[string]::Format("{0}\{1}", $SolutionDir, $SolutionName)
> +     if ($Inputs) {
> +             $i=[string]::Format("/p:Inputs=`"{0}`"", $Inputs)

I'm no powershell expert so I could be wrong but it appears that you could set 
$i to an empty string in the case where $Inputs is empty and then unify the if 
and else below. This is assuming that, because $i is not quoted, an empty 
string evaluation will simply be ignored.

Everything looks fine though, even without this potential small optimization, 
so...

Reviewed-by: Paul Durrant <paul.durrant@xxxxxxxxxx>

> +             Write-Host "msbuild.exe" "/m:1" $c $p $t $i $s
> +             & "msbuild.exe" "/m:1" $c $p $t $s $i
> +     } else {
> +             Write-Host "msbuild.exe" "/m:1" $c $p $t $s
> +             & "msbuild.exe" "/m:1" $c $p $t $s
> +     }
> +}
> +
> +Function Run-MSBuildSDV {
> +     param(
> +             [string]$SolutionDir,
> +             [string]$ProjectName
> +     )
> +
> +     $basepath = Get-Location
> +     $projpath = Join-Path -Path $SolutionDir -ChildPath $ProjectName
> +     Set-Location $projpath
> +
> +     $project = [string]::Format("{0}.vcxproj", $ProjectName)
> +     Run-MSBuild $projpath $project "Windows 10 Release" "x64" "Build"
> +     Run-MSBuild $projpath $project "Windows 10 Release" "x64" "sdv" "/clean"
> +     Run-MSBuild $projpath $project "Windows 10 Release" "x64" "sdv" 
> "/check:default.sdv /debug"
> +     Run-MSBuild $projpath $project "Windows 10 Release" "x64" "dvl"
> +
> +     $refine = Join-Path -Path $projpath -ChildPath "refine.sdv"
> +     if (Test-Path -Path $refine -PathType Leaf) {
> +             Run-MSBuild $projpath $project "Windows 10 Release" "x64" "sdv" 
> "/refine"
> +     }
> +
> +     Set-Location $basepath
> +}
> +
> +#
> +# Script Body
> +#
> +
> +$configuration = @{ "free"="$ConfigurationBase Release"; 
> "checked"="$ConfigurationBase Debug" }
> +$solutionname = [string]::Format("{0}.sln", $DriverName)
> +$solutiondir = Resolve-Path $SolutionDir
> +
> +if ($Free -or -not ($Sdv -or $Checked)) {
> +     Run-MSBuild $solutiondir $solutionname $configuration["free"] "x64"
> +     Run-MSBuild $solutiondir $solutionname $configuration["free"] "Win32"
> +}
> +if ($Checked) {
> +     Run-MSBuild $solutiondir $solutionname $configuration["checked"] "x64"
> +     Run-MSBuild $solutiondir $solutionname $configuration["checked"] "Win32"
> +}
> +if ($Sdv) {
> +     Run-MSBuildSDV $solutiondir "xen"
> +     Run-MSBuildSDV $solutiondir "xenfilt"
> +     Run-MSBuildSDV $solutiondir "xenbus"
> +}
> +if ($Package) {
> +     $config=$ConfigurationBase.Replace(' ', '')
> +     $params = @{
> +             SolutionDir=$SolutionDir;
> +             DriverName=$DriverName;
> +             ConfigurationBase=$config;
> +             Free=$Free;
> +             Checked=$Checked
> +     }
> +     & ".\package.ps1" @params
> +}
> +if (-not $DontBumpBuild) {
> +     if (Test-Path ".build_number") {
> +             $TheBuildNum = Get-Content -Path ".build_number"
> +             Set-Content -Path ".build_number" -Value ([int]$TheBuildNum + 1)
> +     } else {
> +             Set-Content -Path ".build_number" -Value "1"
> +     }
> +}
> diff --git a/genfiles.ps1 b/genfiles.ps1
> new file mode 100644
> index 0000000..ddab96e
> --- /dev/null
> +++ b/genfiles.ps1
> @@ -0,0 +1,116 @@
> +#
> +# Generate version.h and xenbus.inf
> +#
> +param(
> +     [string]$SolutionDir = "vs2017",
> +     [string]$DriverName = "xenbus",
> +     [string]$ConfigFile = $null
> +)
> +
> +# Copy $InFileName -> $OutFileName replacing $Token$_.Key$Token with 
> $_.Value from
> +# either $ConfigFile or $Replacements
> +Function Copy-FileWithReplacements {
> +     param(
> +             [Parameter(Mandatory=$true)]
> +             [string]$InFileName,
> +             [Parameter(Mandatory=$true)]
> +             [string]$OutFileName,
> +             [string]$ConfigFile,
> +             [hashtable]$Replacements,
> +             [string]$Token = "@"
> +     )
> +
> +     Write-Host "Copy-FileWithReplacements"
> +     Write-Host $InFileName" -> "$OutFileName
> +
> +     if ($ConfigFile) {
> +             $List = Get-Content $ConfigFile | Out-String | iex
> +             $List | Out-String | Write-Host
> +     } elseif ($Replacements) {
> +             $List = $Replacements
> +     } else {
> +             Write-Host "Invalid Arguments, ConfigFile or Replacements must 
> be set"
> +             Write-Host
> +             Exit -1
> +     }
> +
> +     (Get-Content $InFileName) |
> +     ForEach-Object {
> +             $line = $_
> +             $List.GetEnumerator() | ForEach-Object {
> +                     $key=[string]::Format("{0}{1}{2}", $Token, $_.Name, 
> $Token)
> +                     if (([string]::IsNullOrEmpty($_.Value)) -and 
> ($line.Contains($key))) {
> +                             Write-Host "Skipping Line Containing " $_.Name
> +                             $line = $null
> +                     }
> +                     $line = $line -replace $key, $_.Value
> +             }
> +             $line
> +     } |
> +     Set-Content $OutFileName
> +}
> +
> +#
> +# Script Body
> +#
> +
> +$TheDate = Get-Date -UFormat "%m/%d/%Y"
> +$TheYear = (Get-Date -date $TheDate).Year
> +$TheMonth = (Get-Date -date $TheDate).Month
> +$TheDay = (Get-Date -date $TheDate).Day
> +
> +# if GitRevision is $null, GIT_REVISION will be excluded from the 
> Copy-FileWithReplacements
> +$GitRevision = & "git.exe" "rev-list" "--max-count=1" "HEAD"
> +if ($GitRevision) {
> +     Set-Content -Path ".revision" -Value $GitRevision
> +}
> +
> +# if ".build_number" doesnt exist, BUILD_NUMBER = 0
> +# since this can called by the vcxproj, do not autoincrement the build number
> +# as this will mean x64 and Win32 builds have different numbers!
> +if (Test-Path ".build_number") {
> +     $TheBuildNum = Get-Content -Path ".build_number"
> +} else {
> +     Set-Content -Path ".build_number" -Value "0"
> +}
> +if (-not $TheBuildNum) {
> +     $TheBuildNum = '0'
> +}
> +
> +# [ordered] makes output easier to parse by humans
> +$Replacements = [ordered]@{
> +     # default parameters, may be overridden in config.ps1
> +     'VENDOR_NAME'='Xen Project';
> +     'PRODUCT_NAME'='Xen';
> +     'VENDOR_DEVICE_ID'=$null; # must define this replacement, or 
> @VENDOR_DEVICE_ID@ will remain in
> OutFileName
> +     'VENDOR_PREFIX'='XP';
> +
> +     'MAJOR_VERSION'='9';
> +     'MINOR_VERSION'='0';
> +     'MICRO_VERSION'='0';
> +
> +     # generated values (should not be in config.ps1)
> +     'BUILD_NUMBER'=$TheBuildNum;
> +     'GIT_REVISION'= $GitRevision;
> +
> +     'INF_DATE'=$TheDate;
> +     'YEAR'=$TheYear;
> +     'MONTH'=$TheMonth;
> +     'DAY'=$TheDay
> +}
> +
> +if ($ConfigFile -and (Test-Path -Path $ConfigFile)) {
> +     $config = Resolve-Path $ConfigFile | Get-Content | Out-String | iex
> +     $config.GetEnumerator() | % { $Replacements[$_.Key] = $_.Value }
> +}
> +
> +$Replacements | Out-String | Write-Host
> +
> +$src = "./include/version._h_"
> +$dst = "./include/version.h"
> +Copy-FileWithReplacements $src $dst -Replacements $Replacements
> +
> +$src = [string]::Format("./src/{0}.inf", $DriverName)
> +$dst = [string]::Format("./{0}/{1}.inf", $SolutionDir, $DriverName)
> +Copy-FileWithReplacements $src $dst -Replacements $Replacements
> +
> diff --git a/include/version._h_ b/include/version._h_
> new file mode 100644
> index 0000000..b2fe640
> --- /dev/null
> +++ b/include/version._h_
> @@ -0,0 +1,22 @@
> +#define VENDOR_NAME_STR      "@VENDOR_NAME@"
> +#define PRODUCT_NAME_STR     "@PRODUCT_NAME@"
> +#define VENDOR_PREFIX_STR    "@VENDOR_PREFIX@"
> +#define VENDOR_DEVICE_ID_STR "@VENDOR_DEVICE_ID@"
> +
> +#define MAJOR_VERSION_STR    "@MAJOR_VERSION@"
> +#define MINOR_VERSION_STR    "@MINOR_VERSION@"
> +#define MICRO_VERSION_STR    "@MICRO_VERSION@"
> +#define BUILD_NUMBER_STR     "@BUILD_NUMBER@"
> +
> +#define YEAR_STR             "@YEAR@"
> +#define MONTH_STR            "@MONTH@"
> +#define DAY_STR              "@DAY@"
> +
> +#define MAJOR_VERSION        @MAJOR_VERSION@
> +#define MINOR_VERSION        @MINOR_VERSION@
> +#define MICRO_VERSION        @MICRO_VERSION@
> +#define BUILD_NUMBER         @BUILD_NUMBER@
> +
> +#define YEAR                 @YEAR@
> +#define MONTH                @MONTH@
> +#define DAY                  @DAY@
> \ No newline at end of file
> diff --git a/package.ps1 b/package.ps1
> new file mode 100644
> index 0000000..5db6bf6
> --- /dev/null
> +++ b/package.ps1
> @@ -0,0 +1,69 @@
> +#
> +# Package - create the output package
> +#
> +param(
> +     [string]$SolutionDir = "vs2017",
> +     [string]$DriverName = "xenbus",
> +     [string]$ConfigurationBase = "Windows10",
> +     [switch]$Free,
> +     [switch]$Checked
> +)
> +
> +Function Build-Package {
> +     param(
> +             [string]$SolutionDir,
> +             [string]$BinPath,
> +             [string]$Package
> +     )
> +
> +     $zipfile = [string]::Format("{0}.zip", $Package)
> +     $hashfile = [string]::Format("{0}.sha256", $Package)
> +     if (Test-Path -Path $zipfile) {
> +             Remove-Item -Path $zipfile -Recurse -Force
> +     }
> +     if (Test-Path -Path $hashfile) {
> +             Remove-Item -Path $hashfile -Recurse -Force
> +     }
> +     if (Test-Path -Path $Package) {
> +             Remove-Item -Path $Package -Recurse -Force
> +     }
> +     New-Item -Name $Package -ItemType Directory | Out-Null
> +
> +     $src = Join-Path -Path $BinPath -ChildPath "x64\package\*"
> +     $dst = Join-Path -Path $Package -ChildPath "x64"
> +     New-Item -Path $dst -ItemType Directory | Out-Null
> +     Copy-Item -Path $src -Destination $dst -Recurse -Force
> +
> +     $src = Join-Path -Path $BinPath -ChildPath "Win32\package\*"
> +     $dst = Join-Path -Path $Package -ChildPath "x86"
> +     New-Item -Path $dst -ItemType Directory | Out-Null
> +     Copy-Item -Path $src -Destination $dst -Recurse -Force
> +
> +     Copy-Item ".build_number" $Package
> +     Copy-Item ".revision" $Package
> +
> +     Get-ChildItem -Path $SolutionDir -Include "*.DVL.XML" -File -Recurse | 
> Copy-Item -Destination
> $Package
> +
> +     Compress-Archive -Path $Package -DestinationPath $zipfile
> +
> +     $hash = Get-FileHash -Path $zipfile -Algorithm SHA256
> +     $hash.Hash | Set-Content $hashfile
> +
> +     Format-List -InputObject $hash
> +}
> +
> +#
> +# Script Body
> +#
> +
> +if ($Free -or -not $Checked) {
> +     $config=[string]::Format("{0}Release", $ConfigurationBase);
> +     $binpath = Join-Path -Path $SolutionDir -ChildPath $config
> +     Build-Package $SolutionDir $binpath $DriverName
> +}
> +if ($Checked) {
> +     $config=[string]::Format("{0}Debug", $ConfigurationBase);
> +     $binpath = Join-Path -Path $SolutionDir -ChildPath $config
> +     $package = [string]::Format("{0}-checked", $DriverName)
> +     Build-Package $SolutionDir $binpath $package
> +}
> diff --git a/src/xenbus.inf b/src/xenbus.inf
> index f2aced3..37782d9 100644
> --- a/src/xenbus.inf
> +++ b/src/xenbus.inf
> @@ -34,7 +34,7 @@ Class=System
>  ClassGUID={4d36e97d-e325-11ce-bfc1-08002be10318}
>  Provider=%Vendor%
>  CatalogFile=xenbus.cat
> -DriverVer=01/01/1900,0.0.0.0
> +DriverVer=@INF_DATE@,@MAJOR_VERSION@.@MINOR_VERSION@.@MICRO_VERSION@.@BUILD_NUMBER@
>  DriverPackageDisplayName=%DiskDesc%
> 
>  [DestinationDirs]
> diff --git a/symstore.ps1 b/symstore.ps1
> new file mode 100644
> index 0000000..8b139a7
> --- /dev/null
> +++ b/symstore.ps1
> @@ -0,0 +1,45 @@
> +#
> +# Wrapper script Symbol Server
> +#
> +param(
> +     [string]$DriverName = "xenbus",
> +     [string]$SymbolServer = "c:\symbols",
> +     [switch]$Free,
> +     [switch]$Checked
> +)
> +
> +Function Add-Symbols {
> +     param(
> +             [string]$DriverName,
> +             [string]$DriverPath,
> +             [string]$SymbolServer,
> +             [string]$Arch
> +     )
> +
> +     $cwd = Get-Location
> +     Set-Location $DriverPath
> +
> +     $symstore = [string]::Format("{0}Debuggers\{1}\symstore.exe", 
> $env:WDKContentRoot, $Arch)
> +
> +     $inffile=[string]::Format("{0}.inf", $DriverName)
> +     $Version=(Get-Content -Path $inffile | Select-String 
> "DriverVer").Line.Split(',')[1]
> +
> +     Write-Host $symstore "add" "/s" $SymbolServer "/r" "/f" "*.pdb" "/t" 
> $DriverName "/v" $Version
> +     Get-ChildItem -Path "." -Include "*.pdb" -Name | Write-Host
> +     & $symstore "add" "/s" $SymbolServer "/r" "/f" "*.pdb" "/t" $DriverName 
> "/v" $Version
> +
> +     Set-Location $cwd
> +}
> +
> +if ($Free -or -not $Checked) {
> +     $driverpath = [string]::Format("{0}\x64", $DriverName)
> +     Add-Symbols $DriverName $driverpath $SymbolServer "x64"
> +     $driverpath = [string]::Format("{0}\x86", $DriverName)
> +     Add-Symbols $DriverName $driverpath $SymbolServer "x86"
> +}
> +if ($Checked) {
> +     $driverpath = [string]::Format("{0}-checked\x64", $DriverName)
> +     Add-Symbols $DriverName $driverpath $SymbolServer "x64"
> +     $driverpath = [string]::Format("{0}-checked\x86", $DriverName)
> +     Add-Symbols $DriverName $driverpath $SymbolServer "x86"
> +}
> --
> 2.16.2.windows.1
> 
> 
> _______________________________________________
> win-pv-devel mailing list
> win-pv-devel@xxxxxxxxxxxxxxxxxxxx
> https://lists.xenproject.org/mailman/listinfo/win-pv-devel
_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/win-pv-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.