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"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log"
|
||||
"maps"
|
||||
"os"
|
||||
@@ -21,9 +22,10 @@ import (
|
||||
|
||||
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 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 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 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")
|
||||
@@ -143,22 +145,12 @@ func createArchive() string {
|
||||
|
||||
// Remove old package from source dir
|
||||
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
||||
if database, err := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb")); err == nil {
|
||||
if entry, ok := database.Entries[pkgInfo.Name]; ok {
|
||||
pkgFilepath := path.Join(repo, "source", entry.Filepath)
|
||||
err := os.Remove(pkgFilepath)
|
||||
if err != nil {
|
||||
log.Printf("Warning: could not remove old source package (%s): %s", pkgFilepath, 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
removedFiles, err := RemoveSourcePackage(repo, pkgInfo.Name)
|
||||
for _, file := range removedFiles {
|
||||
fmt.Println("Removed " + file)
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("Warning: could not remove old source packages: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +179,7 @@ func createArchive() string {
|
||||
|
||||
// Sign package
|
||||
if *signPackage {
|
||||
cmd := exec.Command("gpg", "--detach-sign", filename)
|
||||
cmd := exec.Command("gpg", "--yes", "--detach-sign", filename)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdin = os.Stdin
|
||||
@@ -212,24 +204,18 @@ func compilePackage(archive string) {
|
||||
// Setup compile command
|
||||
args := make([]string, 0)
|
||||
args = append(args, "compile")
|
||||
if *verbose {
|
||||
args = append(args, "-v")
|
||||
}
|
||||
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 := func(condition bool, arg string) {
|
||||
if condition {
|
||||
args = append(args, arg)
|
||||
}
|
||||
}
|
||||
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, archive)
|
||||
cmd := exec.Command("bpm", args...)
|
||||
@@ -270,31 +256,22 @@ func compilePackage(archive string) {
|
||||
for _, line := range strings.Split(strings.TrimSpace(string(cmdOutput)), "\n") {
|
||||
// Read generated package info
|
||||
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromTarball(line)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not read package info: %s", err)
|
||||
}
|
||||
|
||||
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
||||
// 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
|
||||
if _, err := os.Stat(pkgFilepath + ".sig"); err == nil {
|
||||
err := os.Remove(pkgFilepath + ".sig")
|
||||
if err != nil {
|
||||
log.Printf("Warning: could not remove old binary package signature (%s): %s", pkgFilepath+".str", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
removedFiles, err := RemoveBinaryPackage(repo, pkgInfo.Name)
|
||||
for _, file := range removedFiles {
|
||||
fmt.Println("Removed " + file)
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("Warning: could not remove old binary packages: %s", err)
|
||||
}
|
||||
|
||||
// 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))
|
||||
os.MkdirAll(path.Dir(newPath), 0755)
|
||||
os.Rename(line, newPath)
|
||||
@@ -308,7 +285,7 @@ func compilePackage(archive string) {
|
||||
// Sign package
|
||||
if *signPackage {
|
||||
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.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
@@ -364,3 +341,85 @@ func setupFlagsAndHelp(usage, desc string) {
|
||||
}
|
||||
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"`
|
||||
Provides []string `yaml:"provides,omitempty"`
|
||||
Options []string `yaml:"options,omitempty"`
|
||||
Flags []PackageFlag `yaml:"flags,omitempty"`
|
||||
Downloads []PackageDownload `yaml:"downloads,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 {
|
||||
Url string `yaml:"url"`
|
||||
Type string `yaml:"type,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user