srcinfo

package module
v0.0.0-...-cd3b76a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

README

GPL3 license GoDoc Build Status codecov Go Report Card

go-srcinfo

A golang package for parsing .SRCINFO files. SRCINFO

go-srcinfo aimes to be simple while ensuring each srcinfo is syntactically correct. Split packages and architecture specific fields are fully supported.

Examples

Reading a srcinfo from a file

package main

import (
	"fmt"
	"github.com/pacstall/go-srcinfo"
)

func main() {
	info, err := srcinfo.ParseFile("SRCINFO")
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(info)
}

Reading each package from a split package

package main

import (
	"fmt"
	"github.com/pacstall/go-srcinfo"
)

func main() {
	info, err := srcinfo.ParseFile("SRCINFO")
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, pkg := range info.SplitPackages() {
		fmt.Printf("%s-%s: %s\n", pkg.Pkgname, info.Version(), pkg.Pkgdesc)
	}
}

Showing the architecture of each source

package main

import (
	"fmt"
	"github.com/pacstall/go-srcinfo"
)

func main() {
	info, err := srcinfo.ParseFile("SRCINFO")
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, source := range info.Source {
		if source.Arch == "" {
			fmt.Printf("This source is for %s: %s\n", "any", source.Value)
		} else {
			fmt.Printf("This source is for %s: %s\n", source.Arch, source.Value)
		}
	}
}

Reading a srcinfo from a string

package main

import (
	"fmt"
	"github.com/pacstall/go-srcinfo"
)

const str = `
pkgbase = gdc-bin
	pkgver = 6.3.0+2.068.2
	pkgrel = 1
	url = https://gdcproject.org/
	arch = i686
	arch = x86_64
	license = GPL
	source_i686 = http://gdcproject.org/downloads/binaries/6.3.0/i686-linux-gnu/gdc-6.3.0+2.068.2.tar.xz
	md5sums_i686 = cc8dcd66b189245e39296b1382d0dfcc
	source_x86_64 = http://gdcproject.org/downloads/binaries/6.3.0/x86_64-linux-gnu/gdc-6.3.0+2.068.2.tar.xz
	md5sums_x86_64 = 16d3067ebb3938dba46429a4d9f6178f

pkgname = gdc-bin
	pkgdesc = Compiler for D programming language which uses gcc backend
	depends = gdc-gcc
	depends = perl
	depends = binutils
	depends = libgphobos
	provides = d-compiler=2.068.2
	provides = gdc=6.3.0+2.068.2

pkgname = gdc-gcc
	pkgdesc = The GNU Compiler Collection - C and C++ frontends (from GDC, gdcproject.org)
	provides = gcc=6.3.0
	provides = gcc-libs=6.3.0

pkgname = libgphobos-lib32
	pkgdesc = Standard library for D programming language, GDC port
	provides = d-runtime-lib32
	provides = d-stdlib-lib32
`
func main() {
	info, err := srcinfo.Parse(str)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(info)
}

Documentation

Overview

Package srcinfo is a parser for srcinfo files. Typically generated by makepkg, part of the pacman package manager.

Split packages and architecture dependent fields are fully supported.

This Package aims to parse srcinfos but not interpret them in any way. All values are fundamentally strings, other tools should be used for things such as dependency parsing, validity checking etc.

Example (Parse_file)
info, err := srcinfo.ParseFile(SRCINFO)
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println(info)
Output:

Example (Parse_string)
info, err := srcinfo.Parse(str)
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println(info)
Output:

Example (Show_architecture_dependant_sources)
info, err := srcinfo.ParseFile(SRCINFO)
if err != nil {
	fmt.Println(err)
	return
}

for _, source := range info.Source {
	if source.Arch == "" {
		fmt.Printf("This source is for %s: %s\n", "any", source.Value)
	} else {
		fmt.Printf("This source is for %s: %s\n", source.Arch, source.Value)
	}
}
Output:

Example (Show_split_packages)
info, err := srcinfo.ParseFile(SRCINFO)
if err != nil {
	fmt.Println(err)
	return
}

for _, pkg := range info.SplitPackages() {
	fmt.Printf("%s-%s: %s\n", pkg.Pkgname, info.Version(), pkg.Pkgdesc)
}
Output:

Index

Examples

Constants

View Source
const EmptyOverride = "\x00"

EmptyOverride is used to signal when a value has been overridden with an empty value. An empty ovrride is when a value is defined in the pkgbuild but then overridden inside the package function to be empty.

For example "pkgdesc=”" is an empty override on the pkgdesc which would lead to the line "pkgdesc=" in the srcinfo.

This value is used internally to store empty overrides, mainly to avoid using string pointers. It is possible to check for empty overrides using the Packages slice in Packagebase.

During normal use with the SplitPackage function this value will be converted back to an empty string, or removed entirely for slice values. This means the this value can be completley ignored unless you are explicitly looking for empty overrides.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArchDistroString

type ArchDistroString struct {
	Arch   string // Architecture name
	Distro string // Distribution
	Value  string // Value
}

ArchDistroString describes string values that may be architecture dependent. For Example depends_x86_64. If Arch is an empty string then the field is not architecture dependent.

type LineError

type LineError struct {
	LineNumber int    // The line number at which the error occurred
	Line       string // The line that caused the error
	ErrorStr   string // An error string
}

LineError is an error type that stores the line number at which an error occurred as well the full Line that cased the error and an error string.

func Error

func Error(LineNumber int, Line string, ErrorStr string) *LineError

Error Returns a new LineError

func Errorf

func Errorf(LineNumber int, Line string, ErrorStr string, args ...interface{}) *LineError

Errorf Returns a new LineError using the same formatting rules as fmt.Printf.

func (LineError) Error

func (le LineError) Error() string

Error Returns an error string in the format: "Line <LineNumber>: <ErrorStr>: <Line>".

type Package

type Package struct {
	Pkgname        string
	Pkgdesc        string
	URL            string
	Priority       string
	Arch           []string
	License        []string
	Gives          []ArchDistroString
	Depends        []ArchDistroString
	CheckDepends   []ArchDistroString
	OptDepends     []ArchDistroString
	Pacdeps        []ArchDistroString
	CheckConflicts []ArchDistroString
	Conflicts      []ArchDistroString
	Provides       []ArchDistroString
	Breaks         []ArchDistroString
	Replaces       []ArchDistroString
	Enhances       []ArchDistroString
	Recommends     []ArchDistroString
	Suggests       []ArchDistroString
	Backup         []string
	Repology       []string
}

Package describes the fields of a pkgbuild that may be overwritten by in build_<pkgname> function.

type PackageBase

type PackageBase struct {
	Pkgbase       string
	Pkgver        string
	Pkgrel        string
	Epoch         string
	Mask          []string
	Compatible    []string
	Incompatible  []string
	Maintainer    []string
	Source        []ArchDistroString
	NoExtract     []string
	NoSubmodules  []string
	MD5Sums       []ArchDistroString
	SHA1Sums      []ArchDistroString
	SHA224Sums    []ArchDistroString
	SHA256Sums    []ArchDistroString
	SHA384Sums    []ArchDistroString
	SHA512Sums    []ArchDistroString
	B2Sums        []ArchDistroString
	MakeDepends   []ArchDistroString
	MakeConflicts []ArchDistroString
}

PackageBase describes the fields of a pkgbuild that may not be overwritten in package_<pkgname> function.

type Srcinfo

type Srcinfo struct {
	PackageBase           // Fields that only apply to the package base
	Package               // Fields that apply to the package globally
	Packages    []Package // Fields for each package this package base contains
}

Srcinfo represents a full srcinfo. All global fields are defined here while fields overwritten in the package_<pkgname> function are defined in the Packages field.

Note: The Packages field only contains the values that each package overrides, global fields will be missing. A Package containing both global and overwritten fields can be generated using the SplitPackage function.

func Parse

func Parse(data string) (*Srcinfo, error)

Parse parses a srcinfo in string form. Parsing will fail if:

A srcinfo does not contain all required fields
The same pkgname is specified more then once
arch is missing
pkgver is mising
pkgrel is missing
An architecture specific field is defined for an architecture that does not exist
An unknown key is specified
An empty value is specified

Required fields are:

pkgbase
pkname
arch
pkgrel
pkgver

func ParseFile

func ParseFile(path string) (*Srcinfo, error)

ParseFile parses a srcinfo file as specified by path.

func (*Srcinfo) SplitPackage

func (si *Srcinfo) SplitPackage(pkgname string) (*Package, error)

SplitPackage generates a Package that contains all fields that the specified pkgname has. But will fall back on global fields if they are not defined in the Package.

Note slice values will be passed by reference, it is not recommended you modify this struct after it is returned.

func (*Srcinfo) SplitPackages

func (si *Srcinfo) SplitPackages() []*Package

SplitPackages generates a splice of all packages that are part of this srcinfo. This is equivalent to calling SplitPackage on every pkgname.

func (*Srcinfo) String

func (si *Srcinfo) String() string

String generates a string that should be similar to the srcinfo data used to create this Srcinfo struct. Fields will be printed in order and with the same whitespace rules that `makepkg --printsrcinfo` uses.

The order of each global field is as follows:

pkgdesc
pkgver
pkgrel
epoch
url
install
changelog
arch
groups
license
checkdepends
makedepends
depends
optdepends
provides
conflicts
replaces
noextract
options
backup
source
validpgpkeys
md5suns
sha1sums
sha224sums
sha256sums
sha384sums
sha512sums

The order of each overwritten field is as follows:

pkgdesc
url
install
changelog
arch
groups
license
checkdepends
depends
optdepends
provides
conflicts
replaces
options
backup

func (*Srcinfo) Version

func (si *Srcinfo) Version() string

Version formats a version string from the epoch, pkgver and pkgrel of the srcinfo. In the format [epoch:]pkgver-pkgrel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL