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