.go-autogen.ps1 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #>
  11. param(
  12. [Parameter(Mandatory=$true)][string]$CommitString,
  13. [Parameter(Mandatory=$true)][string]$DockerVersion,
  14. [Parameter(Mandatory=$false)][string]$Platform,
  15. [Parameter(Mandatory=$false)][string]$Product,
  16. [Parameter(Mandatory=$false)][string]$DefaultProductLicense
  17. )
  18. $ErrorActionPreference = "Stop"
  19. # Utility function to get the build date/time in UTC
  20. Function Get-BuildDateTime() {
  21. return $(Get-Date).ToUniversalTime()
  22. }
  23. try {
  24. $buildDateTime=Get-BuildDateTime
  25. if (Test-Path ".\autogen") {
  26. Remove-Item ".\autogen" -Recurse -Force | Out-Null
  27. }
  28. $fileContents = '
  29. // +build autogen
  30. // Package dockerversion is auto-generated at build-time
  31. package dockerversion
  32. // Default build-time variable for library-import.
  33. // This file is overridden on build with build-time information.
  34. const (
  35. GitCommit string = "'+$CommitString+'"
  36. Version string = "'+$DockerVersion+'"
  37. BuildTime string = "'+$buildDateTime+'"
  38. PlatformName string = "'+$Platform+'"
  39. ProductName string = "'+$Product+'"
  40. DefaultProductLicense string = "'+$DefaultProductLicense+'"
  41. )
  42. // AUTOGENERATED FILE; see hack\make\.go-autogen.ps1
  43. '
  44. # Write the file without BOM
  45. $outputFile="$(Get-Location)\dockerversion\version_autogen.go"
  46. if (Test-Path $outputFile) { Remove-Item $outputFile }
  47. [System.IO.File]::WriteAllText($outputFile, $fileContents, (New-Object System.Text.UTF8Encoding($False)))
  48. New-Item -ItemType Directory -Path "autogen\winresources\tmp" | Out-Null
  49. New-Item -ItemType Directory -Path "autogen\winresources\dockerd" | Out-Null
  50. Copy-Item "hack\make\.resources-windows\resources.go" "autogen\winresources\dockerd"
  51. # Generate a version in the form major,minor,patch,build
  52. $versionQuad=$DockerVersion -replace "[^0-9.]*" -replace "\.", ","
  53. # Compile the messages
  54. windmc hack\make\.resources-windows\event_messages.mc -h autogen\winresources\tmp -r autogen\winresources\tmp
  55. if ($LASTEXITCODE -ne 0) { Throw "Failed to compile event message resources" }
  56. # If you really want to understand this madness below, search the Internet for powershell variables after verbatim arguments... Needed to get double-quotes passed through to the compiler options.
  57. # Generate the .syso files containing all the resources and manifest needed to compile the final docker binaries. Both 32 and 64-bit clients.
  58. $env:_ag_dockerVersion=$DockerVersion
  59. $env:_ag_gitCommit=$CommitString
  60. windres -i hack/make/.resources-windows/dockerd.rc -o autogen/winresources/dockerd/rsrc_amd64.syso -F pe-x86-64 --use-temp-file -I autogen/winresources/tmp -D DOCKER_VERSION_QUAD=$versionQuad --% -D DOCKER_VERSION=\"%_ag_dockerVersion%\" -D DOCKER_COMMIT=\"%_ag_gitCommit%\"
  61. if ($LASTEXITCODE -ne 0) { Throw "Failed to compile daemon resources" }
  62. }
  63. Catch [Exception] {
  64. # Throw the error onto the caller to display errors. We don't expect this script to be called directly
  65. Throw ".go-autogen.ps1 failed with error $_"
  66. }
  67. Finally {
  68. Remove-Item .\autogen\winresources\tmp -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
  69. $env:_ag_dockerVersion=""
  70. $env:_ag_gitCommit=""
  71. }