1
0

feat: less smart kbuild version guess

This commit is contained in:
dump_stack() 2023-05-29 11:21:20 +00:00
parent 7942bd22fa
commit 9271d69bc6
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 28 additions and 11 deletions

View File

@ -3,7 +3,6 @@ package debian
import ( import (
"errors" "errors"
"math" "math"
"sort"
"strings" "strings"
"time" "time"
@ -227,10 +226,6 @@ func getCachedKernel(deb string) (dk DebianKernel, err error) {
} }
func kbuildVersion(versions []string, kpkgver string) string { func kbuildVersion(versions []string, kpkgver string) string {
sort.Slice(versions, func(i, j int) bool {
return kver(versions[i]).GreaterThan(kver(versions[j]))
})
for _, v := range versions { for _, v := range versions {
if v == kpkgver { if v == kpkgver {
return v return v
@ -254,12 +249,6 @@ func kbuildVersion(versions []string, kpkgver string) string {
continue continue
} }
// Use the first version that is newer than the kernel
if ver.LessThan(cver) {
continue
}
return v return v
} }

View File

@ -5,6 +5,8 @@ import (
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot"
) )
func TestGetDebianKernel(t *testing.T) { func TestGetDebianKernel(t *testing.T) {
@ -37,3 +39,29 @@ func TestParseKernelVersion(t *testing.T) {
versions[dkv.Package] = true versions[dkv.Package] = true
} }
} }
func TestKbuildVersion(t *testing.T) {
assert := assert.New(t)
kernels, err := GetKernels()
assert.Nil(err)
assert.NotEmpty(kernels)
toolsVersions, err := snapshot.SourcePackageVersions("linux-tools")
assert.Nil(err)
for _, dk := range kernels {
if !kver(dk.Version.Package).LessThan(kver("4.5-rc0")) {
continue
}
version := kbuildVersion(
toolsVersions,
dk.Version.Package,
)
assert.Nil(err)
assert.NotEmpty(version)
t.Log(dk.Version.Package, "->", version)
}
}