.go-autogen.ps1 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <#
  2. .NOTES
  3. Author: @jhowardmsft
  4. Summary: Windows native version of .go-autogen which generates the
  5. .go source code for building, and performs resource compilation.
  6. .PARAMETER CommitString
  7. The commit string. This is calculated externally to this script.
  8. .PARAMETER DockerVersion
  9. The version such as 17.04.0-dev. This is calculated externally to this script.
  10. .PARAMETER Platform
  11. The platform name, such as "Docker Engine - Community".
  12. .PARAMETER Product
  13. The product name, used to set version.ProductName, which is used to set BuildKit's
  14. ExportedProduct variable in order to show useful error messages to users when a
  15. certain version of the product doesn't support a BuildKit feature.
  16. .PARAMETER DefaultProductLicense
  17. Sets the version.DefaultProductLicense string, such as "Community Engine". This field
  18. can contain a summary of the product license of the daemon if a commercial license has
  19. been applied to the daemon.
  20. .PARAMETER PackagerName
  21. The name of the packager (e.g. "Docker, Inc."). This used to set CompanyName in the manifest.
  22. #>
  23. param(
  24. [Parameter(Mandatory=$true)][string]$CommitString,
  25. [Parameter(Mandatory=$true)][string]$DockerVersion,
  26. [Parameter(Mandatory=$false)][string]$Platform,
  27. [Parameter(Mandatory=$false)][string]$Product,
  28. [Parameter(Mandatory=$false)][string]$DefaultProductLicense,
  29. [Parameter(Mandatory=$false)][string]$PackagerName
  30. )
  31. $ErrorActionPreference = "Stop"
  32. # Utility function to get the build date/time in UTC
  33. Function Get-BuildDateTime() {
  34. return $(Get-Date).ToUniversalTime()
  35. }
  36. Function Get-Year() {
  37. return $(Get-Date).year
  38. }
  39. Function Get-FixQuadVersionNumber($number) {
  40. if ($number -eq 0) {
  41. return $number
  42. }
  43. return $number.TrimStart("0")
  44. }
  45. try {
  46. $buildDateTime=Get-BuildDateTime
  47. $currentYear=Get-Year
  48. # Update PATH
  49. $env:PATH="$env:GOPATH\bin;$env:PATH"
  50. # Generate a version in the form major,minor,patch,build
  51. $versionQuad=($DockerVersion -replace "[^0-9.]*")
  52. if ($versionQuad -Match "^\d+`.\d+`.\d+$"){
  53. $versionQuad = $versionQuad + ".0"
  54. }
  55. $versionMatches = $($versionQuad | Select-String -AllMatches -Pattern "(\d+)`.(\d+)`.(\d+)`.(\d+)").Matches
  56. $mkwinresContents = '{
  57. "RT_GROUP_ICON": {
  58. "#1": {
  59. "0409": "../../winresources/docker.ico"
  60. }
  61. },
  62. "RT_MANIFEST": {
  63. "#1": {
  64. "0409": {
  65. "identity": {},
  66. "description": "Docker Engine",
  67. "minimum-os": "vista",
  68. "execution-level": "",
  69. "ui-access": false,
  70. "auto-elevate": false,
  71. "dpi-awareness": "unaware",
  72. "disable-theming": false,
  73. "disable-window-filtering": false,
  74. "high-resolution-scrolling-aware": false,
  75. "ultra-high-resolution-scrolling-aware": false,
  76. "long-path-aware": false,
  77. "printer-driver-isolation": false,
  78. "gdi-scaling": false,
  79. "segment-heap": false,
  80. "use-common-controls-v6": false
  81. }
  82. }
  83. },
  84. "RT_MESSAGETABLE": {
  85. "#1": {
  86. "0409": "../../winresources/event_messages.bin"
  87. }
  88. },
  89. "RT_VERSION": {
  90. "#1": {
  91. "0409": {
  92. "fixed": {
  93. "file_version": "'+(Get-FixQuadVersionNumber($versionMatches.Groups[1].Value))+'.'+(Get-FixQuadVersionNumber($versionMatches.Groups[2].Value))+'.'+(Get-FixQuadVersionNumber($versionMatches.Groups[3].Value))+'.'+(Get-FixQuadVersionNumber($versionMatches.Groups[4].Value))+'",
  94. "product_version": "'+(Get-FixQuadVersionNumber($versionMatches.Groups[1].Value))+'.'+(Get-FixQuadVersionNumber($versionMatches.Groups[2].Value))+'.'+(Get-FixQuadVersionNumber($versionMatches.Groups[3].Value))+'.'+(Get-FixQuadVersionNumber($versionMatches.Groups[4].Value))+'",
  95. "type": "Unknown"
  96. },
  97. "info": {
  98. "0000": {
  99. "CompanyName": "'+$PackagerName+'",
  100. "FileVersion": "'+$DockerVersion+'",
  101. "LegalCopyright": "Copyright (C) 2015-'+$currentYear+' Docker Inc.",
  102. "OriginalFileName": "dockerd.exe",
  103. "ProductName": "'+$Product+'",
  104. "ProductVersion": "'+$DockerVersion+'",
  105. "SpecialBuild": "'+$CommitString+'"
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }'
  112. # Write the file
  113. $outputFile="$(Get-Location)\cli\winresources\dockerd\winres.json"
  114. if (Test-Path $outputFile) { Remove-Item $outputFile }
  115. [System.IO.File]::WriteAllText($outputFile, $mkwinresContents)
  116. Get-Content $outputFile | Out-Host
  117. # Create winresources package stub if removed while using tmpfs in Dockerfile
  118. $stubPackage="$(Get-Location)\cli\winresources\dockerd\winresources.go"
  119. if(![System.IO.File]::Exists($stubPackage)){
  120. Set-Content -NoNewline -Path $stubPackage -Value 'package winresources'
  121. }
  122. # Generate
  123. go generate -v "github.com/docker/docker/cmd/dockerd"
  124. if ($LASTEXITCODE -ne 0) { Throw "Failed to generate version info" }
  125. }
  126. Catch [Exception] {
  127. # Throw the error onto the caller to display errors. We don't expect this script to be called directly
  128. Throw ".go-autogen.ps1 failed with error $_"
  129. }
  130. Finally {
  131. $env:_ag_dockerVersion=""
  132. $env:_ag_gitCommit=""
  133. }