View | Details | Raw Unified | Return to bug 244931
Collapse All | Expand All

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

Return to bug 244931