github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+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      [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\dockerd" | Out-Null
    64      Copy-Item "hack\make\.resources-windows\resources.go" "autogen\winresources\dockerd"
    65  
    66      # Generate a version in the form major,minor,patch,build
    67      $versionQuad=$DockerVersion -replace "[^0-9.]*" -replace "\.", ","
    68  
    69      # Compile the messages
    70      windmc hack\make\.resources-windows\event_messages.mc -h autogen\winresources\tmp -r autogen\winresources\tmp
    71      if ($LASTEXITCODE -ne 0) { Throw "Failed to compile event message resources" }
    72  
    73      # 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.
    74      # Generate the .syso files containing all the resources and manifest needed to compile the final docker binaries. Both 32 and 64-bit clients.
    75      $env:_ag_dockerVersion=$DockerVersion
    76      $env:_ag_gitCommit=$CommitString
    77  
    78      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%\"
    79      if ($LASTEXITCODE -ne 0) { Throw "Failed to compile daemon resources" }
    80  }
    81  Catch [Exception] {
    82      # Throw the error onto the caller to display errors. We don't expect this script to be called directly 
    83      Throw ".go-autogen.ps1 failed with error $_"
    84  }
    85  Finally {
    86      Remove-Item .\autogen\winresources\tmp -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
    87      $env:_ag_dockerVersion=""
    88      $env:_ag_gitCommit=""
    89  }