Change -o flag from output filename to output directory
This commit is contained in:
parent
5085981f52
commit
903c7dce3e
@ -42,7 +42,7 @@ var doCleanup = false
|
|||||||
var showRepoInfo = false
|
var showRepoInfo = false
|
||||||
var installSrcPkgDepends = false
|
var installSrcPkgDepends = false
|
||||||
var skipChecks = false
|
var skipChecks = false
|
||||||
var outputFilename = ""
|
var outputDirectory = ""
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := bpmlib.ReadConfig()
|
err := bpmlib.ReadConfig()
|
||||||
@ -642,36 +642,40 @@ func resolveCommand() {
|
|||||||
log.Fatalf("Error: could not get user home directory: %s", err)
|
log.Fatalf("Error: could not get user home directory: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim output filename
|
// Trim output directory
|
||||||
outputFilename = strings.TrimSpace(outputFilename)
|
outputDirectory = strings.TrimSpace(outputDirectory)
|
||||||
if outputFilename != "/" {
|
if outputDirectory != "/" {
|
||||||
outputFilename = strings.TrimSuffix(outputFilename, "/")
|
outputDirectory = strings.TrimSuffix(outputDirectory, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set output filename if empty
|
// Set output directory if empty
|
||||||
if outputFilename == "" {
|
if outputDirectory == "" {
|
||||||
outputFilename = path.Join(workdir, fmt.Sprintf("%s-%s-%d.bpm", bpmpkg.PkgInfo.Name, bpmpkg.PkgInfo.Version, bpmpkg.PkgInfo.Revision))
|
outputDirectory = workdir
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace first tilde with user home directory
|
// Replace first tilde with user home directory
|
||||||
if strings.Split(outputFilename, "/")[0] == "~" {
|
if strings.Split(outputDirectory, "/")[0] == "~" {
|
||||||
outputFilename = strings.Replace(outputFilename, "~", homedir, 1)
|
outputDirectory = strings.Replace(outputDirectory, "~", homedir, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepend current working directory to output filename if not an absolute path
|
// Prepend current working directory to output directory if not an absolute path
|
||||||
if outputFilename != "" && !strings.HasPrefix(outputFilename, "/") {
|
if outputDirectory != "" && !strings.HasPrefix(outputDirectory, "/") {
|
||||||
outputFilename = filepath.Join(workdir, outputFilename)
|
outputDirectory = filepath.Join(workdir, outputDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean path
|
// Clean path
|
||||||
path.Clean(outputFilename)
|
path.Clean(outputDirectory)
|
||||||
|
|
||||||
// Append archive filename if path is set to a directory
|
// Ensure output directory exists and is a directory
|
||||||
if stat, err := os.Stat(outputFilename); err == nil && stat.IsDir() {
|
stat, err := os.Stat(outputDirectory)
|
||||||
outputFilename = path.Join(outputFilename, fmt.Sprintf("%s-%s-%d.bpm", bpmpkg.PkgInfo.Name, bpmpkg.PkgInfo.Version, bpmpkg.PkgInfo.Revision))
|
if err != nil {
|
||||||
|
log.Fatalf("Error: could not stat output directory (%s): %s", outputDirectory, err)
|
||||||
|
}
|
||||||
|
if !stat.IsDir() {
|
||||||
|
log.Fatalf("Error: output directory (%s) is not a directory", outputDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
outputBpmPackages, err := bpmlib.CompileSourcePackage(sourcePackage, outputFilename, skipChecks)
|
outputBpmPackages, err := bpmlib.CompileSourcePackage(sourcePackage, outputDirectory, skipChecks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not compile source package (%s): %s", sourcePackage, err)
|
log.Fatalf("Error: could not compile source package (%s): %s", sourcePackage, err)
|
||||||
}
|
}
|
||||||
@ -762,7 +766,7 @@ func printHelp() {
|
|||||||
fmt.Println(" -v Show additional information about what BPM is doing")
|
fmt.Println(" -v Show additional information about what BPM is doing")
|
||||||
fmt.Println(" -d installs required dependencies for package compilation")
|
fmt.Println(" -d installs required dependencies for package compilation")
|
||||||
fmt.Println(" -s skips the check function in source.sh scripts")
|
fmt.Println(" -s skips the check function in source.sh scripts")
|
||||||
fmt.Println(" -o sets output filename")
|
fmt.Println(" -o sets output directory")
|
||||||
fmt.Println(" -y skips the confirmation prompt")
|
fmt.Println(" -y skips the confirmation prompt")
|
||||||
|
|
||||||
fmt.Println("\033[1m----------------\033[0m")
|
fmt.Println("\033[1m----------------\033[0m")
|
||||||
@ -827,7 +831,7 @@ func resolveFlags() {
|
|||||||
compileFlagSet := flag.NewFlagSet("Compile flags", flag.ExitOnError)
|
compileFlagSet := flag.NewFlagSet("Compile flags", flag.ExitOnError)
|
||||||
compileFlagSet.BoolVar(&installSrcPkgDepends, "d", false, "Install required dependencies for package compilation")
|
compileFlagSet.BoolVar(&installSrcPkgDepends, "d", false, "Install required dependencies for package compilation")
|
||||||
compileFlagSet.BoolVar(&skipChecks, "s", false, "Skip the check function in source.sh scripts")
|
compileFlagSet.BoolVar(&skipChecks, "s", false, "Skip the check function in source.sh scripts")
|
||||||
compileFlagSet.StringVar(&outputFilename, "o", "", "Set output filename")
|
compileFlagSet.StringVar(&outputDirectory, "o", "", "Set output directory")
|
||||||
compileFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
compileFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
||||||
compileFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
compileFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
var rootCompilationUID = "65534"
|
var rootCompilationUID = "65534"
|
||||||
var rootCompilationGID = "65534"
|
var rootCompilationGID = "65534"
|
||||||
|
|
||||||
func CompileSourcePackage(archiveFilename, outputFilename string, skipChecks bool) (outputBpmPackages map[string]string, err error) {
|
func CompileSourcePackage(archiveFilename, outputDirectory string, skipChecks bool) (outputBpmPackages map[string]string, err error) {
|
||||||
// Initialize map
|
// Initialize map
|
||||||
outputBpmPackages = make(map[string]string)
|
outputBpmPackages = make(map[string]string)
|
||||||
|
|
||||||
@ -326,16 +326,8 @@ func CompileSourcePackage(archiveFilename, outputFilename string, skipChecks boo
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set output filename if split package
|
// Set output filename
|
||||||
if len(bpmpkg.PkgInfo.SplitPackages) != 1 {
|
outputFilename := path.Join(outputDirectory, fmt.Sprintf("%s-%s-%d.bpm", pkgInfo.Name, pkgInfo.Version, pkgInfo.Revision))
|
||||||
// Get current working directory
|
|
||||||
workdir, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("could not get working directory: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
outputFilename = path.Join(workdir, fmt.Sprintf("%s-%s-%d.bpm", pkgInfo.Name, pkgInfo.Version, pkgInfo.Revision))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move final BPM archive
|
// Move final BPM archive
|
||||||
err = os.Rename(path.Join(tempDirectory, "final-archive.bpm"), outputFilename)
|
err = os.Rename(path.Join(tempDirectory, "final-archive.bpm"), outputFilename)
|
||||||
|
@ -473,9 +473,8 @@ func (operation *BPMOperation) Execute(verbose, force bool) error {
|
|||||||
|
|
||||||
// Compile package if type is 'source'
|
// Compile package if type is 'source'
|
||||||
if bpmpkg.PkgInfo.Type == "source" {
|
if bpmpkg.PkgInfo.Type == "source" {
|
||||||
// Get path to compiled package directory and output filename
|
// Get path to compiled package directory
|
||||||
compiledDir := path.Join(operation.RootDir, "/var/lib/bpm/compiled/")
|
compiledDir := path.Join(operation.RootDir, "/var/lib/bpm/compiled/")
|
||||||
outputFilename := path.Join(compiledDir, fmt.Sprintf("%s-%s-%d.bpm", bpmpkg.PkgInfo.Name, bpmpkg.PkgInfo.Version, bpmpkg.PkgInfo.Revision))
|
|
||||||
|
|
||||||
// Create compiled package directory if not exists
|
// Create compiled package directory if not exists
|
||||||
if _, err := os.Stat(compiledDir); err != nil {
|
if _, err := os.Stat(compiledDir); err != nil {
|
||||||
@ -486,14 +485,14 @@ func (operation *BPMOperation) Execute(verbose, force bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compile source package
|
// Compile source package
|
||||||
outputBpmPackages, err := CompileSourcePackage(value.File, outputFilename, false)
|
outputBpmPackages, err := CompileSourcePackage(value.File, compiledDir, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not compile source package (%s): %s\n", value.File, err)
|
return fmt.Errorf("could not compile source package (%s): %s\n", value.File, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set values
|
// Set values
|
||||||
fileToInstall = outputBpmPackages[bpmpkg.PkgInfo.Name]
|
fileToInstall = outputBpmPackages[bpmpkg.PkgInfo.Name]
|
||||||
bpmpkg, err = ReadPackage(outputFilename)
|
bpmpkg, err = ReadPackage(fileToInstall)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not read package (%s): %s\n", fileToInstall, err)
|
return fmt.Errorf("could not read package (%s): %s\n", fileToInstall, err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user