Add compression to build CLI

Also handle how concurrency is set now.

Adds also an accessor to compiler to set the desired compression type

Refers to #33
This commit is contained in:
Ettore Di Giacinto
2019-12-30 14:52:34 +01:00
parent 475b63be95
commit f71c9937c4
3 changed files with 12 additions and 3 deletions

View File

@@ -43,6 +43,7 @@ var buildCmd = &cobra.Command{
viper.BindPFlag("database", cmd.Flags().Lookup("database")) viper.BindPFlag("database", cmd.Flags().Lookup("database"))
viper.BindPFlag("revdeps", cmd.Flags().Lookup("revdeps")) viper.BindPFlag("revdeps", cmd.Flags().Lookup("revdeps"))
viper.BindPFlag("all", cmd.Flags().Lookup("all")) viper.BindPFlag("all", cmd.Flags().Lookup("all"))
viper.BindPFlag("compression", cmd.Flags().Lookup("compression"))
}, },
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
@@ -54,6 +55,7 @@ var buildCmd = &cobra.Command{
revdeps := viper.GetBool("revdeps") revdeps := viper.GetBool("revdeps")
all := viper.GetBool("all") all := viper.GetBool("all")
databaseType := viper.GetString("database") databaseType := viper.GetString("database")
compressionType := viper.GetString("compression")
compilerSpecs := compiler.NewLuetCompilationspecs() compilerSpecs := compiler.NewLuetCompilationspecs()
var compilerBackend compiler.CompilerBackend var compilerBackend compiler.CompilerBackend
@@ -89,7 +91,8 @@ var buildCmd = &cobra.Command{
Fatal("Error: " + err.Error()) Fatal("Error: " + err.Error())
} }
luetCompiler := compiler.NewLuetCompiler(compilerBackend, generalRecipe.GetDatabase()) luetCompiler := compiler.NewLuetCompiler(compilerBackend, generalRecipe.GetDatabase())
luetCompiler.SetConcurrency(concurrency)
luetCompiler.SetCompressionType(compiler.CompressionImplementation(compressionType))
if !all { if !all {
for _, a := range args { for _, a := range args {
decodepackage, err := regexp.Compile(`^([<>]?\~?=?)((([^\/]+)\/)?(?U)(\S+))(-(\d+(\.\d+)*[a-z]?(_(alpha|beta|pre|rc|p)\d*)*(-r\d+)?))?$`) decodepackage, err := regexp.Compile(`^([<>]?\~?=?)((([^\/]+)\/)?(?U)(\S+))(-(\d+(\.\d+)*[a-z]?(_(alpha|beta|pre|rc|p)\d*)*(-r\d+)?))?$`)
@@ -125,10 +128,10 @@ var buildCmd = &cobra.Command{
var artifact []compiler.Artifact var artifact []compiler.Artifact
var errs []error var errs []error
if revdeps { if revdeps {
artifact, errs = luetCompiler.CompileWithReverseDeps(concurrency, privileged, compilerSpecs) artifact, errs = luetCompiler.CompileWithReverseDeps(privileged, compilerSpecs)
} else { } else {
artifact, errs = luetCompiler.CompileParallel(concurrency, privileged, compilerSpecs) artifact, errs = luetCompiler.CompileParallel(privileged, compilerSpecs)
} }
if len(errs) != 0 { if len(errs) != 0 {
@@ -156,6 +159,7 @@ func init() {
buildCmd.Flags().Bool("revdeps", false, "Build with revdeps") buildCmd.Flags().Bool("revdeps", false, "Build with revdeps")
buildCmd.Flags().Bool("all", false, "Build all packages in the tree") buildCmd.Flags().Bool("all", false, "Build all packages in the tree")
buildCmd.Flags().String("destination", path, "Destination folder") buildCmd.Flags().String("destination", path, "Destination folder")
buildCmd.Flags().String("compression", "none", "Compression alg: none, gzip")
RootCmd.AddCommand(buildCmd) RootCmd.AddCommand(buildCmd)
} }

View File

@@ -65,6 +65,10 @@ func (cs *LuetCompiler) SetConcurrency(i int) {
cs.Concurrency = i cs.Concurrency = i
} }
func (cs *LuetCompiler) SetCompressionType(t CompressionImplementation) {
cs.CompressionType = t
}
func (cs *LuetCompiler) compilerWorker(i int, wg *sync.WaitGroup, cspecs chan CompilationSpec, a *[]Artifact, m *sync.Mutex, concurrency int, keepPermissions bool, errors chan error) { func (cs *LuetCompiler) compilerWorker(i int, wg *sync.WaitGroup, cspecs chan CompilationSpec, a *[]Artifact, m *sync.Mutex, concurrency int, keepPermissions bool, errors chan error) {
defer wg.Done() defer wg.Done()

View File

@@ -30,6 +30,7 @@ type Compiler interface {
SetBackend(CompilerBackend) SetBackend(CompilerBackend)
GetBackend() CompilerBackend GetBackend() CompilerBackend
SetCompressionType(t CompressionImplementation)
} }
type CompilerBackendOptions struct { type CompilerBackendOptions struct {