Skip to content

Commit

Permalink
chore: remove libalpm13 support (#64)
Browse files Browse the repository at this point in the history
* remove libalpm.so=13 support

* fix build lint

* fix lint error
  • Loading branch information
Jguer authored Mar 23, 2024
1 parent e5b2e18 commit 3581fc9
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 256 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-git.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: Build and test go-alpm
runs-on: ubuntu-latest
container:
image: jguer/goalpm-builder:latest
image: jguer/yay-builder:latest
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
15 changes: 2 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,11 @@ jobs:
name: Build and test go-alpm
runs-on: ubuntu-latest
container:
image: jguer/goalpm-builder:latest
image: jguer/yay-builder:latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Lint
run: /app/bin/golangci-lint run ./...
- name: Run Build and Tests
run: make test
- name: Build and install pacman-git
run: |
useradd github
pacman -Sy --noconfirm --needed sudo base-devel git
echo "github ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
git clone https://aur.archlinux.org/pacman-git
chown -R github pacman-git
su github -c "cd pacman-git; yes | makepkg -si --nocheck"
- name: Run Build and Tests with pacman-git
run: make test

run: make test
43 changes: 28 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,52 @@ linters-settings:
- opinionated
- performance
- style
disabled-checks:
- dupImport
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/Jguer/go-alpm/v2
local-prefixes: github.com/Jguer/yay/v12
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
govet:
check-shadowing: true
checks:
- argument
- case
- condition
- return
ignored-numbers:
- "0"
- "1"
- "2"
- "3"
ignored-functions:
- strings.SplitN
lll:
line-length: 140
maligned:
suggest-new: true
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- forbidigo
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
- errorlint
- errcheck
- exportloopref
# - funlen # TOFIX
- gochecknoinits
- gocritic
# - goconst # TOFIX
# - gocritic
# - gocyclo # TOFIX
- gofmt
- goimports
# - gomnd # TOFIX
- goprintffuncname
- gosec
- gosimple
Expand All @@ -69,10 +79,12 @@ linters:
- whitespace

run:
go: "1.22"
timeout: "10m"

issues:
exclude-rules:
- path: _test\.go
- path: (.+)_test.go
linters:
- lll
- revive
Expand All @@ -84,6 +96,7 @@ issues:
- dupl
- gocritic
- gochecknoinits
- errorlint

exclude:
- G204
5 changes: 2 additions & 3 deletions callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

alpm "github.com/Jguer/go-alpm/v2"
"github.com/stretchr/testify/require"
)

type Cnt struct {
Expand All @@ -27,7 +28,5 @@ func TestCallbacks(t *testing.T) {

h.Release()

if cnt.cnt != 1 {
panic(nil)
}
require.Equal(t, 1, cnt.cnt)
}
14 changes: 13 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (db *DB) Search(targets []string) IPackageList {
needles = C.alpm_list_add(needles, unsafe.Pointer(C.CString(str)))
}

ok := C.alpm_db_search(db.ptr, needles, &ret) //nolint
ok := C.alpm_db_search(db.ptr, needles, &ret)
if ok != 0 {
return PackageList{nil, db.handle}
}
Expand All @@ -206,3 +206,15 @@ func (db *DB) Search(targets []string) IPackageList {

return PackageList{(*list)(unsafe.Pointer(ret)), db.handle}
}

// PkgCachebyGroup returns a PackageList of packages belonging to a group
func (l DBList) FindGroupPkgs(name string) IPackageList {
cName := C.CString(name)

defer C.free(unsafe.Pointer(cName))

pkglist := (*C.struct__alpm_list_t)(unsafe.Pointer(l.list))
pkgcache := (*list)(unsafe.Pointer(C.alpm_find_group_pkgs(pkglist, cName)))

return PackageList{pkgcache, l.handle}
}
32 changes: 0 additions & 32 deletions db_git.go

This file was deleted.

32 changes: 0 additions & 32 deletions db_six.go

This file was deleted.

9 changes: 3 additions & 6 deletions deps.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !next
// +build !next

package alpm

/*
Expand All @@ -20,8 +17,8 @@ func (l DBList) FindSatisfier(depstring string) (IPackage, error) {

defer C.free(unsafe.Pointer(cDepString))

pkgList := (*C.struct___alpm_list_t)(unsafe.Pointer(l.list))
pkgHandle := (*C.struct___alpm_handle_t)(unsafe.Pointer(l.handle.ptr))
pkgList := (*C.struct__alpm_list_t)(unsafe.Pointer(l.list))
pkgHandle := (*C.struct__alpm_handle_t)(unsafe.Pointer(l.handle.ptr))

ptr := C.alpm_find_dbs_satisfier(pkgHandle, pkgList, cDepString)
if ptr == nil {
Expand All @@ -38,7 +35,7 @@ func (l PackageList) FindSatisfier(depstring string) (IPackage, error) {

defer C.free(unsafe.Pointer(cDepString))

pkgList := (*C.struct___alpm_list_t)(unsafe.Pointer(l.list))
pkgList := (*C.struct__alpm_list_t)(unsafe.Pointer(l.list))

ptr := C.alpm_find_satisfier(pkgList, cDepString)
if ptr == nil {
Expand Down
50 changes: 0 additions & 50 deletions deps_git.go

This file was deleted.

30 changes: 30 additions & 0 deletions package.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ package alpm

/*
#include <alpm.h>
int pkg_cmp(const void *v1, const void *v2)
{
alpm_pkg_t *p1 = (alpm_pkg_t *)v1;
alpm_pkg_t *p2 = (alpm_pkg_t *)v2;
off_t s1 = alpm_pkg_get_isize(p1);
off_t s2 = alpm_pkg_get_isize(p2);
if (s1 > s2)
return -1;
else if (s1 < s2)
return 1;
else
return 0;
}
*/
import "C"

Expand Down Expand Up @@ -287,3 +302,18 @@ func (pkg *Package) ShouldIgnore() bool {
func (pkg *Package) Type() string {
return "alpm"
}

// SortBySize returns a PackageList sorted by size.
func (l PackageList) SortBySize() IPackageList {
pkgList := (*C.struct__alpm_list_t)(unsafe.Pointer(l.list))

pkgCache := (*list)(unsafe.Pointer(
C.alpm_list_msort(pkgList, //nolint
C.alpm_list_count(pkgList),
C.alpm_list_fn_cmp(C.pkg_cmp))))
if pkgCache == nil {
return nil
}

return PackageList{pkgCache, l.handle}
}
Loading

0 comments on commit 3581fc9

Please sign in to comment.