Skip to content

Commit

Permalink
feat: simplify module builders loading logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkobrombin committed Feb 13, 2024
1 parent 500adad commit 7671979
Showing 1 changed file with 16 additions and 48 deletions.
64 changes: 16 additions & 48 deletions core/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,58 +230,26 @@ func BuildModule(recipe *api.Recipe, moduleInterface interface{}) (string, error
}
}

switch module.Type {
case "apt":
command, err := BuildAptModule(moduleInterface, recipe)
if err != nil {
return "", err
}
commands = commands + " && " + command
case "cmake":
command, err := BuildCMakeModule(moduleInterface, recipe)
if err != nil {
return "", err
}
commands = commands + " && " + command
case "dpkg":
command, err := BuildDpkgModule(moduleInterface, recipe)
if err != nil {
return "", err
}
commands = commands + " && " + command
case "dpkg-buildpackage":
command, err := BuildDpkgBuildPkgModule(moduleInterface, recipe)
if err != nil {
return "", err
}
commands = commands + " && " + command
case "go":
command, err := BuildGoModule(moduleInterface, recipe)
if err != nil {
return "", err
}
commands = commands + " && " + command
case "make":
command, err := BuildMakeModule(moduleInterface, recipe)
if err != nil {
return "", err
}
commands = commands + " && " + command
case "meson":
command, err := BuildMesonModule(moduleInterface, recipe)
if err != nil {
return "", err
}
commands = commands + " && " + command
case "shell":
command, err := BuildShellModule(moduleInterface, recipe)
moduleBuilders := map[string]func(interface{}, *api.Recipe) (string, error){
"apt": BuildAptModule,
"dnf": BuildDnfModule,
"cmake": BuildCMakeModule,
"dpkg": BuildDpkgModule,
"dpkg-buildpackage": BuildDpkgBuildPkgModule,
"go": BuildGoModule,
"make": BuildMakeModule,
"meson": BuildMesonModule,
"shell": BuildShellModule,
"includes": func(interface{}, *api.Recipe) (string, error) { return "", nil },
}

if moduleBuilder, ok := moduleBuilders[module.Type]; ok {
command, err := moduleBuilder(moduleInterface, recipe)
if err != nil {
return "", err
}
commands = commands + " && " + command
case "includes":
return "", nil
default:
} else {
command, err := LoadPlugin(module.Type, moduleInterface, recipe)
if err != nil {
return "", err
Expand Down

0 comments on commit 7671979

Please sign in to comment.