github.com/sams1990/dockerrepo@v17.12.1-ce-rc2+incompatible/hack/make/.go-autogen.ps1 (about) 1 <# 2 .NOTES 3 Author: @jhowardmsft 4 5 Summary: Windows native version of .go-autogen which generates the 6 .go source code for building, and performs resource compilation. 7 8 .PARAMETER CommitString 9 The commit string. This is calculated externally to this script. 10 11 .PARAMETER DockerVersion 12 The version such as 17.04.0-dev. This is calculated externally to this script. 13 #> 14 15 param( 16 [Parameter(Mandatory=$true)][string]$CommitString, 17 [Parameter(Mandatory=$true)][string]$DockerVersion, 18 [Parameter(Mandatory=$false)][string]$Platform 19 ) 20 21 $ErrorActionPreference = "Stop" 22 23 # Utility function to get the build date/time in UTC 24 Function Get-BuildDateTime() { 25 return $(Get-Date).ToUniversalTime() 26 } 27 28 try { 29 $buildDateTime=Get-BuildDateTime 30 31 if (Test-Path ".\autogen") { 32 Remove-Item ".\autogen" -Recurse -Force | Out-Null 33 } 34 35 $fileContents = ' 36 // +build autogen 37 38 // Package dockerversion is auto-generated at build-time 39 package dockerversion 40 41 // Default build-time variable for library-import. 42 // This file is overridden on build with build-time informations. 43 const ( 44 GitCommit string = "'+$CommitString+'" 45 Version string = "'+$DockerVersion+'" 46 BuildTime string = "'+$buildDateTime+'" 47 PlatformName string = "'+$Platform+'" 48 ) 49 50 // AUTOGENERATED FILE; see hack\make\.go-autogen.ps1 51 ' 52 53 # Write the file without BOM 54 $outputFile="$(pwd)\dockerversion\version_autogen.go" 55 if (Test-Path $outputFile) { Remove-Item $outputFile } 56 [System.IO.File]::WriteAllText($outputFile, $fileContents, (New-Object System.Text.UTF8Encoding($False))) 57 58 New-Item -ItemType Directory -Path "autogen\winresources\tmp" | Out-Null 59 New-Item -ItemType Directory -Path "autogen\winresources\docker" | Out-Null 60 New-Item -ItemType Directory -Path "autogen\winresources\dockerd" | Out-Null 61 Copy-Item "hack\make\.resources-windows\resources.go" "autogen\winresources\docker" 62 Copy-Item "hack\make\.resources-windows\resources.go" "autogen\winresources\dockerd" 63 64 # Generate a version in the form major,minor,patch,build 65 $versionQuad=$DockerVersion -replace "[^0-9.]*" -replace "\.", "," 66 67 # Compile the messages 68 windmc hack\make\.resources-windows\event_messages.mc -h autogen\winresources\tmp -r autogen\winresources\tmp 69 if ($LASTEXITCODE -ne 0) { Throw "Failed to compile event message resources" } 70 71 # 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. 72 # Generate the .syso files containing all the resources and manifest needed to compile the final docker binaries. Both 32 and 64-bit clients. 73 $env:_ag_dockerVersion=$DockerVersion 74 $env:_ag_gitCommit=$CommitString 75 76 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%\" 77 if ($LASTEXITCODE -ne 0) { Throw "Failed to compile client 64-bit resources" } 78 79 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%\" 80 if ($LASTEXITCODE -ne 0) { Throw "Failed to compile client 32-bit resources" } 81 82 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%\" 83 if ($LASTEXITCODE -ne 0) { Throw "Failed to compile daemon resources" } 84 } 85 Catch [Exception] { 86 # Throw the error onto the caller to display errors. We don't expect this script to be called directly 87 Throw ".go-autogen.ps1 failed with error $_" 88 } 89 Finally { 90 Remove-Item .\autogen\winresources\tmp -Recurse -Force -ErrorAction SilentlyContinue | Out-Null 91 $env:_ag_dockerVersion="" 92 $env:_ag_gitCommit="" 93 }