common_regular.go 649 B

123456789101112131415161718192021222324252627282930313233
  1. // +build !coverage
  2. package scenarios
  3. import (
  4. "bytes"
  5. "fmt"
  6. "os"
  7. "os/exec"
  8. )
  9. func BuildXray() error {
  10. genTestBinaryPath()
  11. if _, err := os.Stat(testBinaryPath); err == nil {
  12. return nil
  13. }
  14. fmt.Printf("Building Xray into path (%s)\n", testBinaryPath)
  15. cmd := exec.Command("go", "build", "-o="+testBinaryPath, GetSourcePath())
  16. cmd.Stdout = os.Stdout
  17. cmd.Stderr = os.Stderr
  18. return cmd.Run()
  19. }
  20. func RunXrayProtobuf(config []byte) *exec.Cmd {
  21. genTestBinaryPath()
  22. proc := exec.Command(testBinaryPath, "-config=stdin:", "-format=pb")
  23. proc.Stdin = bytes.NewBuffer(config)
  24. proc.Stderr = os.Stderr
  25. proc.Stdout = os.Stdout
  26. return proc
  27. }