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