progen.ps1 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #
  2. # POCO progen automation script
  3. #
  4. # Usage:
  5. # ------
  6. # progen.ps1 [-poco_base dir]
  7. # [-vs 160| 170]
  8. # [-omit "Lib1X,LibY,LibZ,..."]
  9. # [-components "Lib1X,LibY,LibZ,..."]
  10. # [-platform Win32 | x64 | ARM64 | WEC2013]
  11. # [-samples]
  12. # [-tests]
  13. # [-nobuild]
  14. [CmdletBinding()]
  15. Param
  16. (
  17. [Parameter()]
  18. [string] $poco_base = $([System.Environment]::GetEnvironmentVariable('POCO_BASE')),
  19. [Parameter()]
  20. [ValidateSet(160, 170)]
  21. [int] $vs = 170,
  22. [string] $omit,
  23. [string] $components,
  24. [Parameter()]
  25. [ValidateSet('Win32', 'x64', 'ARM64', 'WEC2013')]
  26. [string] $platform = 'x64',
  27. [switch] $samples = $false,
  28. [switch] $tests = $false,
  29. [switch] $nobuild = $false,
  30. [switch] $help
  31. )
  32. function ProcessInput
  33. {
  34. if ($help -eq $true)
  35. {
  36. Write-Host 'Usage:'
  37. Write-Host '------'
  38. Write-Host 'progen.ps1 [-poco_base <dir>]'
  39. Write-Host ' [-vs 160 | 170]'
  40. Write-Host ' [-omit "Lib1X,LibY,LibZ,..."]'
  41. Write-Host ' [-components "Lib1X,LibY,LibZ,..."]'
  42. Write-Host ' [-samples]'
  43. Write-Host ' [-tests]'
  44. Write-Host ' [-nobuild]'
  45. Exit
  46. }
  47. else
  48. {
  49. if($components -ne '' -and $omit -ne '') {
  50. Write-Host "-components and -omit cannot be used simultaneously, exiting..."
  51. Exit
  52. }
  53. Write-Host ""
  54. Write-Host "--------------------"
  55. Write-Host "Progen configuration:"
  56. Write-Host "--------------------"
  57. Write-Host "Poco Base: $poco_base"
  58. Write-Host "Version: $vs"
  59. Write-Host "Samples: $samples"
  60. Write-Host "Tests: $tests"
  61. Write-Host "No Build: $nobuild"
  62. if ($omit -ne '')
  63. {
  64. Write-Host "Omit: $omit"
  65. }
  66. if ($components -ne '')
  67. {
  68. Write-Host "Components: $components"
  69. }
  70. Write-Host "----------------------------------------"
  71. Write-Host ""
  72. # NB: this won't work in PowerShell ISE
  73. #Write-Host "Press Ctrl-C to exit or any other key to continue ..."
  74. #$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp")
  75. }
  76. }
  77. function InvokeProcess([string] $exe, [string] $arguments)
  78. {
  79. $proc = Start-Process -NoNewWindow -FilePath $exe -ArgumentList $arguments -PassThru
  80. $handle = $proc.Handle # cache proc.Handle, necessary to get exit code
  81. $proc.WaitForExit();
  82. if ($proc.ExitCode -ne 0) {
  83. Write-Warning "$_ exited with status code $($proc.ExitCode)"
  84. }
  85. }
  86. function InvokeProgenSamples
  87. {
  88. process {
  89. $sampleName = $_.BaseName.split(".")[0]
  90. if($_.Name -eq "samples.progen") {
  91. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  92. Write-Host "| Running Progen for $componentDir\$sampleName"
  93. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  94. $sampleProgenPath = "$($poco_base)\$($componentDir)\$($sampleName)\$($_)"
  95. }
  96. else {
  97. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  98. Write-Host "| Running Progen for $componentDir\samples\$sampleName"
  99. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  100. $sampleProgenPath = "$($poco_base)\$($componentDir)\samples\$($sampleName)\$($_)"
  101. }
  102. if (Test-Path -Path $sampleProgenPath) {
  103. InvokeProcess $progenPath "/tool=vs$vs $sampleProgenPath"
  104. }
  105. else {
  106. Write-Host "NOTICE: No .progen file for $sampleName"
  107. }
  108. }
  109. }
  110. function InvokeProgenComponents([string] $type)
  111. {
  112. if(Test-Path "$poco_base\ProGen\bin64\static_mt\progen.exe") {
  113. $progenPath = Resolve-Path "$poco_base\ProGen\bin64\static_mt\progen.exe"
  114. }
  115. elseif(Test-Path "$poco_base\ProGen\bin64\static_md\progen.exe") {
  116. $progenPath = Resolve-Path "$poco_base\ProGen\bin64\static_md\progen.exe"
  117. }
  118. else {
  119. $progenPath = Resolve-Path "$poco_base\ProGen\bin64\progen.exe"
  120. }
  121. $exists = Test-Path "$poco_base\ProGen\bin64\static_mt\progen.exe"
  122. if (-not $exists) {
  123. Write-Error "Progen not found, exiting..."
  124. Exit -1
  125. }
  126. Get-Content "$poco_base\components" | Foreach-Object {
  127. $component = $_
  128. $componentDir = $_.Replace("/", "\")
  129. $componentArr = $_.split('/')
  130. $componentName = $componentArr[$componentArr.Length - 1]
  131. $omitArray = @()
  132. $omit.Split(',') | ForEach-Object {
  133. $omitArray += $_.Trim()
  134. }
  135. $componentsArray = @()
  136. $components.Split(',') | ForEach-Object {
  137. $componentsArray += $_.Trim()
  138. }
  139. if ($omitArray -NotContains $component -and ((-not ($component -Contains "Foundation")) -or ($type -eq "sample")) -and (($componentsArray -Contains $component) -or ($components -eq '')))
  140. {
  141. if($type -eq "lib") {
  142. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  143. Write-Host "| Running ProGen for $componentDir"
  144. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  145. $componentProgenPath = "$poco_base\$componentDir\$componentName.progen"
  146. InvokeProcess $progenPath "/tool=vs$vs $componentProgenPath"
  147. }
  148. ElseIf ($tests -and ($type -eq "test")) {
  149. if (Test-Path -Path "$poco_base\$componentDir\testsuite") {
  150. $componentTestProgenPath = "$poco_base\$componentDir\testsuite\TestSuite.Progen"
  151. if (Test-Path -Path $componentTestProgenPath) {
  152. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  153. Write-Host "| Running Progen for $componentDir\testsuite"
  154. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  155. InvokeProcess $progenPath "/tool=vs$vs $componentTestProgenPath"
  156. if ($component -eq "Data") # special case for Data
  157. {
  158. $componentTestProgenPath = "$poco_base\$componentDir\DataTest\DataTest.progen"
  159. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  160. Write-Host "| Running Progen for $componentDir\DataTest"
  161. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  162. InvokeProcess $progenPath "/tool=vs$vs $componentTestProgenPath"
  163. }
  164. }
  165. Else {
  166. Write-Host "NOTICE: Missing .progen file for $componentDir\testsuite"
  167. }
  168. }
  169. }
  170. ElseIf ($samples -and ($type -eq "sample")) {
  171. Get-Childitem "$poco_base\$($componentDir)" -Recurse |`
  172. Where-Object {$_.Extension -Match ".progen" -And $_.DirectoryName -Like "*samples*" } `
  173. | InvokeProgenSamples "$_"
  174. }
  175. }
  176. else
  177. {
  178. Write-Host "-------------------------------"
  179. Write-Host "# Skipping $componentDir"
  180. Write-Host "-------------------------------"
  181. }
  182. }
  183. }
  184. function InvokeBuildWin {
  185. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  186. Write-Host "| Building Foundation,XML,JSON,Util,Progen"
  187. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  188. Invoke-Expression "$poco_base\buildwin.ps1 -poco_base $poco_base -platform $platform -linkmode static_mt -vs $vs -action build -components `"Foundation,XML,JSON,Util,Progen`" "
  189. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  190. Write-Host "| Build finished."
  191. Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  192. }
  193. function Run
  194. {
  195. ProcessInput
  196. if($nobuild -eq $false) {
  197. InvokeBuildWin
  198. }
  199. InvokeProgenComponents "lib"
  200. InvokeProgenComponents "test"
  201. InvokeProgenComponents "sample"
  202. }
  203. Run