pkg

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: MIT Imports: 15 Imported by: 0

README

pkg

a simple c/c++ package manager based on source code.

Usage

  • Quick Start
$ go get -u github.com/genshen/pkg/pkg

# generate a new "package.yaml"
$ pkg init

# install a package,type can be "git", "tar", "files" for now. 
$ pkg fetch <type> <packagename>

# build and install packages from "package.yaml" file.
$ pkg install

# build and install a package specified by argument --pkg.
$ pkg install -pkg=<package_name>  # or: pkg install --pkg <package_name>

Documentation

Index

Constants

View Source
const (
	DlStatusEmpty = iota
	DlStatusSkip
	DlStatusOk
)
View Source
const (
	InsCmake   = "CMAKE" // run cmake configuration and build,install
	InsAutoPkg = "AUTO_PKG"
)

this shows the supported instructions in pkg

View Source
const (
	VendorName        = "vendor"
	VendorCache       = "cache"
	VendorSrc         = "src"
	VendorPkg         = "pkg"
	VendorScripts     = "scripts"
	VendorInclude     = "include"
	VendorLib         = "lib"
	VendorLib64       = "lib64"
	VendorUserHome    = ".pkg"
	VendorUserHomeSrc = "registry/default-pkg/src"
)
View Source
const (
	PkgFileName         = "pkg.yaml"
	PurgePkgSumFileName = "pkg.sum.yaml"
	PkgSumFileName      = VendorName + "/" + PurgePkgSumFileName
	VendorSrcDir        = VendorName + "/" + "src"
	BuildShellName      = "pkg.build.sh"
	CMakeDep            = "pkg.dep.cmake"
	DepGraph            = "pkg.graph"
	CMakeVendorPath     = "${VENDOR_PATH}"
)
View Source
const RootPKG = "root"

Variables

This section is empty.

Functions

func CheckDir

func CheckDir(path string) error

check if the dir exits,if not create it.

func CheckDirLists

func CheckDirLists(dirs ...string) error

check a list of dirs

func DepTreeRecover

func DepTreeRecover(metas *map[string]PackageMeta, filename string) error

recover the dependency tree from a yaml file. the result is saved in variable metas.

func ExpandEnv added in v0.4.0

func ExpandEnv(origin string, envs *PackageEnvs) (string, error)

replace origin string with args values.

func GetCMakeVendorPkgPath

func GetCMakeVendorPkgPath(packageName string) (path string)

return ${VENDOR_PATH}/pkg/@packageName

func GetCachePath

func GetCachePath(base, packageName string) (path string)

return @base/vendor/cache

func GetCachedPackageSrcPath added in v0.3.3

func GetCachedPackageSrcPath(packageName string, version string) (string, error)

func GetDepGraphPath

func GetDepGraphPath(base string) string

func GetHomeSrcPath

func GetHomeSrcPath() (string, error)

return $HOME/.pkg/registry/default-pkg/src

func GetIncludePath

func GetIncludePath(base string) (path string)

return @base/vendor/include

func GetPackageDepsPath added in v0.4.0

func GetPackageDepsPath(base string, packageName string) (path string)

return @base/vendor/deps/@packageName

func GetPackagePkgPath

func GetPackagePkgPath(base string, packageName string) (path string)

return @base/vendor/pkg/@packageName

func GetPkgBuildPath

func GetPkgBuildPath(base string) string

func GetPkgIncludePath

func GetPkgIncludePath(base string, packageName string) (path string)

return @base/vendor/pkg/@packageName/include

func GetPkgPath

func GetPkgPath(base string) (path string)

return @base/vendor/pkg

func GetPkgSrcPath added in v0.3.3

func GetPkgSrcPath(base string) string

func GetPkgSumPath

func GetPkgSumPath(base string) string

func GetPkgUserHomeFile

func GetPkgUserHomeFile(suffixPath string) (string, error)

func GetVendorPath

func GetVendorPath(base string) string

func LoadListFromGraph

func LoadListFromGraph(graphPath, packageName string) ([]string, error)

func RelativePath

func RelativePath(base, target string) string

// change path to relative path, replace PKG_DIR with relative path.

func Unzip

func Unzip(src string, dest string) error

FROM https://golangcode.com/unzip-files-in-go/ Unzip will decompress a zip archive, moving all files and folders within the zip file (parameter 1) to an output directory (parameter 2).

func UrlJoin

func UrlJoin(base, ele string) string

Types

type DependencyTree

type DependencyTree struct {
	Dependencies []*DependencyTree
	Context      PackageMeta
	DlStatus     int
	IsPkgPackage bool
}

func (*DependencyTree) Dump

func (depTree *DependencyTree) Dump(filename string) error

marshal dependency tree content to a yaml file.

func (*DependencyTree) ListDeps

func (depTree *DependencyTree) ListDeps(skipRoot bool) ([]*DependencyTree, error)

list all dependencies packages of a package by TraversalDeep.

func (*DependencyTree) ListDepsName added in v0.3.3

func (depTree *DependencyTree) ListDepsName() ([]string, error)

list all dependencies packages name of a package by TraversalDeep.

func (*DependencyTree) MarshalGraph

func (depTree *DependencyTree) MarshalGraph(writer io.Writer) error

dump direct and indirect dependencies packages of all packages.

func (*DependencyTree) Traversal

func (depTree *DependencyTree) Traversal(callback func(*DependencyTree) bool)

traversal all tree node with pre-order. if the return value of callback function is false, it will skip its children nodes.

func (*DependencyTree) TraversalDeep

func (depTree *DependencyTree) TraversalDeep(callback func(*DependencyTree) error) error

traversal all tree node(including the root node) by deep first strategy. if return value of callback is false, then the traversal will break.

func (*DependencyTree) TraversalPreOrder

func (depTree *DependencyTree) TraversalPreOrder(callback func(*DependencyTree) bool) bool

traversal all tree node with pre-order. if the return value of callback function is false, then the traversal will break.

type InsTriple added in v0.3.3

type InsTriple struct {
	First  string
	Second string
	Third  string
}

install instruction

func ParseIns added in v0.3.3

func ParseIns(insStr string) (ins InsTriple, err error)

todo parse multiple space, and `\"`

type PackageEnvs added in v0.4.0

type PackageEnvs struct {
	PkgRoot             string `pkg:"PKG_ROOT"`              // the path running pkg
	VendorPath          string `pkg:"VENDOR_PATH"`           // vendor
	PkgInCPath          string `pkg:"INCLUDE"`               // vendor/include
	PackageCacheDir     string `pkg:"CACHE"`                 // vendor/cache/@pkg
	PackagePkgDir       string `pkg:"PKG_DIR"`               // vendor/pkg/@pkg
	PackagePkgIncDir    string `pkg:"PKG_INC"`               // vendor/pkg/@pkg/include
	PackageSrcDir       string `pkg:"SRC_DIR"`               // vendor/src/@pkg
	PackageFindPath     string `pkg:"PKG_FIND_PATH"`         // vendor/deps/@pkg or vendor/pkg/@pkg (decided by env)
	CMakePackageFindDir string `pkg:"CMAKE_VENDOR_PATH_PKG"` // vendor/pkg/@pkg
}

paths env variable used in instruction

func NewPackageEnvs added in v0.4.0

func NewPackageEnvs(pkgRoot, packageName, packageSrc string) *PackageEnvs

pkgRoot: the root directory of project packageName: package name/path packageSrcPath: path of package source

type PackageMeta

type PackageMeta struct {
	PackageName string   `yaml:"pkg"`    // package name (usually it is a path)
	TargetName  string   `yaml:"target"` // cmake package name
	Features    []string `yaml:"features"`
	//	SrcPath      string   `yaml:"-"`
	Version      string   `yaml:"version"`
	Builder      []string `yaml:"builder"`        // outer builder (lib used by others, specified by others pkg)
	SelfBuild    []string `yaml:"self_build"`     // inner builder (shows how this package is built, specified in package's pkg.yaml file)
	CMakeLib     string   `yaml:"cmake_lib"`      // outer cmake script to add this lib.
	SelfCMakeLib string   `yaml:"self_cmake_lib"` // inner cmake script to add this lib.
}

package metadata used in sum file.

func (*PackageMeta) HomeCacheSrcPath added in v0.3.3

func (ctx *PackageMeta) HomeCacheSrcPath() string

return directory path of cached source in user home

func (*PackageMeta) SetPackageName added in v0.3.3

func (ctx *PackageMeta) SetPackageName(key string) error

func (*PackageMeta) VendorSrcPath added in v0.3.3

func (ctx *PackageMeta) VendorSrcPath(base string) string

return directory path of source in vendor

type V1FilesPackage added in v0.3.3

type V1FilesPackage struct {
	V1Package `yaml:",inline"`
	Files     map[string]string `yaml:"files"`
}

type V1GitPackage added in v0.3.3

type V1GitPackage struct {
	V1Package `yaml:",inline"`
	Tag       string `yaml:"tag"`    // git tag
	Branch    string `yaml:"branch"` // git branch
	Hash      string `yaml:"hash"`   // git commit hash
}

type V1Package added in v0.3.3

type V1Package struct {
	Path             string   `yaml:"path"`
	Override         bool     `yaml:"override"` // override package self build.
	Build            []string `yaml:"build"`
	CMakeLib         string   `yaml:"cmake_lib"`
	CMakeLibOverride bool     `yaml:"cmake_lib_override"`
}

type V1Packages added in v0.3.3

type V1Packages struct {
	GitPackages   map[string]V1GitPackage   `yaml:"git"`
	FilesPackages map[string]V1FilesPackage `yaml:"files"`
}

for pkg file version 1.

func (*V1Packages) MigrateToV2 added in v0.3.3

func (v1 *V1Packages) MigrateToV2(d *YamlDependencies) error

type YamlArchivePackage added in v0.3.3

type YamlArchivePackage struct {
	YamlPackage `yaml:",inline"`
}

type YamlDependencies added in v0.3.3

type YamlDependencies struct {
	GitPackages     map[string]YamlGitPackage     `yaml:"packages"`
	FilesPackages   map[string]YamlFilesPackage   `yaml:"files"`
	ArchivePackages map[string]YamlArchivePackage `yaml:"archives"`
}

type YamlFilesPackage added in v0.3.3

type YamlFilesPackage struct {
	YamlPackage `yaml:",inline"`
	Files       map[string]string `yaml:"files"`
}

type YamlGitPackage added in v0.3.3

type YamlGitPackage struct {
	YamlPackage `yaml:",inline"`
	Version     string   `yaml:"version"`
	Target      string   `yaml:"target"`
	Features    []string `yaml:"features"`
}

type YamlPackage added in v0.3.3

type YamlPackage V1Package

type YamlPkg added in v0.3.3

type YamlPkg struct {
	Version    int                 `yaml:"version"`
	Args       map[string]string   `yaml:"args"`
	GitReplace map[string]string   `yaml:"git-replace"`
	PkgName    string              `yaml:"pkg"`
	Packages   V1Packages          `yaml:"packages"` // for pkg file version 1
	Deps       YamlDependencies    `yaml:"dependencies"`
	Build      map[string][]string `yaml:"build"`
	CMakeLib   string              `yaml:"cmake_lib"`
}

for pkg yaml file parsing

func (*YamlPkg) FindBuilder added in v0.4.0

func (yamlPkg *YamlPkg) FindBuilder() []string

find builder by os. If builder[os] is not found, return a fallback builder.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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