9 Commits
6 changed files with 79 additions and 15 deletions
+31
View File
@@ -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
View File
@@ -19,7 +19,9 @@ 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 skipCheck = flag.BoolP("skip-checks", "s", false, "Skip 'check' function while compiling") 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 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 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") 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 // Setup compile command
args := make([]string, 0) args := make([]string, 0)
args = append(args, "compile") args = append(args, "compile")
if *verbose {
args = append(args, "-v")
}
if *skipCheck { if *skipCheck {
args = append(args, "-s") args = append(args, "-s")
} }
if *keepCompilationFiles {
args = append(args, "-k")
}
if *installDepends { if *installDepends {
args = append(args, "-d") args = append(args, "-d")
} }
@@ -231,11 +239,13 @@ func compilePackage(archive string) {
os.Rename(line, newPath) os.Rename(line, newPath)
outputPkgs[pkgInfo.Name] = newPath outputPkgs[pkgInfo.Name] = newPath
bpmutilsshared.UpdateDatabases(repo)
} else { } else {
outputPkgs[pkgInfo.Name] = line outputPkgs[pkgInfo.Name] = line
} }
} }
if repo := bpmutilsshared.GetRepository(); repo != "" && *moveToBinaryDir {
bpmutilsshared.UpdateDatabases(repo)
}
// Print out generated packages // Print out generated packages
for k, v := range outputPkgs { for k, v := range outputPkgs {
+5
View File
@@ -114,6 +114,11 @@ func createRepository(name, description string) {
log.Fatalf("Error: could not write to file: %s", err) log.Fatalf("Error: could not write to file: %s", err)
} }
err = os.Mkdir(path.Join(name, "source"), 0755)
if err != nil {
log.Fatalf("Error: could not create directory: %s", err)
}
fmt.Println("Repository created successfully!") fmt.Println("Repository created successfully!")
} }
+1
View File
@@ -123,6 +123,7 @@ func createDirectory() {
Name: *name, Name: *name,
Description: *description, Description: *description,
Version: *version, Version: *version,
Revision: 1,
Url: *url, Url: *url,
License: *license, License: *license,
Arch: "any", Arch: "any",
+27 -14
View File
@@ -58,31 +58,44 @@ func GenerateDatabase(path string) error {
// Initialize database entry // Initialize database entry
entry := BPMDatabaseEntry{} entry := BPMDatabaseEntry{}
entry.DownloadSize = info.Size() entry.DownloadSize = info.Size()
entry.InstalledSize = 0
entry.Filepath, err = filepath.Rel(path, packagePath) entry.Filepath, err = filepath.Rel(path, packagePath)
if err != nil { if err != nil {
return err 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 // Get package info
entry.PackageInfo, err = ReadPacakgeInfoFromTarball(packagePath) entry.PackageInfo, err = ReadPacakgeInfoFromTarball(packagePath)
if err != nil { if err != nil {
return err 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 // Add entry to database
if _, ok := database.Entries[entry.PackageInfo.Name]; ok { if _, ok := database.Entries[entry.PackageInfo.Name]; ok {
return fmt.Errorf("package (%s) has already been added to the database", entry.PackageInfo.Name) return fmt.Errorf("package (%s) has already been added to the database", entry.PackageInfo.Name)
+4
View File
@@ -22,11 +22,13 @@ type PackageInfo struct {
Type string `yaml:"type,omitempty"` Type string `yaml:"type,omitempty"`
Keep []string `yaml:"keep,omitempty"` Keep []string `yaml:"keep,omitempty"`
Depends []string `yaml:"depends,omitempty"` Depends []string `yaml:"depends,omitempty"`
RuntimeDepends []string `yaml:"runtime_depends,omitempty"`
OptionalDepends []string `yaml:"optional_depends,omitempty"` OptionalDepends []string `yaml:"optional_depends,omitempty"`
MakeDepends []string `yaml:"make_depends,omitempty"` MakeDepends []string `yaml:"make_depends,omitempty"`
Conflicts []string `yaml:"conflicts,omitempty"` Conflicts []string `yaml:"conflicts,omitempty"`
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"`
Downloads []PackageDownload `yaml:"downloads,omitempty"` Downloads []PackageDownload `yaml:"downloads,omitempty"`
SplitPackages []*PackageInfo `yaml:"split_packages,omitempty"` SplitPackages []*PackageInfo `yaml:"split_packages,omitempty"`
} }
@@ -54,10 +56,12 @@ func ReadPackageInfo(data []byte) (*PackageInfo, error) {
Keep: make([]string, 0), Keep: make([]string, 0),
Depends: make([]string, 0), Depends: make([]string, 0),
MakeDepends: make([]string, 0), MakeDepends: make([]string, 0),
RuntimeDepends: make([]string, 0),
OptionalDepends: make([]string, 0), OptionalDepends: make([]string, 0),
Conflicts: make([]string, 0), Conflicts: make([]string, 0),
Replaces: make([]string, 0), Replaces: make([]string, 0),
Provides: make([]string, 0), Provides: make([]string, 0),
Options: make([]string, 0),
Downloads: make([]PackageDownload, 0), Downloads: make([]PackageDownload, 0),
SplitPackages: make([]*PackageInfo, 0), SplitPackages: make([]*PackageInfo, 0),
} }