feat: add skiplists for auto_req and auto_prov
This commit is contained in:
		| @@ -50,6 +50,7 @@ import ( | ||||
| 	"gitea.plemya-x.ru/Plemya-x/ALR/internal/shutils/handlers" | ||||
| 	"gitea.plemya-x.ru/Plemya-x/ALR/internal/shutils/helpers" | ||||
| 	"gitea.plemya-x.ru/Plemya-x/ALR/internal/types" | ||||
| 	finddeps "gitea.plemya-x.ru/Plemya-x/ALR/pkg/build/find_deps" | ||||
| 	"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro" | ||||
| 	"gitea.plemya-x.ru/Plemya-x/ALR/pkg/manager" | ||||
| ) | ||||
| @@ -211,8 +212,10 @@ func (b *Builder) BuildPackage(ctx context.Context) ([]string, []string, error) | ||||
| 	sources, checksums = removeDuplicatesSources(sources, checksums) | ||||
|  | ||||
| 	mergedVars := types.BuildVars{ | ||||
| 		Sources:   sources, | ||||
| 		Checksums: checksums, | ||||
| 		BuildVarsPre: types.BuildVarsPre{ | ||||
| 			Sources:   sources, | ||||
| 			Checksums: checksums, | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	buildDeps, err := b.installBuildDeps(ctx, buildDepends) // Устанавливаем зависимости для сборки | ||||
| @@ -858,24 +861,18 @@ func (b *Builder) buildPkgMetadata( | ||||
| 	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 { | ||||
| 			slog.Info(gotext.Get("AutoProv is not implemented for this package format, so it's skipped")) | ||||
| 		f := finddeps.New(b.info, pkgFormat) | ||||
| 		err = f.FindProvides(ctx, pkgInfo, dirs, vars.AutoProvSkipList) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	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 { | ||||
| 			slog.Info(gotext.Get("AutoReq is not implemented for this package format, so it's skipped")) | ||||
| 		f := finddeps.New(b.info, pkgFormat) | ||||
| 		err = f.FindRequires(ctx, pkgInfo, dirs, vars.AutoReqSkipList) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -14,7 +14,7 @@ | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| package build | ||||
| package finddeps | ||||
| 
 | ||||
| import ( | ||||
| 	"bytes" | ||||
| @@ -30,7 +30,7 @@ import ( | ||||
| 	"gitea.plemya-x.ru/Plemya-x/ALR/internal/types" | ||||
| ) | ||||
| 
 | ||||
| func rpmFindDependencies(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, command string, updateFunc func(string)) error { | ||||
| func rpmFindDependenciesALTLinux(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, command string, envs []string, updateFunc func(string)) error { | ||||
| 	if _, err := exec.LookPath(command); err != nil { | ||||
| 		slog.Info(gotext.Get("Command not found on the system"), "command", command) | ||||
| 		return nil | ||||
| @@ -49,8 +49,8 @@ func rpmFindDependencies(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Dir | ||||
| 		return nil | ||||
| 	} | ||||
| 
 | ||||
| 	cmd := exec.Command(command) | ||||
| 	cmd.Stdin = bytes.NewBufferString(strings.Join(paths, "\n")) | ||||
| 	cmd := exec.CommandContext(ctx, command) | ||||
| 	cmd.Stdin = bytes.NewBufferString(strings.Join(paths, "\n") + "\n") | ||||
| 	cmd.Env = append(cmd.Env, | ||||
| 		"RPM_BUILD_ROOT="+dirs.PkgDir, | ||||
| 		"RPM_FINDPROV_METHOD=", | ||||
| @@ -58,6 +58,7 @@ func rpmFindDependencies(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Dir | ||||
| 		"RPM_DATADIR=", | ||||
| 		"RPM_SUBPACKAGE_NAME=", | ||||
| 	) | ||||
| 	cmd.Env = append(cmd.Env, envs...) | ||||
| 	var out bytes.Buffer | ||||
| 	var stderr bytes.Buffer | ||||
| 	cmd.Stdout = &out | ||||
| @@ -66,6 +67,7 @@ func rpmFindDependencies(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Dir | ||||
| 		slog.Error(stderr.String()) | ||||
| 		return err | ||||
| 	} | ||||
| 	slog.Debug(stderr.String()) | ||||
| 
 | ||||
| 	dependencies := strings.Split(strings.TrimSpace(out.String()), "\n") | ||||
| 	for _, dep := range dependencies { | ||||
| @@ -77,15 +79,17 @@ func rpmFindDependencies(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Dir | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func rpmFindProvides(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories) error { | ||||
| 	return rpmFindDependencies(ctx, pkgInfo, dirs, "/usr/lib/rpm/find-provides", func(dep string) { | ||||
| type ALTLinuxFindProvReq struct{} | ||||
| 
 | ||||
| func (o *ALTLinuxFindProvReq) FindProvides(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error { | ||||
| 	return rpmFindDependenciesALTLinux(ctx, pkgInfo, dirs, "/usr/lib/rpm/find-provides", []string{"RPM_FINDPROV_SKIPLIST=" + strings.Join(skiplist, "\n")}, func(dep string) { | ||||
| 		slog.Info(gotext.Get("Provided dependency found"), "dep", dep) | ||||
| 		pkgInfo.Overridables.Provides = append(pkgInfo.Overridables.Provides, dep) | ||||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func rpmFindRequires(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories) error { | ||||
| 	return rpmFindDependencies(ctx, pkgInfo, dirs, "/usr/lib/rpm/find-requires", func(dep string) { | ||||
| func (o *ALTLinuxFindProvReq) FindRequires(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error { | ||||
| 	return rpmFindDependenciesALTLinux(ctx, pkgInfo, dirs, "/usr/lib/rpm/find-requires", []string{"RPM_FINDREQ_SKIPLIST=" + strings.Join(skiplist, "\n")}, func(dep string) { | ||||
| 		slog.Info(gotext.Get("Required dependency found"), "dep", dep) | ||||
| 		pkgInfo.Overridables.Depends = append(pkgInfo.Overridables.Depends, dep) | ||||
| 	}) | ||||
							
								
								
									
										39
									
								
								pkg/build/find_deps/empty.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								pkg/build/find_deps/empty.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| // ALR - Any Linux Repository | ||||
| // Copyright (C) 2025 Евгений Храмов | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // (at your option) any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  | ||||
| package finddeps | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"log/slog" | ||||
|  | ||||
| 	"github.com/goreleaser/nfpm/v2" | ||||
| 	"github.com/leonelquinteros/gotext" | ||||
|  | ||||
| 	"gitea.plemya-x.ru/Plemya-x/ALR/internal/types" | ||||
| ) | ||||
|  | ||||
| type EmptyFindProvReq struct{} | ||||
|  | ||||
| func (o *EmptyFindProvReq) FindProvides(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error { | ||||
| 	slog.Info(gotext.Get("AutoProv is not implemented for this package format, so it's skipped")) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (o *EmptyFindProvReq) FindRequires(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error { | ||||
| 	slog.Info(gotext.Get("AutoReq is not implemented for this package format, so it's skipped")) | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										118
									
								
								pkg/build/find_deps/fedora.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								pkg/build/find_deps/fedora.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,118 @@ | ||||
| // ALR - Any Linux Repository | ||||
| // Copyright (C) 2025 Евгений Храмов | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // (at your option) any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  | ||||
| package finddeps | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"log/slog" | ||||
| 	"os/exec" | ||||
| 	"path" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/goreleaser/nfpm/v2" | ||||
| 	"github.com/leonelquinteros/gotext" | ||||
|  | ||||
| 	"gitea.plemya-x.ru/Plemya-x/ALR/internal/types" | ||||
| ) | ||||
|  | ||||
| type FedoraFindProvReq struct{} | ||||
|  | ||||
| func rpmFindDependenciesFedora(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, command string, args []string, updateFunc func(string)) error { | ||||
| 	if _, err := exec.LookPath(command); err != nil { | ||||
| 		slog.Info(gotext.Get("Command not found on the system"), "command", command) | ||||
| 		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.CommandContext(ctx, command, args...) | ||||
| 	cmd.Stdin = bytes.NewBufferString(strings.Join(paths, "\n") + "\n") | ||||
| 	cmd.Env = append(cmd.Env, | ||||
| 		"RPM_BUILD_ROOT="+dirs.PkgDir, | ||||
| 	) | ||||
| 	var out bytes.Buffer | ||||
| 	var stderr bytes.Buffer | ||||
| 	cmd.Stdout = &out | ||||
| 	cmd.Stderr = &stderr | ||||
| 	if err := cmd.Run(); err != nil { | ||||
| 		slog.Error(stderr.String()) | ||||
| 		return err | ||||
| 	} | ||||
| 	slog.Debug(stderr.String()) | ||||
|  | ||||
| 	dependencies := strings.Split(strings.TrimSpace(out.String()), "\n") | ||||
| 	for _, dep := range dependencies { | ||||
| 		if dep != "" { | ||||
| 			updateFunc(dep) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (o *FedoraFindProvReq) FindProvides(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error { | ||||
| 	return rpmFindDependenciesFedora( | ||||
| 		ctx, | ||||
| 		pkgInfo, | ||||
| 		dirs, | ||||
| 		"/usr/lib/rpm/rpmdeps", | ||||
| 		[]string{ | ||||
| 			"--define=_use_internal_dependency_generator 1", | ||||
| 			"--provides", | ||||
| 			fmt.Sprintf( | ||||
| 				"--define=__provides_exclude_from %s\"", | ||||
| 				strings.Join(skiplist, "|"), | ||||
| 			), | ||||
| 		}, | ||||
| 		func(dep string) { | ||||
| 			slog.Info(gotext.Get("Provided dependency found"), "dep", dep) | ||||
| 			pkgInfo.Overridables.Provides = append(pkgInfo.Overridables.Provides, dep) | ||||
| 		}) | ||||
| } | ||||
|  | ||||
| func (o *FedoraFindProvReq) FindRequires(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error { | ||||
| 	return rpmFindDependenciesFedora( | ||||
| 		ctx, | ||||
| 		pkgInfo, | ||||
| 		dirs, | ||||
| 		"/usr/lib/rpm/rpmdeps", | ||||
| 		[]string{ | ||||
| 			"--define=_use_internal_dependency_generator 1", | ||||
| 			"--requires", | ||||
| 			fmt.Sprintf( | ||||
| 				"--define=__requires_exclude_from %s", | ||||
| 				strings.Join(skiplist, "|"), | ||||
| 			), | ||||
| 		}, | ||||
| 		func(dep string) { | ||||
| 			slog.Info(gotext.Get("Required dependency found"), "dep", dep) | ||||
| 			pkgInfo.Overridables.Depends = append(pkgInfo.Overridables.Depends, dep) | ||||
| 		}) | ||||
| } | ||||
							
								
								
									
										58
									
								
								pkg/build/find_deps/find_deps.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								pkg/build/find_deps/find_deps.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | ||||
| // ALR - Any Linux Repository | ||||
| // Copyright (C) 2025 Евгений Храмов | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // (at your option) any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  | ||||
| package finddeps | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
|  | ||||
| 	"github.com/goreleaser/nfpm/v2" | ||||
|  | ||||
| 	"gitea.plemya-x.ru/Plemya-x/ALR/internal/types" | ||||
| 	"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro" | ||||
| ) | ||||
|  | ||||
| type ProvReqFinder interface { | ||||
| 	FindProvides(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error | ||||
| 	FindRequires(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error | ||||
| } | ||||
|  | ||||
| type ProvReqService struct { | ||||
| 	finder ProvReqFinder | ||||
| } | ||||
|  | ||||
| func New(info *distro.OSRelease, pkgFormat string) *ProvReqService { | ||||
| 	s := &ProvReqService{ | ||||
| 		finder: &EmptyFindProvReq{}, | ||||
| 	} | ||||
| 	if pkgFormat == "rpm" { | ||||
| 		switch info.ID { | ||||
| 		case "altlinux": | ||||
| 			s.finder = &ALTLinuxFindProvReq{} | ||||
| 		case "fedora": | ||||
| 			s.finder = &FedoraFindProvReq{} | ||||
| 		} | ||||
| 	} | ||||
| 	return s | ||||
| } | ||||
|  | ||||
| func (s *ProvReqService) FindProvides(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error { | ||||
| 	return s.finder.FindProvides(ctx, pkgInfo, dirs, skiplist) | ||||
| } | ||||
|  | ||||
| func (s *ProvReqService) FindRequires(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error { | ||||
| 	return s.finder.FindRequires(ctx, pkgInfo, dirs, skiplist) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user