2 Commits
Author SHA1 Message Date
EnumDev 4ff4a74fa3 Improve package info parsing 2025-09-29 10:35:54 +03:00
EnumDev f6ef60aa40 Add cargo template 2025-09-28 18:24:35 +03:00
4 changed files with 56 additions and 45 deletions
+32
View File
@@ -0,0 +1,32 @@
# 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"
# Fetch cargo dependencies
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 --frozen --workspace
}
# 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 --frozen
}
# The package function is executed in the source directory
# This function is used to move the compiled files into the output directory
package() {
find target/release -maxdepth 1 -type f -executable -exec install -Dm755 -t "$BPM_OUTPUT"/usr/bin {} +
# Install package license
install -Dm644 "$BPM_SOURCE"/LICENSE "$BPM_OUTPUT"/usr/share/licenses/$NAME/LICENSE
}
+1 -1
View File
@@ -208,7 +208,7 @@ func compilePackage(archive string) {
outputPkgs := make(map[string]string) outputPkgs := make(map[string]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.ReadPacakgeInfo(line) pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromTarball(line)
if repo := bpmutilsshared.GetRepository(); repo != "" && *moveToBinaryDir { if repo := bpmutilsshared.GetRepository(); repo != "" && *moveToBinaryDir {
// Remove old package from binary dir // Remove old package from binary dir
+1 -1
View File
@@ -78,7 +78,7 @@ func GenerateDatabase(path string) error {
} }
// Get package info // Get package info
entry.PackageInfo, err = ReadPacakgeInfo(packagePath) entry.PackageInfo, err = ReadPacakgeInfoFromTarball(packagePath)
if err != nil { if err != nil {
return err return err
} }
+22 -43
View File
@@ -12,8 +12,8 @@ import (
type PackageInfo struct { type PackageInfo struct {
Name string `yaml:"name"` Name string `yaml:"name"`
Description string `yaml:"description"` Description string `yaml:"description,omitempty"`
Version string `yaml:"version"` Version string `yaml:"version,omitempty"`
Revision int `yaml:"revision,omitempty"` Revision int `yaml:"revision,omitempty"`
Url string `yaml:"url,omitempty"` Url string `yaml:"url,omitempty"`
License string `yaml:"license,omitempty"` License string `yaml:"license,omitempty"`
@@ -42,24 +42,9 @@ type PackageDownload struct {
Checksum string `yaml:"checksum,omitempty"` Checksum string `yaml:"checksum,omitempty"`
} }
func ReadPacakgeInfo(path string) (*PackageInfo, error) { func ReadPackageInfo(data []byte) (*PackageInfo, error) {
// Extract package info using tar
cmd := exec.Command("tar", "-x", "-f", path, "pkg.info", "-O")
output, err := cmd.Output()
if err != nil {
return nil, err
}
pkgInfo := &PackageInfo{ pkgInfo := &PackageInfo{
Name: "",
Description: "",
Version: "",
Revision: 1, Revision: 1,
Url: "",
License: "",
Arch: "",
OutputArch: "",
Type: "",
Keep: make([]string, 0), Keep: make([]string, 0),
Depends: make([]string, 0), Depends: make([]string, 0),
MakeDepends: make([]string, 0), MakeDepends: make([]string, 0),
@@ -72,7 +57,23 @@ func ReadPacakgeInfo(path string) (*PackageInfo, error) {
} }
// Unmarshal yaml // Unmarshal yaml
err = yaml.Unmarshal(output, pkgInfo) err := yaml.Unmarshal(data, pkgInfo)
if err != nil {
return nil, err
}
return pkgInfo, nil
}
func ReadPacakgeInfoFromTarball(path string) (*PackageInfo, error) {
// Extract package info using tar
cmd := exec.Command("tar", "-x", "-f", path, "pkg.info", "-O")
output, err := cmd.Output()
if err != nil {
return nil, err
}
pkgInfo, err := ReadPackageInfo(output)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -81,35 +82,13 @@ func ReadPacakgeInfo(path string) (*PackageInfo, error) {
} }
func ReadPacakgeInfoFromFile(path string) (*PackageInfo, error) { func ReadPacakgeInfoFromFile(path string) (*PackageInfo, error) {
// Extract package info using tar // Read data from file
output, err := os.ReadFile(path) output, err := os.ReadFile(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
pkgInfo := &PackageInfo{ pkgInfo, err := ReadPackageInfo(output)
Name: "",
Description: "",
Version: "",
Revision: 1,
Url: "",
License: "",
Arch: "",
OutputArch: "",
Type: "",
Keep: make([]string, 0),
Depends: make([]string, 0),
OptionalDepends: make([]string, 0),
MakeDepends: make([]string, 0),
Conflicts: make([]string, 0),
Replaces: make([]string, 0),
Provides: make([]string, 0),
Downloads: make([]PackageDownload, 0),
SplitPackages: make([]*PackageInfo, 0),
}
// Unmarshal yaml
err = yaml.Unmarshal(output, pkgInfo)
if err != nil { if err != nil {
return nil, err return nil, err
} }