.go-autogen.ps1 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. )
  15. $ErrorActionPreference = "Stop"
  16. # Utility function to get the build date/time in UTC
  17. Function Get-BuildDateTime() {
  18. return $(Get-Date).ToUniversalTime()
  19. }
  20. try {
  21. $buildDateTime=Get-BuildDateTime
  22. if (Test-Path ".\autogen") {
  23. Remove-Item ".\autogen" -Recurse -Force | Out-Null
  24. }
  25. $fileContents = '
  26. // +build autogen
  27. // Package dockerversion is auto-generated at build-time
  28. package dockerversion
  29. // Default build-time variable for library-import.
  30. // This file is overridden on build with build-time informations.
  31. const (
  32. GitCommit string = "'+$CommitString+'"
  33. Version string = "'+$DockerVersion+'"
  34. BuildTime string = "'+$buildDateTime+'"
  35. )
  36. // AUTOGENERATED FILE; see hack\make\.go-autogen.ps1
  37. '
  38. # Write the file without BOM
  39. $outputFile="$(pwd)\dockerversion\version_autogen.go"
  40. if (Test-Path $outputFile) { Remove-Item $outputFile }
  41. [System.IO.File]::WriteAllText($outputFile, $fileContents, (New-Object System.Text.UTF8Encoding($False)))
  42. New-Item -ItemType Directory -Path "autogen\winresources\tmp" | Out-Null
  43. New-Item -ItemType Directory -Path "autogen\winresources\docker" | Out-Null
  44. New-Item -ItemType Directory -Path "autogen\winresources\dockerd" | Out-Null
  45. Copy-Item "hack\make\.resources-windows\resources.go" "autogen\winresources\docker"
  46. Copy-Item "hack\make\.resources-windows\resources.go" "autogen\winresources\dockerd"
  47. # Generate a version in the form major,minor,patch,build
  48. $versionQuad=$DockerVersion -replace "[^0-9.]*" -replace "\.", ","
  49. # Compile the messages
  50. windmc hack\make\.resources-windows\event_messages.mc -h autogen\winresources\tmp -r autogen\winresources\tmp
  51. if ($LASTEXITCODE -ne 0) { Throw "Failed to compile event message resources" }
  52. # 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.
  53. # Generate the .syso files containing all the resources and manifest needed to compile the final docker binaries. Both 32 and 64-bit clients.
  54. $env:_ag_dockerVersion=$DockerVersion
  55. $env:_ag_gitCommit=$CommitString
  56. windres -i hack/make/.resources-windows/docker.rc -o autogen/winresources/docker/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%\"
  57. if ($LASTEXITCODE -ne 0) { Throw "Failed to compile client 64-bit resources" }
  58. windres -i hack/make/.resources-windows/docker.rc -o autogen/winresources/docker/rsrc_386.syso -F pe-i386 --use-temp-file -I autogen/winresources/tmp -D DOCKER_VERSION_QUAD=$versionQuad --% -D DOCKER_VERSION=\"%_ag_dockerVersion%\" -D DOCKER_COMMIT=\"%_ag_gitCommit%\"
  59. if ($LASTEXITCODE -ne 0) { Throw "Failed to compile client 32-bit resources" }
  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. }