Improve package compilation and installation handling

This commit is contained in:
2025-09-04 12:01:59 +03:00
parent 3b5c8de115
commit 3cfb314333
3 changed files with 30 additions and 31 deletions
+3 -2
View File
@@ -2,7 +2,8 @@ module git.enumerated.dev/bubble-package-manager/bpm-utils/src/bpm-package
go 1.23 go 1.23
require gopkg.in/yaml.v3 v3.0.1 // indirect require gopkg.in/yaml.v3 v3.0.1
require bpm-utils-shared v1.0.0 require bpm-utils-shared v1.0.0
replace bpm-utils-shared => ../bpm-utils-shared replace bpm-utils-shared => ../bpm-utils-shared
+1
View File
@@ -1,3 +1,4 @@
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+26 -29
View File
@@ -2,16 +2,16 @@ package main
import ( import (
bpmutilsshared "bpm-utils-shared" bpmutilsshared "bpm-utils-shared"
"bufio"
"flag" "flag"
"fmt" "fmt"
"gopkg.in/yaml.v3"
"io" "io"
"log" "log"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"gopkg.in/yaml.v3"
) )
var compile = flag.Bool("c", false, "Compile BPM source package") var compile = flag.Bool("c", false, "Compile BPM source package")
@@ -127,14 +127,23 @@ func compilePackage(archive string) {
if *yesAll { if *yesAll {
args = append(args, "-y") args = append(args, "-y")
} }
if *installPackage {
args = append(args, "--fd=3")
}
args = append(args, archive) args = append(args, archive)
cmd := exec.Command("bpm", args...) cmd := exec.Command("bpm", args...)
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
pipe, err := cmd.StdoutPipe()
// Set output pipe for file descriptor 3
cmdOutputReader, cmdOutputWriter, err := os.Pipe()
if err != nil { if err != nil {
log.Fatalf("Error: could not setup stdout pipe: %s", err) log.Fatalf("Error: failed to create pipe: %s", err)
} }
defer cmdOutputReader.Close()
defer cmdOutputWriter.Close()
cmd.ExtraFiles = append(cmd.ExtraFiles, cmdOutputWriter)
// Run command // Run command
err = cmd.Start() err = cmd.Start()
@@ -142,37 +151,25 @@ func compilePackage(archive string) {
log.Fatalf("Error: failed to compile BPM source package: %s", err) log.Fatalf("Error: failed to compile BPM source package: %s", err)
} }
// Print command output and store it in variable
pipeOutput := ""
buf := bufio.NewReader(pipe)
for {
b, err := buf.ReadByte()
if err == io.EOF {
break
} else if err != nil {
log.Fatalf("Error: failed to read byte from command: %s", err)
}
pipeOutput += string(b)
fmt.Print(string(b))
}
fmt.Println()
// Put output file into slice
outputFiles := make([]string, 0)
for _, line := range strings.Split(pipeOutput, "\n") {
if strings.Contains(line, "Binary package generated at: ") {
path := strings.TrimSpace(strings.SplitN(line, ":", 2)[1])
outputFiles = append(outputFiles, path)
}
}
// Wait for process to complete // Wait for process to complete
err = cmd.Wait() err = cmd.Wait()
if err != nil { if err != nil {
log.Fatalf("Error: failed to compile BPM source package: %s", err) log.Fatalf("Error: failed to compile BPM source package: %s", err)
} }
// Read cmd output
cmdOutputWriter.Close()
cmdOutput, err := io.ReadAll(cmdOutputReader)
if err != nil {
log.Fatalf("Error: failed to get cmd output: %s", err)
}
// Put output file into slice
outputFiles := make([]string, 0)
for _, line := range strings.Split(strings.TrimSpace(string(cmdOutput)), "\n") {
outputFiles = append(outputFiles, line)
}
// Install compiled packages // Install compiled packages
if *installPackage && len(outputFiles) != 0 { if *installPackage && len(outputFiles) != 0 {
// Read BPM utils config // Read BPM utils config