Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#113: disable pty on windows #114

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/gbc/artifact/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (plugin Plugin) install() (string, error) {
return pair
})
task := fmt.Sprintf("%s installation", plugin.Name())
if err := StreamCmdOutput(cmd, task, func(msg string) string {
if err := PtyCmdOutput(cmd, task, func(msg string) string {
return ""
}); err != nil {
return tempGoPath, err
Expand Down Expand Up @@ -160,7 +160,7 @@ func (plugin Plugin) Execute() error {
}
// always use absolute path
pCmd := exec.Command(filepath.Join(GoPath(), plugin.Binary()), strings.Split(plugin.Args, " ")...) //nolint #gosec
if err := StreamCmdOutput(pCmd, plugin.taskName(), nil); err != nil {
if err := PtyCmdOutput(pCmd, plugin.taskName(), nil); err != nil {
return err
}
if pCmd.ProcessState.ExitCode() != 0 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/gbc/artifact/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func init() {
log.Fatal(color.RedString("please execute command in project root directory %s", string(output)))
}
cfg := &packages.Config{
Mode: packages.NeedName | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedFiles | packages.NeedTypesInfo | packages.NeedDeps | packages.NeedImports | packages.NeedSyntax,
Mode: packages.NeedName | packages.NeedTypes | packages.NeedFiles | packages.NeedTypesInfo,
Dir: project.root,
}
project.pkgs, err = packages.Load(cfg, "./...")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package artifact
import (
"bufio"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
Expand All @@ -18,17 +19,19 @@ import (

type consoleFormatter func(msg string) string

func StreamCmdOutput(cmd *exec.Cmd, task string, formatter consoleFormatter) error {
func PtyCmdOutput(cmd *exec.Cmd, task string, formatter consoleFormatter) error {
// Start the command with a pty
var scanner *bufio.Scanner
if ptmx, err := pty.Start(cmd); err == nil {
scanner = bufio.NewScanner(ptmx)
defer ptmx.Close()
} else if rd, err := cmd.StdoutPipe(); err == nil {
scanner = bufio.NewScanner(rd)
} else {
rc, err := func() (io.ReadCloser, error) {
if Windows() {
return cmd.StdoutPipe()
}
return pty.Start(cmd)
}()
if err != nil {
return err
}
defer rc.Close()
scanner := bufio.NewScanner(rc)
color.Green("start %s ......\n", task)
// Create a file to save the output
log, err := os.Create(filepath.Join(CurProject().Target(), fmt.Sprintf("%s.log", strings.ReplaceAll(task, " ", "_"))))
Expand Down
2 changes: 1 addition & 1 deletion cmd/gbc/command/build_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func cleanAction(_ *cobra.Command, _ ...string) error {
func testAction(_ *cobra.Command, _ ...string) error {
coverProfile := fmt.Sprintf("-coverprofile=%s/cover.out", artifact.CurProject().Target())
testCmd := exec.Command("go", []string{"test", "-v", coverProfile, "./..."}...) //nolint
return artifact.StreamCmdOutput(testCmd, "test", nil)
return artifact.PtyCmdOutput(testCmd, "test", nil)
}

func coverReport(_ *cobra.Command, _ ...string) error {
Expand Down
Loading