Skip to content

Commit

Permalink
feat(alpm): Add changes for pacman-git (#54)
Browse files Browse the repository at this point in the history
* update gitignore

* specify test packages

* add pacman-git changes

* separate git test

* add go flags for -git
  • Loading branch information
Jguer committed Mar 4, 2022
1 parent a5e5513 commit 2a4af8a
Show file tree
Hide file tree
Showing 16 changed files with 286 additions and 61 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/test-git.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test pacman-git
# This workflow is triggered on pushes to the repository.
on:
push:
branches-ignore:
- pacman*
paths-ignore:
- "examples/**"
- "Dockerfile"
- "**/builder-image.yml"
pull_request:

jobs:
build:
name: Build and test go-alpm
runs-on: ubuntu-latest
container:
image: jguer/goalpm-builder:latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build and install pacman-git
run: |
useradd github
pacman -Syu --noconfirm --overwrite=* --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
29 changes: 28 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
_obj/
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test
.vscode

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

*.exe
*.test
*.prof
*.tar.gz
qemu-*
.go

# Locale
*.mo
*.pot
*.po~
*.pprof
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ export GO111MODULE=on
GO ?= go

SOURCES ?= $(shell find . -name "*.go")
GOFLAGS += $(shell pacman -T 'pacman-git' && echo "-tags next")

.PHONY: test
test:
@test -z "$$(gofmt -l *.go)" || (echo "Files need to be linted. Use make fmt" && false)
$(GO) test -v .
$(GO) test $(GOFLAGS) -v ./...

.PHONY: fmt
fmt:
Expand Down
2 changes: 1 addition & 1 deletion alpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package alpm_test
import (
"testing"

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

Expand Down
2 changes: 1 addition & 1 deletion callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package alpm_test
import (
"testing"

"github.com/Jguer/go-alpm/v2"
alpm "github.com/Jguer/go-alpm/v2"
)

type Cnt struct {
Expand Down
15 changes: 1 addition & 14 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ func (db *DB) SetServers(servers []string) {
for _, srv := range servers {
Csrv := C.CString(srv)

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

C.alpm_db_add_server(db.ptr, Csrv)
C.free(unsafe.Pointer(Csrv))
}
}

Expand Down Expand Up @@ -155,18 +154,6 @@ func (db *DB) Pkg(name string) IPackage {
return &Package{ptr, 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}
}

// PkgCache returns the list of packages of the database
func (db *DB) PkgCache() IPackageList {
pkgcache := (*list)(unsafe.Pointer(C.alpm_db_get_pkgcache(db.ptr)))
Expand Down
31 changes: 31 additions & 0 deletions db_git.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//go:build next

// db.go - Functions for database handling.
//
// Copyright (c) 2013 The go-alpm Authors
//
// MIT Licensed. See LICENSE for details.

package alpm

/*
#include <alpm.h>
#include <alpm_list.h>
*/
import "C"

import (
"unsafe"
)

// 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}
}
31 changes: 31 additions & 0 deletions db_six.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//go:build !next

// db.go - Functions for database handling.
//
// Copyright (c) 2013 The go-alpm Authors
//
// MIT Licensed. See LICENSE for details.

package alpm

/*
#include <alpm.h>
#include <alpm_list.h>
*/
import "C"

import (
"unsafe"
)

// 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}
}
2 changes: 2 additions & 0 deletions deps.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !next

package alpm

/*
Expand Down
49 changes: 49 additions & 0 deletions deps_git.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//go:build next

package alpm

/*
#include <alpm.h>
*/
import "C"

import (
"fmt"
"unsafe"
)

// FindSatisfier searches a DBList for a package that satisfies depstring
// Example "glibc>=2.12"
func (l DBList) FindSatisfier(depstring string) (IPackage, error) {
cDepString := C.CString(depstring)

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))

ptr := C.alpm_find_dbs_satisfier(pkgHandle, pkgList, cDepString)
if ptr == nil {
return nil,
fmt.Errorf("unable to satisfy dependency %s in DBlist", depstring)
}

return &Package{ptr, l.handle}, nil
}

// FindSatisfier finds a package that satisfies depstring from PkgList
func (l PackageList) FindSatisfier(depstring string) (IPackage, error) {
cDepString := C.CString(depstring)

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

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

ptr := C.alpm_find_satisfier(pkgList, cDepString)
if ptr == nil {
return nil,
fmt.Errorf("unable to find dependency %s in PackageList", depstring)
}

return &Package{ptr, l.handle}, nil
}
2 changes: 1 addition & 1 deletion handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (h *Handle) optionSetList(hookDirs []string, f func(*C.alpm_handle_t, *C.al
cDir := C.CString(dir)
list = C.alpm_list_add(list, unsafe.Pointer(cDir))

defer C.free(unsafe.Pointer(cDir))
C.free(unsafe.Pointer(cDir))
}

if ok := f(h.ptr, list); ok < 0 {
Expand Down
46 changes: 8 additions & 38 deletions package.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@ 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 @@ -61,21 +46,6 @@ func (l PackageList) Slice() []IPackage {
return slice
}

// 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}
}

// DependList describes a linkedlist of dependency type packages.
type DependList struct{ *list }

Expand Down Expand Up @@ -277,14 +247,14 @@ func (pkg *Package) ComputeRequiredBy() []string {
requiredby := make([]string, 0)

for i := (*list)(unsafe.Pointer(result)); i != nil; i = i.Next {
defer C.free(unsafe.Pointer(i))

if i.Data != nil {
defer C.free(i.Data)

name := C.GoString((*C.char)(i.Data))
requiredby = append(requiredby, name)

C.free(i.Data)
}

C.free(unsafe.Pointer(i))
}

return requiredby
Expand All @@ -296,14 +266,14 @@ func (pkg *Package) ComputeOptionalFor() []string {
optionalfor := make([]string, 0)

for i := (*list)(unsafe.Pointer(result)); i != nil; i = i.Next {
defer C.free(unsafe.Pointer(i))

if i.Data != nil {
defer C.free(i.Data)

name := C.GoString((*C.char)(i.Data))
optionalfor = append(optionalfor, name)

C.free(i.Data)
}

C.free(unsafe.Pointer(i))
}

return optionalfor
Expand Down
48 changes: 48 additions & 0 deletions package_git.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//go:build next

// package.go - libalpm package type and methods.
//
// Copyright (c) 2013 The go-alpm Authors
//
// MIT Licensed. See LICENSE for details.

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"

import (
"unsafe"
)

// 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 2a4af8a

Please sign in to comment.