mirror of
https://github.com/EnumeratedDev/bpm-utils.git
synced 2026-09-24 14:36:13 +00:00
Compare commits
6
Commits
7.0.0
...
5240ae4a8c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5240ae4a8c
|
||
|
|
9d03b5b423
|
||
|
|
f17bc777d9
|
||
|
|
154f546b7f
|
||
|
|
c4a0e9f860
|
||
|
|
b9d7dfd9d0
|
@@ -0,0 +1,31 @@
|
||||
# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
||||
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
||||
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
||||
|
||||
# The prepare function is executed in the root of the temp directory
|
||||
# This function is used for putting downloaded files to the correct location or applying patches
|
||||
prepare() {
|
||||
cd "$BPM_SOURCE"
|
||||
cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
|
||||
}
|
||||
|
||||
# The build function is executed in the source directory
|
||||
# This function is used to compile the source code
|
||||
build() {
|
||||
cargo build --release --locked --frozen
|
||||
}
|
||||
|
||||
# The check function is executed in the source directory
|
||||
# This function is used to run tests to verify the package has been compiled correctly
|
||||
check() {
|
||||
cargo test --release --frozen
|
||||
}
|
||||
|
||||
# The package function is executed in the source directory
|
||||
# This function is used to move the compiled files into the output directory
|
||||
package() {
|
||||
# Cargo built packages are not usually packaged manually and not with an 'install' subcommand
|
||||
|
||||
# Install package license
|
||||
install -Dm644 "$BPM_SOURCE"/LICENSE "$BPM_OUTPUT"/usr/share/licenses/$NAME/LICENSE
|
||||
}
|
||||
+11
-1
@@ -19,7 +19,9 @@ 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.BoolP("skip-checks", "s", 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 installPackage = flag.BoolP("install", "i", false, "Install compiled BPM package after compilation finishes")
|
||||
var moveToBinaryDir = flag.BoolP("move", "m", false, "Move output packages to the current repository's binary directory")
|
||||
@@ -160,9 +162,15 @@ 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")
|
||||
}
|
||||
@@ -231,11 +239,13 @@ func compilePackage(archive string) {
|
||||
os.Rename(line, newPath)
|
||||
outputPkgs[pkgInfo.Name] = newPath
|
||||
|
||||
bpmutilsshared.UpdateDatabases(repo)
|
||||
} else {
|
||||
outputPkgs[pkgInfo.Name] = line
|
||||
}
|
||||
}
|
||||
if repo := bpmutilsshared.GetRepository(); repo != "" && *moveToBinaryDir {
|
||||
bpmutilsshared.UpdateDatabases(repo)
|
||||
}
|
||||
|
||||
// Print out generated packages
|
||||
for k, v := range outputPkgs {
|
||||
|
||||
@@ -58,31 +58,44 @@ func GenerateDatabase(path string) error {
|
||||
// Initialize database entry
|
||||
entry := BPMDatabaseEntry{}
|
||||
entry.DownloadSize = info.Size()
|
||||
entry.InstalledSize = 0
|
||||
entry.Filepath, err = filepath.Rel(path, packagePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get package installed size
|
||||
cmd := exec.Command("tar", "-t", "-v", "-f", packagePath, "files.tar.gz")
|
||||
output, err := cmd.Output()
|
||||
if err == nil {
|
||||
entry.InstalledSize, err = strconv.ParseInt(strings.Fields(string(output))[2], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err.(*exec.ExitError).ExitCode() == 2 {
|
||||
entry.InstalledSize = 0
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get package info
|
||||
entry.PackageInfo, err = ReadPacakgeInfoFromTarball(packagePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get package installed size
|
||||
if entry.PackageInfo.Type == "binary" {
|
||||
cmd := exec.Command("tar", "xf", packagePath, "pkg.files", "-O")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, line := range strings.Split(string(output), "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
stringEntry := strings.Split(line, " ")
|
||||
if len(stringEntry) < 5 {
|
||||
return fmt.Errorf("pkg.files is not formatted correctly")
|
||||
}
|
||||
size, err := strconv.ParseInt(stringEntry[len(stringEntry)-1], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
entry.InstalledSize += size
|
||||
}
|
||||
}
|
||||
|
||||
// Add entry to database
|
||||
if _, ok := database.Entries[entry.PackageInfo.Name]; ok {
|
||||
return fmt.Errorf("package (%s) has already been added to the database", entry.PackageInfo.Name)
|
||||
|
||||
@@ -27,6 +27,7 @@ type PackageInfo struct {
|
||||
Conflicts []string `yaml:"conflicts,omitempty"`
|
||||
Replaces []string `yaml:"replaces,omitempty"`
|
||||
Provides []string `yaml:"provides,omitempty"`
|
||||
Options []string `yaml:"options,omitempty"`
|
||||
Downloads []PackageDownload `yaml:"downloads,omitempty"`
|
||||
SplitPackages []*PackageInfo `yaml:"split_packages,omitempty"`
|
||||
}
|
||||
@@ -58,6 +59,7 @@ func ReadPackageInfo(data []byte) (*PackageInfo, error) {
|
||||
Conflicts: make([]string, 0),
|
||||
Replaces: make([]string, 0),
|
||||
Provides: make([]string, 0),
|
||||
Options: make([]string, 0),
|
||||
Downloads: make([]PackageDownload, 0),
|
||||
SplitPackages: make([]*PackageInfo, 0),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user