Compare commits
7 Commits
v0.0.3
...
fb5c875713
Author | SHA1 | Date | |
---|---|---|---|
fb5c875713 | |||
a345a24b95 | |||
5d1d3d7c45 | |||
a711edbcc0 | |||
d5636e8094 | |||
5d17875813 | |||
41eec2fc98 |
@@ -222,7 +222,7 @@ func extractFile(r io.Reader, format archiver.Format, name string, opts Options)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
err = os.Mkdir(path, 0o755)
|
err = os.MkdirAll(path, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -25,12 +25,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
"plemya-x.ru/alr/internal/overrides"
|
|
||||||
"plemya-x.ru/alr/pkg/distro"
|
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
"mvdan.cc/sh/v3/expand"
|
"mvdan.cc/sh/v3/expand"
|
||||||
"mvdan.cc/sh/v3/interp"
|
"mvdan.cc/sh/v3/interp"
|
||||||
"mvdan.cc/sh/v3/syntax"
|
"mvdan.cc/sh/v3/syntax"
|
||||||
|
"plemya-x.ru/alr/internal/overrides"
|
||||||
|
"plemya-x.ru/alr/pkg/distro"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrNotPointerToStruct = errors.New("val must be a pointer to a struct")
|
var ErrNotPointerToStruct = errors.New("val must be a pointer to a struct")
|
||||||
@@ -221,3 +221,8 @@ func (d *Decoder) getVar(name string) *expand.Variable {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsTruthy(value string) bool {
|
||||||
|
value = strings.ToLower(strings.TrimSpace(value))
|
||||||
|
return value == "true" || value == "yes" || value == "1"
|
||||||
|
}
|
||||||
|
@@ -49,6 +49,8 @@ type BuildVars struct {
|
|||||||
Checksums []string `sh:"checksums"`
|
Checksums []string `sh:"checksums"`
|
||||||
Backup []string `sh:"backup"`
|
Backup []string `sh:"backup"`
|
||||||
Scripts Scripts `sh:"scripts"`
|
Scripts Scripts `sh:"scripts"`
|
||||||
|
AutoReq []string `sh:"auto_req"`
|
||||||
|
AutoProv []string `sh:"auto_prov"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Scripts struct {
|
type Scripts struct {
|
||||||
|
@@ -46,6 +46,7 @@ import (
|
|||||||
_ "github.com/goreleaser/nfpm/v2/arch"
|
_ "github.com/goreleaser/nfpm/v2/arch"
|
||||||
_ "github.com/goreleaser/nfpm/v2/deb"
|
_ "github.com/goreleaser/nfpm/v2/deb"
|
||||||
_ "github.com/goreleaser/nfpm/v2/rpm"
|
_ "github.com/goreleaser/nfpm/v2/rpm"
|
||||||
|
"go.elara.ws/logger/log"
|
||||||
"mvdan.cc/sh/v3/expand"
|
"mvdan.cc/sh/v3/expand"
|
||||||
"mvdan.cc/sh/v3/interp"
|
"mvdan.cc/sh/v3/interp"
|
||||||
"mvdan.cc/sh/v3/syntax"
|
"mvdan.cc/sh/v3/syntax"
|
||||||
@@ -170,7 +171,7 @@ func BuildPackage(ctx context.Context, opts types.BuildOpts) ([]string, []string
|
|||||||
|
|
||||||
pkgFormat := getPkgFormat(opts.Manager) // Получаем формат пакета
|
pkgFormat := getPkgFormat(opts.Manager) // Получаем формат пакета
|
||||||
|
|
||||||
pkgInfo, err := buildPkgMetadata(vars, dirs, pkgFormat, info, append(repoDeps, builtNames...)) // Собираем метаданные пакета
|
pkgInfo, err := buildPkgMetadata(ctx, vars, dirs, pkgFormat, info, append(repoDeps, builtNames...)) // Собираем метаданные пакета
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -502,7 +503,7 @@ func executeFunctions(ctx context.Context, dec *decoder.Decoder, dirs types.Dire
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Функция buildPkgMetadata создает метаданные для пакета, который будет собран.
|
// Функция buildPkgMetadata создает метаданные для пакета, который будет собран.
|
||||||
func buildPkgMetadata(vars *types.BuildVars, dirs types.Directories, pkgFormat string, info *distro.OSRelease, deps []string) (*nfpm.Info, error) {
|
func buildPkgMetadata(ctx context.Context, vars *types.BuildVars, dirs types.Directories, pkgFormat string, info *distro.OSRelease, deps []string) (*nfpm.Info, error) {
|
||||||
pkgInfo := getBasePkgInfo(vars)
|
pkgInfo := getBasePkgInfo(vars)
|
||||||
pkgInfo.Description = vars.Description
|
pkgInfo.Description = vars.Description
|
||||||
pkgInfo.Platform = "linux"
|
pkgInfo.Platform = "linux"
|
||||||
@@ -543,6 +544,28 @@ func buildPkgMetadata(vars *types.BuildVars, dirs types.Directories, pkgFormat s
|
|||||||
}
|
}
|
||||||
pkgInfo.Overridables.Contents = contents
|
pkgInfo.Overridables.Contents = contents
|
||||||
|
|
||||||
|
if len(vars.AutoProv) == 1 && decoder.IsTruthy(vars.AutoProv[0]) {
|
||||||
|
if pkgFormat == "rpm" {
|
||||||
|
err = rpmFindProvides(ctx, pkgInfo, dirs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Info("AutoProv is not implemented for this package format, so it's skiped").Send()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(vars.AutoReq) == 1 && decoder.IsTruthy(vars.AutoReq[0]) {
|
||||||
|
if pkgFormat == "rpm" {
|
||||||
|
err = rpmFindRequires(ctx, pkgInfo, dirs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Info("AutoReq is not implemented for this package format, so it's skiped").Send()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return pkgInfo, nil
|
return pkgInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
80
pkg/build/findDeps.go
Normal file
80
pkg/build/findDeps.go
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package build
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/goreleaser/nfpm/v2"
|
||||||
|
"plemya-x.ru/alr/internal/types"
|
||||||
|
"plemya-x.ru/alr/pkg/loggerctx"
|
||||||
|
)
|
||||||
|
|
||||||
|
func rpmFindDependencies(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, command string, updateFunc func(string)) error {
|
||||||
|
log := loggerctx.From(ctx)
|
||||||
|
|
||||||
|
if _, err := exec.LookPath(command); err != nil {
|
||||||
|
log.Info("Command not found on the system").Str("command", command).Send()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var paths []string
|
||||||
|
for _, content := range pkgInfo.Contents {
|
||||||
|
if content.Type != "dir" {
|
||||||
|
paths = append(paths,
|
||||||
|
path.Join(dirs.PkgDir, content.Destination),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(paths) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command(command)
|
||||||
|
cmd.Stdin = bytes.NewBufferString(strings.Join(paths, "\n"))
|
||||||
|
cmd.Env = append(cmd.Env,
|
||||||
|
"RPM_BUILD_ROOT="+dirs.PkgDir,
|
||||||
|
"RPM_FINDPROV_METHOD=",
|
||||||
|
"RPM_FINDREQ_METHOD=",
|
||||||
|
"RPM_DATADIR=",
|
||||||
|
"RPM_SUBPACKAGE_NAME=",
|
||||||
|
)
|
||||||
|
var out bytes.Buffer
|
||||||
|
var stderr bytes.Buffer
|
||||||
|
cmd.Stdout = &out
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
log.Error(stderr.String()).Send()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies := strings.Split(strings.TrimSpace(out.String()), "\n")
|
||||||
|
for _, dep := range dependencies {
|
||||||
|
if dep != "" {
|
||||||
|
updateFunc(dep)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func rpmFindProvides(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories) error {
|
||||||
|
log := loggerctx.From(ctx)
|
||||||
|
|
||||||
|
return rpmFindDependencies(ctx, pkgInfo, dirs, "/usr/lib/rpm/find-provides", func(dep string) {
|
||||||
|
log.Info("Provided dependency found").Str("dep", dep).Send()
|
||||||
|
pkgInfo.Overridables.Provides = append(pkgInfo.Overridables.Provides, dep)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func rpmFindRequires(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories) error {
|
||||||
|
log := loggerctx.From(ctx)
|
||||||
|
|
||||||
|
return rpmFindDependencies(ctx, pkgInfo, dirs, "/usr/lib/rpm/find-requires", func(dep string) {
|
||||||
|
log.Info("Required dependency found").Str("dep", dep).Send()
|
||||||
|
pkgInfo.Overridables.Depends = append(pkgInfo.Overridables.Depends, dep)
|
||||||
|
})
|
||||||
|
}
|
Reference in New Issue
Block a user