github.com/aclaygray/packer@v1.3.2/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 } else { 57 if (Test-Path env:XC_ARCH) { 58 $XC_ARCH = $(Get-Content env:XC_ARCH) 59 } else { 60 $XC_ARCH="386 amd64 arm arm64 ppc64le" 61 } 62 63 if (Test-Path env:XC_OS) { 64 $XC_OS = $(Get-Content env:XC_OS) 65 } else { 66 $XC_OS = "linux darwin windows freebsd openbsd solaris" 67 } 68 } 69 70 # Delete the old dir 71 echo "==> Removing old directory..." 72 Remove-Item -Recurse -ErrorAction Ignore -Force "bin\" 73 Remove-Item -Recurse -ErrorAction Ignore -Force "pkg\" 74 New-Item -Type Directory -Name bin | Out-Null 75 76 # Delete the old dir 77 echo "==> Building..." 78 gox.exe ` 79 -os="${XC_OS}" ` 80 -arch="${XC_ARCH}" ` 81 -ldflags "-X github.com/hashicorp/packer/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" ` 82 -output "pkg/{{.OS}}_{{.Arch}}/packer" ` 83 . 84 85 if ($LastExitCode -ne 0) { 86 exit 1 87 } 88 89 # Move all the compiled things to the $GOPATH/bin 90 $GOPATH=$(go.exe env GOPATH) 91 92 # Copy our OS/Arch to the bin/ directory 93 echo "==> Copying binaries for this platform..." 94 Get-ChildItem ".\pkg\$(go env GOOS)_$(go env GOARCH)\" ` 95 |? { !($_.PSIsContainer) } ` 96 |% { 97 Copy-Item $_.FullName "bin\" 98 Copy-Item $_.FullName "${GOPATH}\bin\" 99 } 100 101 # Done! 102 echo "`r`n==> Results:" 103 Get-ChildItem bin\