build: improve build output.

This commit is contained in:
Alexandre Pujol 2023-12-15 19:14:32 +00:00
parent d2fc3c3325
commit 6fa2c8ec3a
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
3 changed files with 106 additions and 57 deletions

View file

@ -5,7 +5,12 @@
package prebuild
import (
"reflect"
"runtime"
"strings"
"github.com/arduino/go-paths-helper"
"github.com/roddhjav/apparmor.d/pkg/logging"
)
var (
@ -24,11 +29,35 @@ func init() {
Distribution = getSupportedDistribution()
}
func getFctName(i any) string {
tmp := runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
res := strings.Split(tmp, ".")
return res[len(res)-1]
}
func printPrepareMessage(name string, msg []string) {
logging.Success("%v", PrepareMsg[name])
logging.Indent = " "
for _, line := range msg {
logging.Bullet("%s", line)
}
logging.Indent = ""
}
func printBuildMessage() {
for _, fct := range Builds {
name := getFctName(fct)
logging.Success("%v", BuildMsg[name])
}
}
func Prepare() error {
for _, fct := range Prepares {
if err := fct(); err != nil {
msg, err := fct()
if err != nil {
return err
}
printPrepareMessage(getFctName(fct), msg)
}
return nil
}
@ -48,5 +77,6 @@ func Build() error {
panic(err)
}
}
printBuildMessage()
return nil
}