github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/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      [Parameter(Mandatory=$false)][string]$Product,
    20      [Parameter(Mandatory=$false)][string]$DefaultProductLicense
    21  )
    22  
    23  $ErrorActionPreference = "Stop"
    24  
    25  # Utility function to get the build date/time in UTC
    26  Function Get-BuildDateTime() {
    27      return $(Get-Date).ToUniversalTime()
    28  }
    29  
    30  try {
    31      $buildDateTime=Get-BuildDateTime
    32  
    33      if (Test-Path ".\autogen") {
    34          Remove-Item ".\autogen" -Recurse -Force | Out-Null
    35      }
    36  
    37      $fileContents = '
    38  // +build autogen
    39  
    40  // Package dockerversion is auto-generated at build-time
    41  package dockerversion
    42  
    43  // Default build-time variable for library-import.
    44  // This file is overridden on build with build-time information.
    45  const (
    46  	GitCommit             string = "'+$CommitString+'"
    47  	Version               string = "'+$DockerVersion+'"
    48  	BuildTime             string = "'+$buildDateTime+'"
    49  	PlatformName          string = "'+$Platform+'"
    50  	ProductName           string = "'+$Product+'"
    51  	DefaultProductLicense string = "'+$DefaultProductLicense+'"
    52  )
    53  
    54  // AUTOGENERATED FILE; see hack\make\.go-autogen.ps1
    55  '
    56  
    57      # Write the file without BOM
    58      $outputFile="$(Get-Location)\dockerversion\version_autogen.go"
    59      if (Test-Path $outputFile) { Remove-Item $outputFile }
    60      [System.IO.File]::WriteAllText($outputFile, $fileContents, (New-Object System.Text.UTF8Encoding($False)))
    61  
    62      New-Item -ItemType Directory -Path "autogen\winresources\tmp" | Out-Null
    63      New-Item -ItemType Directory -Path "autogen\winresources\docker" | Out-Null
    64      New-Item -ItemType Directory -Path "autogen\winresources\dockerd" | Out-Null
    65      Copy-Item "hack\make\.resources-windows\resources.go" "autogen\winresources\docker"
    66      Copy-Item "hack\make\.resources-windows\resources.go" "autogen\winresources\dockerd"
    67  
    68      # Generate a version in the form major,minor,patch,build
    69      $versionQuad=$DockerVersion -replace "[^0-9.]*" -replace "\.", ","
    70  
    71      # Compile the messages
    72      windmc hack\make\.resources-windows\event_messages.mc -h autogen\winresources\tmp -r autogen\winresources\tmp
    73      if ($LASTEXITCODE -ne 0) { Throw "Failed to compile event message resources" }
    74  
    75      # 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.
    76      # Generate the .syso files containing all the resources and manifest needed to compile the final docker binaries. Both 32 and 64-bit clients.
    77      $env:_ag_dockerVersion=$DockerVersion
    78      $env:_ag_gitCommit=$CommitString
    79  
    80      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%\"
    81      if ($LASTEXITCODE -ne 0) { Throw "Failed to compile client 64-bit resources" }
    82  
    83      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%\"
    84      if ($LASTEXITCODE -ne 0) { Throw "Failed to compile client 32-bit resources" }
    85  
    86      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%\"
    87      if ($LASTEXITCODE -ne 0) { Throw "Failed to compile daemon resources" }
    88  }
    89  Catch [Exception] {
    90      # Throw the error onto the caller to display errors. We don't expect this script to be called directly 
    91      Throw ".go-autogen.ps1 failed with error $_"
    92  }
    93  Finally {
    94      Remove-Item .\autogen\winresources\tmp -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
    95      $env:_ag_dockerVersion=""
    96      $env:_ag_gitCommit=""
    97  }