github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/spec/distro/pkg.go (about) 1 package distro 2 3 import ( 4 "log" 5 6 "github.com/metux/go-metabuild/util" 7 "github.com/metux/go-metabuild/util/pkgmgr" 8 "github.com/metux/go-metabuild/util/specobj" 9 ) 10 11 const ( 12 KeyPkgName = Key("name") 13 KeyPkgVersion = Key("version") 14 KeyPkgDescription = Key("description") 15 KeyPkgArch = Key("arch") 16 KeyPkgMaintainer = Key("maintainer") 17 KeyPkgSection = Key("section") 18 KeyPkgLocalDepend = Key("local-depend") 19 KeyPkgExtdepend = Key("pkg-depend") 20 KeyPkgBugs = Key("bugs") 21 KeyPkgHomepage = Key("homepage") 22 KeyPkgOrigin = Key("origin") 23 KeyPkgPriority = Key("priority") 24 KeyPkgSkip = Key("skip") 25 ) 26 27 type DistPkg struct { 28 specobj.SpecObj 29 Distro Distro 30 } 31 32 func (pkg DistPkg) Id() string { 33 return pkg.EntryStr(Key("@@KEY")) 34 } 35 36 func (pkg DistPkg) DistroName() string { 37 return pkg.Distro.Name() 38 } 39 40 func (pkg DistPkg) Name() string { 41 return pkg.EntryStr(KeyPkgName) 42 } 43 44 func (pkg DistPkg) Version() string { 45 return pkg.EntryStr(KeyPkgVersion) 46 } 47 48 func (pkg DistPkg) Description() string { 49 return pkg.EntryStr(KeyPkgDescription) 50 } 51 52 func (pkg DistPkg) Arch() string { 53 return pkg.EntryStr(KeyPkgArch) 54 } 55 56 func (pkg DistPkg) Maintainer() string { 57 return pkg.EntryStr(KeyPkgMaintainer) 58 } 59 60 func (pkg DistPkg) Section() string { 61 return pkg.EntryStr(KeyPkgSection) 62 } 63 64 func (pkg DistPkg) Depends() []string { 65 return pkg.EntryStrList(KeyPkgLocalDepend) 66 } 67 68 func (pkg DistPkg) ControlInfo(deps []string) pkgmgr.PkgControl { 69 70 // add our local deps 71 for _, d := range pkg.Depends() { 72 p := pkg.Distro.Package(d) 73 if p.Skipped() { 74 log.Println("skipping package:", p.Name()) 75 } else { 76 deps = append(deps, p.Name()+" (>="+p.Version()+")") 77 } 78 } 79 80 return pkgmgr.PkgControl{ 81 Package: pkg.EntryStr(KeyPkgName), 82 Version: pkg.EntryStr(KeyPkgVersion), 83 Description: pkg.EntryStr(KeyPkgDescription), 84 Architecture: pkg.EntryStr(KeyPkgArch), 85 Maintainer: pkg.EntryStr(KeyPkgMaintainer), 86 Section: pkg.EntryStr(KeyPkgSection), 87 Origin: pkg.EntryStr(KeyPkgOrigin), 88 Homepage: pkg.EntryStr(KeyPkgHomepage), 89 Bugs: pkg.EntryStr(KeyPkgBugs), 90 Priority: pkg.EntryStr(KeyPkgPriority), 91 Depend: util.Uniq(pkg.EntryStrList("pkg-depend"), deps), 92 } 93 } 94 95 func (pkg DistPkg) Skipped() bool { 96 return pkg.EntryBoolDef(KeyPkgSkip, false) 97 } 98 99 func NewDistPkg(so specobj.SpecObj, d Distro) DistPkg { 100 return DistPkg{so, d} 101 }