1
0

feat: parameter to refetch kbuild

This commit is contained in:
dump_stack() 2023-05-29 11:47:40 +00:00
parent 9271d69bc6
commit e141f46892
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
4 changed files with 49 additions and 24 deletions

View File

@ -25,7 +25,7 @@ jobs:
run: go build
- name: Cache
run: ./out-of-tree --log-level=trace distro debian cache --refetch=0 --limit=128 --update-release
run: ./out-of-tree --log-level=trace distro debian cache --refetch=0 --limit=128 --update-release --update-kbuild
- name: Install s3cmd
run: sudo apt install s3cmd

View File

@ -39,6 +39,7 @@ type DebianCacheCmd struct {
Path string `help:"path to cache"`
Refetch int `help:"days before refetch versions without deb package" default:"7"`
UpdateRelease bool `help:"update release data"`
UpdateKbuild bool `help:"update kbuild package"`
Dump bool `help:"dump cache"`
}
@ -56,7 +57,10 @@ func (cmd *DebianCacheCmd) Run(dcmd *DebianCmd) (err error) {
mode := debian.NoMode
if cmd.UpdateRelease {
mode = debian.UpdateRelease
mode |= debian.UpdateRelease
}
if cmd.UpdateKbuild {
mode |= debian.UpdateKbuild
}
kernels, err := debian.GetKernelsWithLimit(dcmd.Limit, mode)

View File

@ -278,6 +278,30 @@ func findKbuild(versions []string, kpkgver string) (
return
}
func updateKbuild(toolsVersions []string, dk *DebianKernel) {
if !kver(dk.Version.Package).LessThan(kver("4.5-rc0")) {
dk.Internal.Invalid = true
return
}
var deps []snapshot.Package
for _, pkg := range dk.Dependencies {
if strings.Contains(pkg.Name, "kbuild") {
continue
}
deps = append(deps, pkg)
}
dk.Dependencies = deps
kbuildpkg, err := findKbuild(toolsVersions, dk.Version.Package)
if err != nil {
dk.Internal.Invalid = true
return
}
dk.Dependencies = append(dk.Dependencies, kbuildpkg)
}
func getKernelsByVersion(slog zerolog.Logger, c *Cache, toolsVersions []string,
version string, mode GetKernelsMode) (kernels []DebianKernel,
fromcache bool) {
@ -287,6 +311,7 @@ func getKernelsByVersion(slog zerolog.Logger, c *Cache, toolsVersions []string,
if err == nil {
dk = dks[0]
if !dk.Internal.Invalid {
// TODO refactor
slog.Trace().Msgf("found in cache")
if dk.Release == None && mode&UpdateRelease != 0 {
slog.Debug().Msg("update release")
@ -300,6 +325,16 @@ func getKernelsByVersion(slog zerolog.Logger, c *Cache, toolsVersions []string,
}
}
}
if mode&UpdateKbuild != 0 {
slog.Debug().Msg("update kbuild")
updateKbuild(toolsVersions, &dk)
slog.Debug().Msg("update cache")
err = c.Put([]DebianKernel{dk})
if err != nil {
slog.Error().Err(err).Msg("")
return
}
}
kernels = append(kernels, dk)
fromcache = true
return
@ -326,26 +361,11 @@ func getKernelsByVersion(slog zerolog.Logger, c *Cache, toolsVersions []string,
}
if !dk.HasDependency("kbuild") {
if !kver(dk.Version.Package).LessThan(kver("4.5-rc0")) {
dk.Internal.Invalid = true
} else {
// Debian kernels prior to the 4.5 package
// version did not have a kbuild built from
// the linux source itself, but used the
// linux-tools source package.
kbuildpkg, err := findKbuild(
toolsVersions,
dk.Version.Package,
)
if err != nil {
dk.Internal.Invalid = true
} else {
dk.Dependencies = append(
dk.Dependencies,
kbuildpkg,
)
}
}
updateKbuild(toolsVersions, &dk)
}
dk.Internal.LastFetch = time.Now()
@ -374,6 +394,7 @@ type GetKernelsMode int
const (
NoMode GetKernelsMode = iota
UpdateRelease
UpdateKbuild
)
// GetKernelsWithLimit is workaround for testing and building the

View File

@ -23,7 +23,7 @@ func TestGetDebianKernel(t *testing.T) {
func TestParseKernelVersion(t *testing.T) {
assert := assert.New(t)
kernels, err := GetKernels()
kernels, err := GetKernelsWithLimit(16, NoMode)
assert.Nil(err)
assert.NotEmpty(kernels)
@ -43,7 +43,7 @@ func TestParseKernelVersion(t *testing.T) {
func TestKbuildVersion(t *testing.T) {
assert := assert.New(t)
kernels, err := GetKernels()
kernels, err := GetKernelsWithLimit(16, NoMode)
assert.Nil(err)
assert.NotEmpty(kernels)