diff --git sysutils/packer/Makefile sysutils/packer/Makefile index 6f88a0449cc1..dfb631dc1062 100644 --- sysutils/packer/Makefile +++ sysutils/packer/Makefile @@ -2,6 +2,7 @@ PORTNAME= packer PORTVERSION= 1.5.1 +PORTREVISION= 1 DISTVERSIONPREFIX= v CATEGORIES= sysutils @@ -18,4 +19,10 @@ USES= go:modules USE_GITHUB= yes GH_ACCOUNT= hashicorp -.include +.include + +post-patch: + ${MKDIR} ${WRKSRC}/helper/wrappedstreams + ${MV} ${WRKSRC}/streams* ${WRKSRC}/helper/wrappedstreams/ + +.include diff --git sysutils/packer/files/patch-command_console.go sysutils/packer/files/patch-command_console.go new file mode 100644 index 000000000000..f74fbf019b70 --- /dev/null +++ sysutils/packer/files/patch-command_console.go @@ -0,0 +1,19 @@ +--- command/console.go.orig 2019-12-20 19:14:09 UTC ++++ command/console.go +@@ -9,6 +9,7 @@ import ( + + "github.com/chzyer/readline" + "github.com/hashicorp/packer/helper/wrappedreadline" ++ "github.com/hashicorp/packer/helper/wrappedstreams" + "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/template" + "github.com/hashicorp/packer/template/interpolate" +@@ -115,7 +116,7 @@ func (*ConsoleCommand) AutocompleteFlags() complete.Fl + + func (c *ConsoleCommand) modePiped(session *REPLSession) int { + var lastResult string +- scanner := bufio.NewScanner(wrappedreadline.Stdin()) ++ scanner := bufio.NewScanner(wrappedstreams.Stdin()) + for scanner.Scan() { + result, err := session.Handle(strings.TrimSpace(scanner.Text())) + if err != nil { diff --git sysutils/packer/files/patch-command_meta.go sysutils/packer/files/patch-command_meta.go new file mode 100644 index 000000000000..45e77f4292ad --- /dev/null +++ sysutils/packer/files/patch-command_meta.go @@ -0,0 +1,20 @@ +--- command/meta.go.orig 2019-12-20 19:14:09 UTC ++++ command/meta.go +@@ -9,7 +9,7 @@ import ( + + kvflag "github.com/hashicorp/packer/helper/flag-kv" + sliceflag "github.com/hashicorp/packer/helper/flag-slice" +- "github.com/hashicorp/packer/helper/wrappedreadline" ++ "github.com/hashicorp/packer/helper/wrappedstreams" + "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/template" + ) +@@ -145,7 +145,7 @@ func (m *Meta) ValidateFlags() error { + + // StdinPiped returns true if the input is piped. + func (m *Meta) StdinPiped() bool { +- fi, err := wrappedreadline.Stdin().Stat() ++ fi, err := wrappedstreams.Stdin().Stat() + if err != nil { + // If there is an error, let's just say its not piped + return false diff --git sysutils/packer/files/patch-helper_wrappedreadline_wrappedreadline.go sysutils/packer/files/patch-helper_wrappedreadline_wrappedreadline.go new file mode 100644 index 000000000000..d627271d24be --- /dev/null +++ sysutils/packer/files/patch-helper_wrappedreadline_wrappedreadline.go @@ -0,0 +1,101 @@ +--- helper/wrappedreadline/wrappedreadline.go.orig 2019-12-20 19:14:09 UTC ++++ helper/wrappedreadline/wrappedreadline.go +@@ -1,6 +1,8 @@ +-// Shamelessly copied from the Terraform repo because it wasn't worth vendoring +-// out two hundred lines of code so Packer could use it too. ++// STOLEN SHAMELESSLY FROM THE TERRAFORM REPO BECAUSE VENDORING OUT ++// WRAPPEDREADLINE AND WRAPPEDSTREAMS FELT LIKE TOO MUCH WORK. + // ++// "a little copying is better than a lot of dependency" ++// + // wrappedreadline is a package that has helpers for interacting with + // readline from a panicwrap executable. + // +@@ -13,24 +15,24 @@ + package wrappedreadline + + import ( +- "os" + "runtime" + + "github.com/chzyer/readline" +- "github.com/mitchellh/panicwrap" ++ ++ "github.com/hashicorp/packer/helper/wrappedstreams" + ) + + // Override overrides the values in readline.Config that need to be + // set with wrapped values. + func Override(cfg *readline.Config) *readline.Config { +- cfg.Stdin = Stdin() +- cfg.Stdout = Stdout() +- cfg.Stderr = Stderr() ++ cfg.Stdin = wrappedstreams.Stdin() ++ cfg.Stdout = wrappedstreams.Stdout() ++ cfg.Stderr = wrappedstreams.Stderr() + + cfg.FuncGetWidth = TerminalWidth + cfg.FuncIsTerminal = IsTerminal + +- rm := RawMode{StdinFd: int(Stdin().Fd())} ++ rm := RawMode{StdinFd: int(wrappedstreams.Stdin().Fd())} + cfg.FuncMakeRaw = rm.Enter + cfg.FuncExitRaw = rm.Exit + +@@ -45,9 +47,9 @@ func IsTerminal() bool { + } + + // Same implementation as readline but with our custom fds +- return readline.IsTerminal(int(Stdin().Fd())) && +- (readline.IsTerminal(int(Stdout().Fd())) || +- readline.IsTerminal(int(Stderr().Fd()))) ++ return readline.IsTerminal(int(wrappedstreams.Stdin().Fd())) && ++ (readline.IsTerminal(int(wrappedstreams.Stdout().Fd())) || ++ readline.IsTerminal(int(wrappedstreams.Stderr().Fd()))) + } + + // TerminalWidth gets the terminal width in characters. +@@ -78,43 +80,3 @@ func (r *RawMode) Exit() error { + + return readline.Restore(r.StdinFd, r.state) + } +- +-// Package provides access to the standard OS streams +-// (stdin, stdout, stderr) even if wrapped under panicwrap. +-// Stdin returns the true stdin of the process. +-func Stdin() *os.File { +- stdin := os.Stdin +- if panicwrap.Wrapped(nil) { +- stdin = wrappedStdin +- } +- +- return stdin +-} +- +-// Stdout returns the true stdout of the process. +-func Stdout() *os.File { +- stdout := os.Stdout +- if panicwrap.Wrapped(nil) { +- stdout = wrappedStdout +- } +- +- return stdout +-} +- +-// Stderr returns the true stderr of the process. +-func Stderr() *os.File { +- stderr := os.Stderr +- if panicwrap.Wrapped(nil) { +- stderr = wrappedStderr +- } +- +- return stderr +-} +- +-// These are the wrapped standard streams. These are setup by the +-// platform specific code in initPlatform. +-var ( +- wrappedStdin *os.File +- wrappedStdout *os.File +- wrappedStderr *os.File +-) diff --git sysutils/packer/files/patch-helper_wrappedreadline_wrappedreadline__unix.go sysutils/packer/files/patch-helper_wrappedreadline_wrappedreadline__unix.go new file mode 100644 index 000000000000..d14c10eac97b --- /dev/null +++ sysutils/packer/files/patch-helper_wrappedreadline_wrappedreadline__unix.go @@ -0,0 +1,34 @@ +--- helper/wrappedreadline/wrappedreadline_unix.go.orig 2019-12-20 19:14:09 UTC ++++ helper/wrappedreadline/wrappedreadline_unix.go +@@ -3,15 +3,16 @@ + package wrappedreadline + + import ( +- "os" + "syscall" + "unsafe" ++ ++ "github.com/hashicorp/packer/helper/wrappedstreams" + ) + + // getWidth impl for Unix + func getWidth() int { +- stdoutFd := int(Stdout().Fd()) +- stderrFd := int(Stderr().Fd()) ++ stdoutFd := int(wrappedstreams.Stdout().Fd()) ++ stderrFd := int(wrappedstreams.Stderr().Fd()) + + w := getWidthFd(stdoutFd) + if w < 0 { +@@ -42,11 +43,4 @@ func getWidthFd(stdoutFd int) int { + } + + return int(ws.Col) +-} +- +-func init() { +- // The standard streams are passed in via extra file descriptors. +- wrappedStdin = os.NewFile(uintptr(3), "stdin") +- wrappedStdout = os.NewFile(uintptr(4), "stdout") +- wrappedStderr = os.NewFile(uintptr(5), "stderr") + } diff --git sysutils/packer/files/patch-helper_wrappedreadline_wrappedreadline__windows.go sysutils/packer/files/patch-helper_wrappedreadline_wrappedreadline__windows.go new file mode 100644 index 000000000000..e8cfab574652 --- /dev/null +++ sysutils/packer/files/patch-helper_wrappedreadline_wrappedreadline__windows.go @@ -0,0 +1,59 @@ +--- helper/wrappedreadline/wrappedreadline_windows.go.orig 2019-12-20 19:14:09 UTC ++++ helper/wrappedreadline/wrappedreadline_windows.go +@@ -2,56 +2,7 @@ + + package wrappedreadline + +-import ( +- "log" +- "os" +- "syscall" +-) +- + // getWidth impl for other + func getWidth() int { + return 0 +-} +- +-func init() { +- wrappedStdin = openConsole("CONIN$", os.Stdin) +- wrappedStdout = openConsole("CONOUT$", os.Stdout) +- wrappedStderr = wrappedStdout +-} +- +-// openConsole opens a console handle, using a backup if it fails. +-// This is used to get the exact console handle instead of the redirected +-// handles from panicwrap. +-func openConsole(name string, backup *os.File) *os.File { +- // Convert to UTF16 +- path, err := syscall.UTF16PtrFromString(name) +- if err != nil { +- log.Printf("[ERROR] wrappedstreams: %s", err) +- return backup +- } +- +- // Determine the share mode +- var shareMode uint32 +- switch name { +- case "CONIN$": +- shareMode = syscall.FILE_SHARE_READ +- case "CONOUT$": +- shareMode = syscall.FILE_SHARE_WRITE +- } +- +- // Get the file +- h, err := syscall.CreateFile( +- path, +- syscall.GENERIC_READ|syscall.GENERIC_WRITE, +- shareMode, +- nil, +- syscall.OPEN_EXISTING, +- 0, 0) +- if err != nil { +- log.Printf("[ERROR] wrappedstreams: %s", err) +- return backup +- } +- +- // Create the Go file +- return os.NewFile(uintptr(h), name) + } diff --git sysutils/packer/files/patch-streams.go sysutils/packer/files/patch-streams.go new file mode 100644 index 000000000000..2409be32d9c3 --- /dev/null +++ sysutils/packer/files/patch-streams.go @@ -0,0 +1,52 @@ +--- streams.go.orig 2020-04-09 22:22:46 UTC ++++ streams.go +@@ -0,0 +1,49 @@ ++// STOLEN SHAMELESSLY FROM THE TERRAFORM REPO BECAUSE VENDORING OUT ++// WRAPPEDREADLINE AND WRAPPEDSTREAMS FELT LIKE TOO MUCH WORK. ++// ++// "a little copying is better than a lot of dependency" ++// ++// Package wrappedstreams provides access to the standard OS streams ++// (stdin, stdout, stderr) even if wrapped under panicwrap. ++package wrappedstreams ++ ++import ( ++ "os" ++ ++ "github.com/mitchellh/panicwrap" ++) ++ ++// Stdin returns the true stdin of the process. ++func Stdin() *os.File { ++ stdin, _, _ := fds() ++ return stdin ++} ++ ++// Stdout returns the true stdout of the process. ++func Stdout() *os.File { ++ _, stdout, _ := fds() ++ return stdout ++} ++ ++// Stderr returns the true stderr of the process. ++func Stderr() *os.File { ++ _, _, stderr := fds() ++ return stderr ++} ++ ++func fds() (stdin, stdout, stderr *os.File) { ++ stdin, stdout, stderr = os.Stdin, os.Stdout, os.Stderr ++ if panicwrap.Wrapped(nil) { ++ initPlatform() ++ stdin, stdout, stderr = wrappedStdin, wrappedStdout, wrappedStderr ++ } ++ return ++} ++ ++// These are the wrapped standard streams. These are setup by the ++// platform specific code in initPlatform. ++var ( ++ wrappedStdin *os.File ++ wrappedStdout *os.File ++ wrappedStderr *os.File ++) diff --git sysutils/packer/files/patch-streams__other.go sysutils/packer/files/patch-streams__other.go new file mode 100644 index 000000000000..b50128b97e33 --- /dev/null +++ sysutils/packer/files/patch-streams__other.go @@ -0,0 +1,24 @@ +--- streams_other.go.orig 2020-04-09 22:22:46 UTC ++++ streams_other.go +@@ -0,0 +1,21 @@ ++// +build !windows ++ ++package wrappedstreams ++ ++import ( ++ "os" ++ "sync" ++) ++ ++var initOnce sync.Once ++ ++func initPlatform() { ++ // These must be initialized lazily, once it's been determined that this is ++ // a wrapped process. ++ initOnce.Do(func() { ++ // The standard streams are passed in via extra file descriptors. ++ wrappedStdin = os.NewFile(uintptr(3), "stdin") ++ wrappedStdout = os.NewFile(uintptr(4), "stdout") ++ wrappedStderr = os.NewFile(uintptr(5), "stderr") ++ }) ++} diff --git sysutils/packer/files/patch-streams__windows.go sysutils/packer/files/patch-streams__windows.go new file mode 100644 index 000000000000..27c15bc82f2f --- /dev/null +++ sysutils/packer/files/patch-streams__windows.go @@ -0,0 +1,55 @@ +--- streams_windows.go.orig 2020-04-09 22:22:46 UTC ++++ streams_windows.go +@@ -0,0 +1,52 @@ ++// +build windows ++ ++package wrappedstreams ++ ++import ( ++ "log" ++ "os" ++ "syscall" ++) ++ ++func initPlatform() { ++ wrappedStdin = openConsole("CONIN$", os.Stdin) ++ wrappedStdout = openConsole("CONOUT$", os.Stdout) ++ wrappedStderr = wrappedStdout ++} ++ ++// openConsole opens a console handle, using a backup if it fails. ++// This is used to get the exact console handle instead of the redirected ++// handles from panicwrap. ++func openConsole(name string, backup *os.File) *os.File { ++ // Convert to UTF16 ++ path, err := syscall.UTF16PtrFromString(name) ++ if err != nil { ++ log.Printf("[ERROR] wrappedstreams: %s", err) ++ return backup ++ } ++ ++ // Determine the share mode ++ var shareMode uint32 ++ switch name { ++ case "CONIN$": ++ shareMode = syscall.FILE_SHARE_READ ++ case "CONOUT$": ++ shareMode = syscall.FILE_SHARE_WRITE ++ } ++ ++ // Get the file ++ h, err := syscall.CreateFile( ++ path, ++ syscall.GENERIC_READ|syscall.GENERIC_WRITE, ++ shareMode, ++ nil, ++ syscall.OPEN_EXISTING, ++ 0, 0) ++ if err != nil { ++ log.Printf("[ERROR] wrappedstreams: %s", err) ++ return backup ++ } ++ ++ // Create the Go file ++ return os.NewFile(uintptr(h), name) ++}