mirror of
https://github.com/EnumeratedDev/bpm-utils.git
synced 2026-09-17 03:26:10 +00:00
Compare commits
4
Commits
3f84dd4bc3
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66e1aacc5f
|
||
|
|
8034c7d7ea
|
||
|
|
d781c30146
|
||
|
|
8eb771111c
|
+113
-54
@@ -5,6 +5,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"maps"
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
@@ -21,9 +22,10 @@ import (
|
|||||||
|
|
||||||
var compile = flag.BoolP("compile", "c", false, "Compile BPM source package")
|
var compile = flag.BoolP("compile", "c", false, "Compile BPM source package")
|
||||||
var verbose = flag.BoolP("verbose", "v", false, "Show additional information about the compilation process")
|
var verbose = flag.BoolP("verbose", "v", false, "Show additional information about the compilation process")
|
||||||
var skipCheck = flag.Bool("skip-checks", false, "Skip 'check' function while compiling")
|
var skipChecks = flag.Bool("skip-checks", false, "Skip 'check' function while compiling")
|
||||||
var keepCompilationFiles = flag.BoolP("keep", "k", false, "Keep compilation files after successful package compilation")
|
var keepCompilationFiles = flag.BoolP("keep", "k", false, "Keep compilation files after successful package compilation")
|
||||||
var installDepends = flag.BoolP("depends", "d", false, "Install package dependencies for compilation")
|
var installDepends = flag.BoolP("depends", "d", false, "Install package dependencies for compilation")
|
||||||
|
var force = flag.BoolP("force", "f", false, "Bypass warnings during package compilation")
|
||||||
var installPackage = flag.BoolP("install", "i", false, "Install compiled BPM package after compilation finishes")
|
var installPackage = flag.BoolP("install", "i", false, "Install compiled BPM package after compilation finishes")
|
||||||
var compilationJobs = flag.IntP("jobs", "j", 0, "Set the amount of concurrent processes to use for source package compilation")
|
var compilationJobs = flag.IntP("jobs", "j", 0, "Set the amount of concurrent processes to use for source package compilation")
|
||||||
var updateInfo = flag.BoolP("update-info", "u", false, "Update the info.yml file")
|
var updateInfo = flag.BoolP("update-info", "u", false, "Update the info.yml file")
|
||||||
@@ -143,22 +145,12 @@ func createArchive() string {
|
|||||||
|
|
||||||
// Remove old package from source dir
|
// Remove old package from source dir
|
||||||
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
||||||
if database, err := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb")); err == nil {
|
removedFiles, err := RemoveSourcePackage(repo, pkgInfo.Name)
|
||||||
if entry, ok := database.Entries[pkgInfo.Name]; ok {
|
for _, file := range removedFiles {
|
||||||
pkgFilepath := path.Join(repo, "source", entry.Filepath)
|
fmt.Println("Removed " + file)
|
||||||
err := os.Remove(pkgFilepath)
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Warning: could not remove old source package (%s): %s", pkgFilepath, err)
|
log.Printf("Warning: could not remove old source packages: %s", err)
|
||||||
}
|
|
||||||
|
|
||||||
// Remove package signature
|
|
||||||
if _, err := os.Stat(pkgFilepath + ".sig"); err == nil {
|
|
||||||
err := os.Remove(pkgFilepath + ".sig")
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Warning: could not remove old source package signature (%s): %s", pkgFilepath+".str", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +179,7 @@ func createArchive() string {
|
|||||||
|
|
||||||
// Sign package
|
// Sign package
|
||||||
if *signPackage {
|
if *signPackage {
|
||||||
cmd := exec.Command("gpg", "--detach-sign", filename)
|
cmd := exec.Command("gpg", "--yes", "--detach-sign", filename)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
@@ -212,24 +204,18 @@ func compilePackage(archive string) {
|
|||||||
// Setup compile command
|
// Setup compile command
|
||||||
args := make([]string, 0)
|
args := make([]string, 0)
|
||||||
args = append(args, "compile")
|
args = append(args, "compile")
|
||||||
if *verbose {
|
addArg := func(condition bool, arg string) {
|
||||||
args = append(args, "-v")
|
if condition {
|
||||||
}
|
args = append(args, arg)
|
||||||
if *skipCheck {
|
}
|
||||||
args = append(args, "-s")
|
|
||||||
}
|
|
||||||
if *keepCompilationFiles {
|
|
||||||
args = append(args, "-k")
|
|
||||||
}
|
|
||||||
if *installDepends {
|
|
||||||
args = append(args, "-d")
|
|
||||||
}
|
|
||||||
if *compilationJobs > 0 {
|
|
||||||
args = append(args, "-j"+strconv.Itoa(*compilationJobs))
|
|
||||||
}
|
|
||||||
if *yesAll {
|
|
||||||
args = append(args, "-y")
|
|
||||||
}
|
}
|
||||||
|
addArg(*verbose, "-v")
|
||||||
|
addArg(*skipChecks, "--skip-checks")
|
||||||
|
addArg(*keepCompilationFiles, "-k")
|
||||||
|
addArg(*installDepends, "-d")
|
||||||
|
addArg(*compilationJobs > 0, "-j"+strconv.Itoa(*compilationJobs))
|
||||||
|
addArg(*yesAll, "-y")
|
||||||
|
addArg(*force, "-f")
|
||||||
args = append(args, "--output-fd=3")
|
args = append(args, "--output-fd=3")
|
||||||
args = append(args, archive)
|
args = append(args, archive)
|
||||||
cmd := exec.Command("bpm", args...)
|
cmd := exec.Command("bpm", args...)
|
||||||
@@ -270,31 +256,22 @@ func compilePackage(archive string) {
|
|||||||
for _, line := range strings.Split(strings.TrimSpace(string(cmdOutput)), "\n") {
|
for _, line := range strings.Split(strings.TrimSpace(string(cmdOutput)), "\n") {
|
||||||
// Read generated package info
|
// Read generated package info
|
||||||
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromTarball(line)
|
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromTarball(line)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error: could not read package info: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
||||||
// Remove old package from binary dir
|
// Remove old package from binary dir
|
||||||
if database, err := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb")); err == nil {
|
|
||||||
if entry, ok := database.Entries[pkgInfo.Name]; ok {
|
|
||||||
pkgFilepath := path.Join(repo, "binary", entry.Filepath)
|
|
||||||
err := os.Remove(pkgFilepath)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Warning: could not remove old binary package (%s): %s", pkgFilepath, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove package signature
|
removedFiles, err := RemoveBinaryPackage(repo, pkgInfo.Name)
|
||||||
if _, err := os.Stat(pkgFilepath + ".sig"); err == nil {
|
for _, file := range removedFiles {
|
||||||
err := os.Remove(pkgFilepath + ".sig")
|
fmt.Println("Removed " + file)
|
||||||
if err != nil {
|
}
|
||||||
log.Printf("Warning: could not remove old binary package signature (%s): %s", pkgFilepath+".str", err)
|
if err != nil {
|
||||||
}
|
log.Printf("Warning: could not remove old binary packages: %s", err)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move package to binary dir
|
// Move package to binary dir
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error: could not read package info: %s", err)
|
|
||||||
}
|
|
||||||
newPath := path.Join(repo, "binary", pkgInfo.Arch, path.Base(line))
|
newPath := path.Join(repo, "binary", pkgInfo.Arch, path.Base(line))
|
||||||
os.MkdirAll(path.Dir(newPath), 0755)
|
os.MkdirAll(path.Dir(newPath), 0755)
|
||||||
os.Rename(line, newPath)
|
os.Rename(line, newPath)
|
||||||
@@ -308,7 +285,7 @@ func compilePackage(archive string) {
|
|||||||
// Sign package
|
// Sign package
|
||||||
if *signPackage {
|
if *signPackage {
|
||||||
for k, v := range outputPkgs {
|
for k, v := range outputPkgs {
|
||||||
cmd := exec.Command("gpg", "--detach-sign", v)
|
cmd := exec.Command("gpg", "--yes", "--detach-sign", v)
|
||||||
cmd.Dir = path.Dir(v)
|
cmd.Dir = path.Dir(v)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
@@ -364,3 +341,85 @@ func setupFlagsAndHelp(usage, desc string) {
|
|||||||
}
|
}
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RemoveSourcePackage(repo, pkgName string) (removedFiles []string, err error) {
|
||||||
|
if _, err := os.Stat(path.Join(repo, "source")); err != nil {
|
||||||
|
return removedFiles, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err = filepath.Walk(path.Join(repo, "source"), func(packagePath string, info fs.FileInfo, err error) error {
|
||||||
|
if !strings.HasSuffix(packagePath, ".bpm") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get package info
|
||||||
|
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromTarball(packagePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if pkgInfo.Name != pkgName {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove package and its signature
|
||||||
|
err = os.Remove(packagePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if relPath, err := filepath.Rel(repo, packagePath); err != nil {
|
||||||
|
removedFiles = append(removedFiles, packagePath)
|
||||||
|
} else {
|
||||||
|
removedFiles = append(removedFiles, relPath)
|
||||||
|
}
|
||||||
|
err = os.Remove(packagePath + ".sig")
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return removedFiles, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveBinaryPackage(repo, pkgName string) (removedFiles []string, err error) {
|
||||||
|
if _, err := os.Stat(path.Join(repo, "binary")); err != nil {
|
||||||
|
return removedFiles, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err = filepath.Walk(path.Join(repo, "binary"), func(packagePath string, info fs.FileInfo, err error) error {
|
||||||
|
if !strings.HasSuffix(packagePath, ".bpm") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get package info
|
||||||
|
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromTarball(packagePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if pkgInfo.Name != pkgName {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove package and its signature
|
||||||
|
err = os.Remove(packagePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if relPath, err := filepath.Rel(repo, packagePath); err != nil {
|
||||||
|
removedFiles = append(removedFiles, packagePath)
|
||||||
|
} else {
|
||||||
|
removedFiles = append(removedFiles, relPath)
|
||||||
|
}
|
||||||
|
err = os.Remove(packagePath + ".sig")
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return removedFiles, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,10 +33,27 @@ type PackageInfo struct {
|
|||||||
Replaces []string `yaml:"replaces,omitempty"`
|
Replaces []string `yaml:"replaces,omitempty"`
|
||||||
Provides []string `yaml:"provides,omitempty"`
|
Provides []string `yaml:"provides,omitempty"`
|
||||||
Options []string `yaml:"options,omitempty"`
|
Options []string `yaml:"options,omitempty"`
|
||||||
|
Flags []PackageFlag `yaml:"flags,omitempty"`
|
||||||
Downloads []PackageDownload `yaml:"downloads,omitempty"`
|
Downloads []PackageDownload `yaml:"downloads,omitempty"`
|
||||||
SplitPackages []*PackageInfo `yaml:"split_packages,omitempty"`
|
SplitPackages []*PackageInfo `yaml:"split_packages,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PackageFlag struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
DefaultValue string `yaml:"default_value"`
|
||||||
|
BuiltValue string `yaml:"built_value"`
|
||||||
|
AcceptedValues []PackageAcceptedValue `yaml:"accepted_values,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PackageAcceptedValue struct {
|
||||||
|
Value string `yaml:"value"`
|
||||||
|
Depends []string `yaml:"depends,omitempty"`
|
||||||
|
RuntimeDepends []string `yaml:"runtime_depends,omitempty"`
|
||||||
|
OptionalDepends []string `yaml:"optional_depends,omitempty"`
|
||||||
|
MakeDepends []string `yaml:"make_depends,omitempty"`
|
||||||
|
CheckDepends []string `yaml:"check_depends,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type PackageDownload struct {
|
type PackageDownload struct {
|
||||||
Url string `yaml:"url"`
|
Url string `yaml:"url"`
|
||||||
Type string `yaml:"type,omitempty"`
|
Type string `yaml:"type,omitempty"`
|
||||||
|
|||||||
Reference in New Issue
Block a user