-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkg_base.go
98 lines (82 loc) · 2.02 KB
/
pkg_base.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package pkgcraft
// #cgo pkg-config: pkgcraft
// #include <pkgcraft.h>
import "C"
import (
"runtime"
)
type BasePkg struct {
ptr *C.Pkg
format PkgFormat
// cached fields
eapi *Eapi
cpv *Cpv
}
func (self *BasePkg) p() *C.Pkg {
return self.ptr
}
// Return a package's package and version.
func (self *BasePkg) P() string {
return self.Cpv().P()
}
// Return a package's package, version, and revision.
func (self *BasePkg) Pf() string {
return self.Cpv().Pf()
}
// Return an package's revision.
func (self *BasePkg) Pr() string {
return self.Cpv().Pr()
}
// Return an package's version.
func (self *BasePkg) Pv() string {
return self.Cpv().Pv()
}
// Return a package's version and revision.
func (self *BasePkg) Pvr() string {
return self.Cpv().Pvr()
}
// Return a package's Cpv.
func (self *BasePkg) Cpv() *Cpv {
if self.cpv == nil {
ptr := C.pkgcraft_pkg_cpv(self.ptr)
self.cpv, _ = cpvFromPtr(ptr)
}
return self.cpv
}
// Return a package's Cpn.
func (self *BasePkg) Cpn() *Cpn {
return self.Cpv().Cpn()
}
// Return a package's EAPI.
func (self *BasePkg) Eapi() *Eapi {
if self.eapi == nil {
ptr := C.pkgcraft_pkg_eapi(self.ptr)
s := C.pkgcraft_eapi_as_str(ptr)
defer C.pkgcraft_str_free(s)
self.eapi = EAPIS[C.GoString(s)]
}
return self.eapi
}
// Return a package's repo.
func (self *BasePkg) Repo() *BaseRepo {
ptr := C.pkgcraft_pkg_repo(self.ptr)
repo := repoFromPtr(ptr)
runtime.SetFinalizer(repo, func(self *BaseRepo) { C.pkgcraft_repo_free(self.ptr) })
return repo
}
// Return a package's version.
func (self *BasePkg) Version() *Version {
ptr := C.pkgcraft_pkg_version(self.ptr)
version, _ := versionFromPtr(ptr)
return version
}
func (self *BasePkg) String() string {
s := C.pkgcraft_pkg_str(self.ptr)
defer C.pkgcraft_str_free(s)
return C.GoString(s)
}
// Compare a package with another package returning -1, 0, or 1 if the first is
// less than, equal to, or greater than the second, respectively.
func (self *BasePkg) Cmp(other pkgPtr) int {
return int(C.pkgcraft_pkg_cmp(self.ptr, other.p()))
}