github.com/amanya/packer@v0.12.1-0.20161117214323-902ac5ab2eb6/scripts/build.ps1 (about)

     1  <#
     2      .Synopsis
     3      Build script for Packer.
     4  
     5      .Description
     6      Build script for Packer for all supported platforms and architectures.
     7      By default the following OSs and architectures are targeted.
     8  
     9      OS:
    10       * linux
    11       * darwin
    12       * windows
    13       * freebsd
    14       * openbsd
    15  
    16      Architecture:
    17       * 386
    18       * amd64
    19       * arm
    20  
    21      If the environment variable PACKER_DEV is defined, then the OS and
    22      architecture of the go binary in the path is used.
    23  
    24      The built binary is stamped with the current version number of Packer,
    25      the latest git commit, and +CHANGES if there are any outstanding
    26      changes in the current repository, e.g.
    27  
    28        Packer v0.10.1.dev (3c736322ba3a5fcb3a4e92394011a2e56f396da6+CHANGES)
    29  
    30      The build artifacts for the current OS and architecture are copied to
    31      bin and $GOPATH\bin.
    32  
    33      .Example
    34      .\scripts\build.ps1
    35  #>
    36  
    37  # This script builds the application from source for multiple platforms.
    38  
    39  # Get the parent directory of where this script is.
    40  $DIR = [System.IO.Path]::GetDirectoryName($PSScriptRoot)
    41  
    42  # Change into that directory
    43  Push-Location $DIR | Out-Null
    44  
    45  # Get the git commit
    46  $GIT_COMMIT = $(git.exe rev-parse HEAD)
    47  git.exe status --porcelain | Out-Null
    48  if ($LastExitCode -eq 0) {
    49      $GIT_DIRTY = "+CHANGES"
    50  } 
    51  
    52  # If its dev mode, only build for ourself
    53  if (Test-Path env:PACKER_DEV) {
    54      $XC_OS=$(go.exe env GOOS)
    55      $XC_ARCH=$(go.exe env GOARCH)
    56  }
    57  elseif (-not (Test-Path env:XC_ARCH)) {
    58      $XC_ARCH="386 amd64 arm"
    59      $XC_OS="linux darwin windows freebsd openbsd"
    60  }
    61  
    62  # Delete the old dir
    63  echo "==> Removing old directory..."
    64  Remove-Item -Recurse -ErrorAction Ignore -Force "bin\"
    65  Remove-Item -Recurse -ErrorAction Ignore -Force "pkg\"
    66  New-Item -Type Directory -Name bin | Out-Null
    67  
    68  # Delete the old dir
    69  echo "==> Building..."
    70  gox.exe `
    71    -os="${XC_OS}" `
    72    -arch="${XC_ARCH}" `
    73    -ldflags "-X github.com/mitchellh/packer/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" `
    74    -output "pkg/{{.OS}}_{{.Arch}}/packer" `
    75    .
    76  
    77  if ($LastExitCode -ne 0) {
    78      exit 1
    79  }
    80  
    81  # Move all the compiled things to the $GOPATH/bin
    82  $GOPATH=$(go.exe env GOPATH)
    83  
    84  # Copy our OS/Arch to the bin/ directory
    85  echo "==> Copying binaries for this platform..."
    86  Get-ChildItem ".\pkg\$(go env GOOS)_$(go env GOARCH)\" `
    87    |? { !($_.PSIsContainer) } `
    88    |% {
    89        Copy-Item $_.FullName "bin\"
    90        Copy-Item $_.FullName "${GOPATH}\bin\"
    91    }
    92  
    93  # Done!
    94  echo "`r`n==> Results:"
    95  Get-ChildItem bin\