From 57acc40a56f02061af8af5b298dcf74d111f47f3 Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Tue, 16 May 2023 02:53:04 +0200 Subject: [PATCH] switched to KCFLAGS/KCPPFLAGS to build kernels instead of patching --- config_dist.yaml | 13 ------ flags.yaml | 2 + proto_package.go | 105 ----------------------------------------------- 3 files changed, 2 insertions(+), 118 deletions(-) diff --git a/config_dist.yaml b/config_dist.yaml index ab230e4..492d26e 100644 --- a/config_dist.yaml +++ b/config_dist.yaml @@ -8,19 +8,6 @@ svn2git: upstream-core-extra: "https://github.com/archlinux/svntogit-packages.git" upstream-community: "https://github.com/archlinux/svntogit-community.git" -kernel_to_patch: - - linux - - linux-lts - - linux-zen - - linux-hardened - -kernel_patches: - 4.19: "https://raw.githubusercontent.com/graysky2/kernel_compiler_patch/master/more-uarches-for-kernel-4.19-5.4.patch" - 5.5: "none" - 5.8: "https://raw.githubusercontent.com/graysky2/kernel_compiler_patch/master/more-uarches-for-kernel-5.8-5.14.patch" - 5.15: "https://raw.githubusercontent.com/graysky2/kernel_compiler_patch/master/more-uarches-for-kernel-5.15%2B.patch" - linux-zen: "skip" - db: driver: pgx connect_to: "postgres://username:password@localhost:5432/database_name" diff --git a/flags.yaml b/flags.yaml index 196ddeb..f95fe3a 100644 --- a/flags.yaml +++ b/flags.yaml @@ -23,6 +23,8 @@ common: rustflags: "-Copt-level=3 -Ctarget-cpu=$march$" ltoflags: - "-falign-functions=32" # https://github.com/InBetweenNames/gentooLTO/issues/164 + kcflags: " -march=$march$ -O3" + kcppflags: " -march=$march$ -O3" lto: rustflags: diff --git a/proto_package.go b/proto_package.go index a89ff87..e36d8c5 100644 --- a/proto_package.go +++ b/proto_package.go @@ -3,8 +3,6 @@ package main import ( "bytes" "context" - "crypto/sha256" - "encoding/hex" "errors" "fmt" "github.com/Jguer/go-alpm/v2" @@ -14,7 +12,6 @@ import ( "github.com/otiai10/copy" log "github.com/sirupsen/logrus" "io" - "net/http" "os" "os/exec" "path/filepath" @@ -198,14 +195,6 @@ func (p *ProtoPackage) build(ctx context.Context) (time.Duration, error) { return time.Since(start), fmt.Errorf("error while increasing pkgrel: %w", err) } - if Contains(conf.KernelToPatch, p.Pkgbase) { - err = p.prepareKernelPatches() - if err != nil { - p.DBPackage.Update().SetStatus(dbpackage.StatusFailed).SetSkipReason("failed to apply patch").SetHash(p.Hash).ExecX(ctx) - return time.Since(start), fmt.Errorf("error modifying PKGBUILD for kernel patch: %w", err) - } - } - p.PkgFiles = []string{} // default to LTO @@ -431,100 +420,6 @@ func (p *ProtoPackage) increasePkgRel(buildNo int) error { return nil } -func (p *ProtoPackage) prepareKernelPatches() error { - f, err := os.OpenFile(p.Pkgbuild, os.O_RDWR, 0o644) - if err != nil { - return err - } - - defer func(f *os.File) { - err := f.Close() - if err != nil { - panic(err) - } - }(f) - - fStr, err := io.ReadAll(f) - if err != nil { - return err - } - - // choose best suited patch based on kernel version - var curVer string - for k := range conf.KernelPatches { - if k == p.Pkgbase { - curVer = k - break - } - if alpm.VerCmp(p.Srcinfo.Pkgver, k) >= 0 && alpm.VerCmp(k, curVer) >= 0 { - curVer = k - } - } - - newPKGBUILD := string(fStr) - switch { - case conf.KernelPatches[curVer] == "none": - return fmt.Errorf("no patch available") - case conf.KernelPatches[curVer] == "skip": - log.Debugf("[KP] skipped patching for %s", p.Pkgbase) - default: - log.Debugf("[KP] choose patch %s for kernel %s", curVer, p.Srcinfo.Pkgver) - orgSource := rePkgSource.FindStringSubmatch(newPKGBUILD) - if orgSource == nil || len(orgSource) < 1 { - return fmt.Errorf("no source=() found") - } - sources := strings.Split(orgSource[1], "\n") - sources = append(sources, fmt.Sprintf("%q", conf.KernelPatches[curVer])) - newPKGBUILD = rePkgSource.ReplaceAllLiteralString(newPKGBUILD, fmt.Sprintf("source=(%s)", strings.Join(sources, "\n"))) - resp, err := http.Get(conf.KernelPatches[curVer]) //nolint:bodyclose,noctx - if err != nil || resp.StatusCode != 200 { - return err - } - h := sha256.New() - _, err = io.Copy(h, resp.Body) - defer func(Body io.ReadCloser) { - _ = Body.Close() - }(resp.Body) - if err != nil { - return err - } - orgSums := rePkgSum.FindStringSubmatch(newPKGBUILD) - if orgSums == nil || len(orgSums) < 1 { - return fmt.Errorf("no sha256sums=() found") - } - sums := strings.Split(orgSums[1], "\n") - sums = append(sums, fmt.Sprintf("'%s'", hex.EncodeToString(h.Sum(nil)))) - newPKGBUILD = rePkgSum.ReplaceAllLiteralString(newPKGBUILD, fmt.Sprintf("sha256sums=(\n%s\n)", strings.Join(sums, "\n"))) - } - - // enable config option - switch { - case strings.Contains(p.March, "v4"): - newPKGBUILD = strings.Replace(newPKGBUILD, "make olddefconfig\n", "echo CONFIG_GENERIC_CPU4=y >> .config\nmake olddefconfig\n", 1) - case strings.Contains(p.March, "v3"): - newPKGBUILD = strings.Replace(newPKGBUILD, "make olddefconfig\n", "echo CONFIG_GENERIC_CPU3=y >> .config\nmake olddefconfig\n", 1) - case strings.Contains(p.March, "v2"): - newPKGBUILD = strings.Replace(newPKGBUILD, "make olddefconfig\n", "echo CONFIG_GENERIC_CPU2=y >> .config\nmake olddefconfig\n", 1) - } - - // empty file before writing - _, err = f.Seek(0, 0) - if err != nil { - return err - } - err = f.Truncate(0) - if err != nil { - return err - } - - _, err = f.WriteString(newPKGBUILD) - if err != nil { - return err - } - - return nil -} - func (p *ProtoPackage) importKeys() error { if p.Srcinfo == nil { err := p.genSrcinfo()