[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [XENVIF-PATCH] Add clean.ps1 and build.ps1 powershell scripts
Add powershell scripts to clean and build the driver project. ./clean.ps1 will delete any files not under source control, and will return the working folder to a fresh state. ./build.ps1 will build the project and create 2 output zip files (xenvif-source.zip and xenvif-[free|checked].zip). Contents of the driver package zip will also include a WiX merge module .wxs file that can be included in a driver installer. Scripts have been designd to use a minimal install situation, where only git and VCRedist packages are required, by using the Enterprise WDK ISO and its provided build environment. Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx> --- BUILD.md | 34 ++++++- build.ps1 | 273 ++++++++++++++++++++++++++++++++++++++++++++++++++++ clean.ps1 | 16 +++ include/version.inc | 22 +++++ src/xenvif.wxs | 30 ++++++ 5 files changed, 374 insertions(+), 1 deletion(-) create mode 100644 build.ps1 create mode 100644 clean.ps1 create mode 100644 include/version.inc create mode 100644 src/xenvif.wxs diff --git a/BUILD.md b/BUILD.md index 7a56ba7..e2502bf 100644 --- a/BUILD.md +++ b/BUILD.md @@ -1,15 +1,46 @@ Building the XenVif Package =========================== +Simplified Build Process using the EWDK +======================================= + +Requirements: +* Access to source (git) +* Visual C Redistributables (for SDV) +* Enterprise WDK ISO + +Simple Install Procedure using Chocolatey (https://chocolatey.org) + +From a PowerShell Prompt, +PS> Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object + System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) +PS> choco install git.install vcredist-all -y + +* Mount the EWDK iso +PS> D:\LaunchBuildEnv.cmd + +* change to source/build path +* acquire source (git clone...) + +PS> .\build.ps1 + build.ps1 takes several optional parameters: + [string]$VsVersion = "vs2017" (valid "vs2017", "vs2015") + [string]$Configuration = "free" (valid "free", "checked") + [switch]$RunSdv (optional, absent indicates SDV will not be run) + + +Python Build Process +==================== + First you'll need a device driver build environment for Windows 10. This means: * Visual Studio 2015 (Any SKU, including Express or Community) * Windows Driver Kit 10 -Install Visual Studio first (you only need install MFC for C++) and then the WDK. Set an environment variable called VS to the base of the Visual Studio Installation (e.g. C:\Program Files\Microsoft Visual Studio 14.0) and +Install Visual Studio first (you only need install MFC for C++) and then a variable called KIT to the base of the WDK (e.g. C:\Program Files\Windows Kits\10). Also set an environment variable called SYMBOL\_SERVER to point at a location where driver symbols can be @@ -43,3 +74,4 @@ verifier then you can add the 'nosdv' keyword to the end of your command e.g.: build.py free nosdv + diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..37ce9a5 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,273 @@ +# +# Build Driver Package +# +# Steps: +# build list of replacement values +# clean output folder +# generate xenvif\revision +# generate xenvif\version +# generate include\version.h +# generate xenvif.inf +# generate xenvif\xenvif.wxs +# call msbuild (x64) +# call msbuild (Win32) +# call msbuild (sdv) +# create source archive +# create output archive +# +Param( + [string]$VsVersion = "vs2017", + [string]$Configuration = "free", + [switch]$RunSdv +) + +$Driver="xenvif" +$Config="Windows 10 Release" # default value - overridden by VsVersion and Configuration + +Write-Host "=======================================================" +Write-Host "Building Driver: " $Driver +Write-Host "Visual Studio Project Dir: " $VsVersion +Write-Host "Release/Debug Mode: " $Configuration +Write-Host "Run SDV: " $RunSdv +Write-Host "=======================================================" + +# Define Global Variables +$GitDate = & "git.exe" "show" "-s" "--format=%ci" "HEAD" +$GitYear = (Get-Date -date $GitDate).Year +$GitMonth = (Get-Date -date $GitDate).Month +$GitDay = (Get-Date -date $GitDate).Day +$GitRevision = & "git.exe" "rev-list" "--max-count=1" "HEAD" +$GitBuildNum = & "git.exe" "rev-list" "HEAD" "--count" + +$Replacements = [ordered]@{ + "@MAJOR_VERSION@"="9"; + "@MINOR_VERSION@"="0"; + "@MICRO_VERSION@"="0"; + "@BUILD_NUMBER@"=$GitBuildNum + + "@VENDOR_PREFIX@"="XP"; + "@VENDOR_DEVICE_ID@"=$null; + "@VENDOR_NAME@"="Xen Project"; + "@PRODUCT_NAME@"="Xen"; + + "@YEAR@"=$GitYear; + "@MONTH@"=$GitMonth; + "@DAY@"=$GitDay; + + "@GIT_REVISION@"=$GitRevision; + "@WIX_PREFIX@"="XENVIF" +} + +Function Replace-Strings { + Param( + [string]$infile, + [string]$outfile, + $list + ) + Process { + Write-Host $infile " -> " $outfile + (Get-Content $infile) | + ForEach-Object { + $line = $_ + $list.GetEnumerator() | ForEach-Object { + if (([string]::IsNullOrEmpty($_.Value)) -and ($line.Contains($_.Name))) { + Write-Host "Skipping Line Containing " $_.Name + $line = $null + } + $line = $line -replace $_.Key, $_.Value + } + $line + } | + Set-Content $outfile + } +} + +Function Build-Solution { + Param( + [string]$Name, + [string]$Configuration = "Windows 10 Release", + [string]$Platform = "x64", + [string]$VsVersion = "vs2017" + ) + Process { + $c=[string]::Format("/p:Configuration=`"{0}`"", $Configuration) + $p=[string]::Format("/p:Platform=`"{0}`"", $Platform) + $t="/t:`"Build`"" + $s=[string]::Format(".\{0}\{1}.sln", $VsVersion, $Name) + Write-Host "msbuild.exe" "/m:1" $c $p $t $s + & "msbuild.exe" "/m:1" $c $p $t $s + + $platlist=@{ "x64"="x64"; "Win32"="x86" } + $src = [string]::Format("{0}\Windows10Release\{1}\package\*.*", $VsVersion, $Platform) + $dst = [string]::Format("xenvif\{0}", $platlist[$Platform]) + New-Item -Name $dst -ItemType "directory" + Copy-Item $src -Destination $dst + } +} + +Function Build-Project { + Param( + [string]$Name, + [string]$Project, + [string]$Target = "Build", + [string]$Inputs = "", + [string]$Configuration = "Windows 10 Release", + [string]$Platform = "x64", + [string]$VsVersion = "vs2017" + ) + Process { + $cwd = (Get-Location).path + $proj = [string]::Format("{0}\{1}\{2}", $cwd, $VsVersion, $Name) + Set-Location -Path $proj + Write-Host $proj + + $c=[string]::Format("/p:Configuration=`"{0}`"", $Configuration) + $p=[string]::Format("/p:Platform=`"{0}`"", $Platform) + $t=[string]::Format("/t:{0}", $Target) + $i=[string]::Format("/p:Inputs=`"{0}`"", $Inputs) + $s=[string]::Format("{0}.vcxproj", $Project) + if ($Inputs) { + Write-Host "msbuild.exe" $c $p $t $i $s + & "msbuild.exe" $c $p $t $i $s + } else { + Write-Host "msbuild.exe" $c $p $t $s + & "msbuild.exe" $c $p $t $s + } + + Set-Location -Path $cwd + } +} + +Function Build-Sdv-Logs { + Param( + [string]$Name, + [string]$Project, + [string]$Configuration = "Windows 10 Release", + [string]$VsVersion = "vs2017" + ) + Process { + $cwd = (Get-Location).path + + Build-Project $Name $Project + Build-Project $Name $Project "sdv" "/clean" + Build-Project $Name $Project "sdv" "/check:default.sdv" + Build-Project $Name $Project "dvl" + + $sdv=[string]::Format("{0}\{1}\*.DVL.XML", $VsVersion, $Project) + $dst=[string]::Format("{0}\{1}\", $cwd, $Project) + Copy-Item $sdv -Destination $dst + } +} + +Function Create-Archive { + Param( + [string]$Filename, + $FileList, + [string]$BaseDir + ) + Process { + if ($BaseDir -ne ".") { + $cwd = Get-Location + Set-Location $BaseDir + } + Write-Host "Creating Archive" $Filename + if (Test-Path -Path $Filename) { Remove-Item $Filename } + ForEach ($file in $FileList) { + Compress-Archive -Path $file -DestinationPath $Filename -Update + } + if ($BaseDir -ne ".") { + Set-Location $cwd + } + } +} + +Function Copy-ArchiveSrc { + Param( + $FileList, + [string]$BasePath + ) + Process { + New-Item -Path $BasePath -ItemType Directory -ErrorAction Ignore | Out-Null + + ForEach ($file in $FileList) { + $itempath = Split-Path -Path $file + $dest = Join-Path -Path $BasePath -ChildPath $itempath + New-Item -ItemType Directory -Path $dest -ErrorAction Ignore | Out-Null + Copy-Item $file -Destination $dest -Recurse | Out-Null + } + } +} + +# Build Process... +$configlist = @{ "free"="Release"; "checked"="Debug" } +$targetoslist = @{ "vs2017"="Windows 10"; "vs2015"="Windows 8" } +$Config=[string]::Format("{0} {1}", $targetoslist[$VsVersion], $configlist[$Configuration]) + +# Override branding with env vars (if present) +if (Test-Path env:VENDOR_PREFIX) { $Replacements["@VENDOR_PREFIX@"] = $env:VENDOR_PREFIX } +if (Test-Path env:VENDOR_DEVICE_ID) { $Replacements["@VENDOR_DEVICE_ID@"] = $env:VENDOR_DEVICE_ID } +if (Test-Path env:VENDOR_NAME) { $Replacements["@VENDOR_NAME@"] = $env:VENDOR_NAME } +if (Test-Path env:PRODUCT_NAME) { $Replacements["@PRODUCT_NAME@"] = $env:PRODUCT_NAME } +if (Test-Path env:WIX_PREFIX) { $Replacements["@WIX_PREFIX@"] = $env:WIX_PREFIX } + +# Show Variables Used +$Replacements +Write-Host "----" + +# set version variables +$env:MAJOR_VERSION=$Replacements["@MAJOR_VERSION@"] +$env:MINOR_VERSION=$Replacements["@MINOR_VERSION@"] +$env:MICRO_VERSION=$Replacements["@MICRO_VERSION@"] +$env:BUILD_NUMBER=$Replacements["@BUILD_NUMBER@"] + +# Clean Output Path +if (Test-Path -Path $Driver) { + Remove-Item $Driver -Recurse | Out-Null +} +New-Item -Name $Driver -ItemType "directory" | Out-Null + +# Generate xenif\revision +$revision = [string]::Format("{0}\revision", $Driver) +Add-Content -Path $revision -Value $GitRevision + +# Generate xenif\version +$version = [string]::Format("{0}\version", $Driver) +$versionvalue = [string]::Format("{0}.{1}.{2}.{3}", $Replacements["@MAJOR_VERSION@"], $Replacements["@MINOR_VERSION@"], $Replacements["@MICRO_VERSION@"], $Replacements["@BUILD_NUMBER@"]) +Add-Content -Path $version -Value $versionvalue + +# Generate include\version.h +Replace-Strings "include\version.inc" "include\version.h" $Replacements + +# Generate vs2017\xenvif.inf +$InfSrc=[string]::Format("src\{0}.inf", $Driver) +$InfDst=[string]::Format("{0}\{1}.inf", $VsVersion, $Driver) +Replace-Strings $InfSrc $InfDst $Replacements + +# Generate xenif\xenvif.wxs merge module +$WxsSrc=[string]::Format("src\{0}.wxs", $Driver) +$WxsDst=[string]::Format("{0}\{1}.wxs", $Driver, $Driver) +Replace-Strings $WxsSrc $WxsDst $Replacements + +# Execute MSBuild.exe +Build-Solution $Driver $Config "x64" +Build-Solution $Driver $Config "Win32" + +# Execute MSBuild.exe for SDV +if ($RunSdv) { Build-Sdv-Logs $Driver "xenvif" } + +$cwd = Get-Location + +# Archive Source (xenvif-source.zip) +$SourceFiles = & "git.exe" "ls-tree" "-r" "--name-only" "HEAD" +$SourceZip = [string]::Format("{0}/{1}-source.zip", $cwd, $Driver) +$ArchiveTemp = Join-Path -Path $cwd -ChildPath "temp" +Copy-ArchiveSrc $SourceFiles $ArchiveTemp +$ArchiveFiles = (Get-ChildItem -Path $ArchiveTemp).Name +Create-Archive $SourceZip $ArchiveFiles $ArchiveTemp +Remove-Item $ArchiveTemp -Recurse + +# Archive Driver (xenvif-[checked|free].zip) +$DriverFiles = (Get-ChildItem -Path $Driver).Name +$DriverZip = [string]::Format("{0}/{1}-{2}.zip", $cwd, $Driver, $Configuration) +$DriverPath = Join-Path -Path $cwd -ChildPath $Driver +Create-Archive $DriverZip $DriverFiles $DriverPath diff --git a/clean.ps1 b/clean.ps1 new file mode 100644 index 0000000..16dccb1 --- /dev/null +++ b/clean.ps1 @@ -0,0 +1,16 @@ +# +# Delete all files not under source control +# +$files = & "git.exe" "status" "-u" "--porcelain" +ForEach ($line in $files) { + $type = $line.Split(" ")[0] + if ($type -eq "??") { + $file = $line.Split(" ")[1] + Write-Host $file + if (Test-Path -Path $file -PathType Container) { + Remove-Item $file -Force -Recurse + } else { + Remove-Item $file -Force + } + } +} diff --git a/include/version.inc b/include/version.inc new file mode 100644 index 0000000..316a115 --- /dev/null +++ b/include/version.inc @@ -0,0 +1,22 @@ +#define VENDOR_NAME_STR "@VENDOR_NAME@" +#define VENDOR_PREFIX_STR "@VENDOR_PREFIX@" +#define PRODUCT_NAME_STR "@PRODUCT_NAME@" + +#define MAJOR_VERSION @MAJOR_VERSION@ +#define MINOR_VERSION @MINOR_VERSION@ +#define MICRO_VERSION @MICRO_VERSION@ +#define BUILD_NUMBER @BUILD_NUMBER@ + +#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 @YEAR@ +#define MONTH @MONTH@ +#define DAY @DAY@ + +#define YEAR_STR "@YEAR@" +#define MONTH_STR "@MONTH@" +#define DAY_STR "@DAY@" + diff --git a/src/xenvif.wxs b/src/xenvif.wxs new file mode 100644 index 0000000..949c630 --- /dev/null +++ b/src/xenvif.wxs @@ -0,0 +1,30 @@ +<?xml version='1.0' encoding='windows-1252' ?> +<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' + xmlns:difx='http://schemas.microsoft.com/wix/DifxAppExtension'> +<Module Id='@WIX_PREFIX@_XENVIF' Language='1033' Version='@MAJOR_VERSION@.@MINOR_VERSION@.@MICRO_VERSION@.@BUILD_NUMBER@'> + <Package Id='31EE53DC-F692-460F-BE31-CE16EDA08605' Keywords='@PRODUCT_NAME@PVDriver' Description='@PRODUCT_NAME@ PV Driver Installer' + Comments='@PRODUCT_NAME@ PV Driver' Manufacturer='@VENDOR_NAME@' + InstallerVersion='200' Languages='1033' + SummaryCodepage='1252' /> + <Directory Id="TARGETDIR" Name="SourceDir"> + <Directory Id="@WIX_PREFIX@_XENVIF" Name="xenvif"> + <Directory Id="@WIX_PREFIX@_XENVIF_X86" Name="x86"> + <Component Id="@WIX_PREFIX@_XENVIF_X86" Guid=""> + <File Id="@WIX_PREFIX@_X86_XENVIF_INF" Name="xenvif.inf" DiskId="1" Source="x86/xenvif.inf" /> + <File Id="@WIX_PREFIX@_X86_XENVIF_CAT" Name="xenvif.cat" DiskId="1" Source="x86/xenvif.cat" /> + <File Id="@WIX_PREFIX@_X86_XENVIF_SYS" Name="xenvif.sys" DiskId="1" Source="x86/xenvif.sys" /> + <File Id="@WIX_PREFIX@_X86_XENVIF_COINST_DLL" Name="xenvif_coinst.dll" DiskId="1" Source="x86/xenvif_coinst.dll" /> + </Component> + </Directory> + <Directory Id="@WIX_PREFIX@_XENVIF_X64" Name="x64"> + <Component Id="@WIX_PREFIX@_XENVIF_X64" Guid=""> + <File Id="@WIX_PREFIX@_X64_XENVIF_INF" Name="xenvif.inf" DiskId="1" Source="x64/xenvif.inf" /> + <File Id="@WIX_PREFIX@_X64_XENVIF_CAT" Name="xenvif.cat" DiskId="1" Source="x64/xenvif.cat" /> + <File Id="@WIX_PREFIX@_X64_XENVIF_SYS" Name="xenvif.sys" DiskId="1" Source="x64/xenvif.sys" /> + <File Id="@WIX_PREFIX@_X64_XENVIF_COINST_DLL" Name="xenvif_coinst.dll" DiskId="1" Source="x64/xenvif_coinst.dll" /> + </Component> + </Directory> + </Directory> + </Directory> +</Module> +</Wix> -- 2.16.2.windows.1 _______________________________________________ win-pv-devel mailing list win-pv-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/win-pv-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |