File: build.ps1

package info (click to toggle)
packer 1.6.6%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 33,156 kB
  • sloc: sh: 1,154; python: 619; makefile: 251; ruby: 205; xml: 97
file content (103 lines) | stat: -rw-r--r-- 2,618 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<#
    .Synopsis
    Build script for Packer.

    .Description
    Build script for Packer for all supported platforms and architectures.
    By default the following OSs and architectures are targeted.

    OS:
     * linux
     * darwin
     * windows
     * freebsd
     * openbsd

    Architecture:
     * 386
     * amd64
     * arm

    If the environment variable PACKER_DEV is defined, then the OS and
    architecture of the go binary in the path is used.

    The built binary is stamped with the current version number of Packer,
    the latest git commit, and +CHANGES if there are any outstanding
    changes in the current repository, e.g.

      Packer v0.10.1.dev (3c736322ba3a5fcb3a4e92394011a2e56f396da6+CHANGES)

    The build artifacts for the current OS and architecture are copied to
    bin and $GOPATH\bin.

    .Example
    .\scripts\build.ps1
#>

# This script builds the application from source for multiple platforms.

# Get the parent directory of where this script is.
$DIR = [System.IO.Path]::GetDirectoryName($PSScriptRoot)

# Change into that directory
Push-Location $DIR | Out-Null

# Get the git commit
$GIT_COMMIT = $(git.exe rev-parse HEAD)
git.exe status --porcelain | Out-Null
if ($LastExitCode -eq 0) {
    $GIT_DIRTY = "+CHANGES"
}

# If its dev mode, only build for ourself
if (Test-Path env:PACKER_DEV) {
    $XC_OS=$(go.exe env GOOS)
    $XC_ARCH=$(go.exe env GOARCH)
} else {
    if (Test-Path env:XC_ARCH) {
        $XC_ARCH = $(Get-Content env:XC_ARCH)
    } else {
        $XC_ARCH="386 amd64 arm arm64 ppc64le"
    }

    if (Test-Path env:XC_OS) {
        $XC_OS = $(Get-Content env:XC_OS)
    } else {
        $XC_OS = "linux darwin windows freebsd openbsd solaris"
    }
}

# Delete the old dir
echo "==> Removing old directory..."
Remove-Item -Recurse -ErrorAction Ignore -Force "bin\"
Remove-Item -Recurse -ErrorAction Ignore -Force "pkg\"
New-Item -Type Directory -Name bin | Out-Null

# Delete the old dir
echo "==> Building..."
gox.exe `
  -os="${XC_OS}" `
  -arch="${XC_ARCH}" `
  -ldflags "-X github.com/hashicorp/packer/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" `
  -output "pkg/{{.OS}}_{{.Arch}}/packer" `
  .

if ($LastExitCode -ne 0) {
    exit 1
}

# Move all the compiled things to the $GOPATH/bin
$GOPATH=$(go.exe env GOPATH)

# Copy our OS/Arch to the bin/ directory
echo "==> Copying binaries for this platform..."
Get-ChildItem ".\pkg\$(go env GOOS)_$(go env GOARCH)\" `
  |? { !($_.PSIsContainer) } `
  |% {
      Copy-Item $_.FullName "bin\"
      Copy-Item $_.FullName "${GOPATH}\bin\"
  }

# Done!
echo "`r`n==> Results:"
Get-ChildItem bin\