From 5f076d4328a210853b51587c89f59f8342f859ab Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Tue, 7 May 2019 15:58:49 +0200 Subject: [PATCH] allow building packer on solaris by removing progress bar and tty imports fix #7586 --- .circleci/config.yml | 2 +- main.go | 3 +-- packer/progressbar.go | 11 ++--------- packer/progressbar_noop.go | 12 ++++++++++++ packer/progressbar_solaris.go | 3 +++ scripts/build.sh | 2 +- tty.go | 9 +++++++++ tty_solaris.go | 11 +++++++++++ 8 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 packer/progressbar_noop.go create mode 100644 packer/progressbar_solaris.go create mode 100644 tty.go create mode 100644 tty_solaris.go diff --git a/.circleci/config.yml b/.circleci/config.yml index 4be0bbc2c..26436c432 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -57,4 +57,4 @@ workflows: - build_windows - build_freebsd - build_openbsd - \ No newline at end of file + - build_solaris diff --git a/main.go b/main.go index 9ff290f2f..ff4ced0a7 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,6 @@ import ( "github.com/hashicorp/packer/packer/plugin" "github.com/hashicorp/packer/packer/tmp" "github.com/hashicorp/packer/version" - "github.com/mattn/go-tty" "github.com/mitchellh/cli" "github.com/mitchellh/panicwrap" "github.com/mitchellh/prefixedio" @@ -193,7 +192,7 @@ func wrappedMain() int { } ui = basicUi if !inPlugin { - if TTY, err := tty.Open(); err != nil { + if TTY, err := openTTY(); err != nil { fmt.Fprintf(os.Stderr, "No tty available: %s\n", err) } else { basicUi.TTY = TTY diff --git a/packer/progressbar.go b/packer/progressbar.go index fd8c4048b..3328ca9ce 100644 --- a/packer/progressbar.go +++ b/packer/progressbar.go @@ -1,3 +1,5 @@ +// +build !solaris + package packer import ( @@ -78,12 +80,3 @@ type readCloser struct { } func (c *readCloser) Close() error { return c.close() } - -// NoopProgressTracker is a progress tracker -// that displays nothing. -type NoopProgressTracker struct{} - -// TrackProgress returns stream -func (*NoopProgressTracker) TrackProgress(_ string, _, _ int64, stream io.ReadCloser) io.ReadCloser { - return stream -} diff --git a/packer/progressbar_noop.go b/packer/progressbar_noop.go new file mode 100644 index 000000000..e8891afaa --- /dev/null +++ b/packer/progressbar_noop.go @@ -0,0 +1,12 @@ +package packer + +import "io" + +// NoopProgressTracker is a progress tracker +// that displays nothing. +type NoopProgressTracker struct{} + +// TrackProgress returns stream +func (*NoopProgressTracker) TrackProgress(_ string, _, _ int64, stream io.ReadCloser) io.ReadCloser { + return stream +} diff --git a/packer/progressbar_solaris.go b/packer/progressbar_solaris.go new file mode 100644 index 000000000..75b40ad06 --- /dev/null +++ b/packer/progressbar_solaris.go @@ -0,0 +1,3 @@ +package packer + +type uiProgressBar = NoopProgressTracker diff --git a/scripts/build.sh b/scripts/build.sh index a7b779aea..10c5a2b84 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,7 +3,7 @@ # This script builds the application from source for multiple platforms. # Determine the arch/os combos we're building for ALL_XC_ARCH="386 amd64 arm arm64 ppc64le mips mips64 mipsle mipsle64 s390x" -ALL_XC_OS="linux darwin windows freebsd openbsd" +ALL_XC_OS="linux darwin windows freebsd openbsd solaris" # Exit immediately if a command fails set -e diff --git a/tty.go b/tty.go new file mode 100644 index 000000000..85a1c2678 --- /dev/null +++ b/tty.go @@ -0,0 +1,9 @@ +// +build !solaris + +package main + +import ( + "github.com/mattn/go-tty" +) + +var openTTY = tty.Open diff --git a/tty_solaris.go b/tty_solaris.go new file mode 100644 index 000000000..1dd63f044 --- /dev/null +++ b/tty_solaris.go @@ -0,0 +1,11 @@ +package main + +import ( + "fmt" + + "github.com/hashicorp/packer/packer" +) + +func openTTY() (packer.TTY, error) { + return nil, fmt.Errorf("no TTY available on solaris") +}