pkg

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: Apache-2.0 Imports: 15 Imported by: 17

Documentation

Overview

Copyright 2022 The KCL Authors. All rights reserved.

Copyright 2022 The KCL Authors. All rights reserved.

Because the same dependency package will be serialized into toml files in different formats in kcl.mod and kcl.mod.lock, the toml library 'github.com/BurntSushi/toml' is encapsulated in this file, and two different format are provided according to different files.

In kcl.mod, the dependency toml looks like:

<dependency_name> = { git = "<git_url>", tag = "<git_tag>" }

In kcl.mod.lock, the dependency toml looks like:

[dependencies.<dependency_name>] name = "<dependency_name>" full_name = "<dependency_fullname>" version = "<dependency_version>" sum = "yNADGqn3jclWtfpwvWMHBsgkAKzOaMWg/VYxfcOJs64=" url = "https://github.com/xxxx" tag = "<dependency_tag>"

Index

Constants

View Source
const (
	MOD_FILE      = "kcl.mod"
	MOD_LOCK_FILE = "kcl.mod.lock"
)
View Source
const DEPS_FLAG = "dependencies"
View Source
const DEPS_PATTERN = "[dependencies]"
View Source
const DEP_PATTERN = "%s = %s"
View Source
const DESCRIPTION_FLAG = "description"
View Source
const EDITION_FLAG = "edition"
View Source
const GIT_COMMIT_FLAG = "commit"
View Source
const GIT_COMMIT_PATTERN = "commit = \"%s\""
View Source
const GIT_TAG_FLAG = "tag"
View Source
const GIT_TAG_PATTERN = "tag = \"%s\""
View Source
const GIT_URL_FLAG = "git"
View Source
const GIT_URL_PATTERN = "git = \"%s\""
View Source
const LOCAL_PATH_FLAG = "path"
View Source
const LOCAL_PATH_PATTERN = "path = %s"
View Source
const LOCK_FILE_NAME = "kcl.mod.lock"
View Source
const NAME_FLAG = "name"
View Source
const NEWLINE = "\n"
View Source
const PACKAGE_FLAG = "package"
View Source
const PACKAGE_PATTERN = "[package]"
View Source
const PKG_NAME_PATTERN = "%s_%s"
View Source
const PROFILES_FLAG = "profile"
View Source
const PROFILE_PATTERN = "[profile]"
View Source
const SEPARATOR = ", "
View Source
const SOURCE_PATTERN = "{ %s }"
View Source
const TAR_SUFFIX = ".tar"
View Source
const VERSION_FLAG = "version"

Variables

This section is empty.

Functions

func ModFileExists added in v0.3.3

func ModFileExists(path string) (bool, error)

ModFileExists returns whether a 'kcl.mod' file exists in the path.

func ModLockFileExists added in v0.3.3

func ModLockFileExists(path string) (bool, error)

ModLockFileExists returns whether a 'kcl.mod.lock' file exists in the path.

func ParseRepoFullNameFromGitSource added in v0.3.3

func ParseRepoFullNameFromGitSource(gitSrc Git) (string, error)

ParseRepoFullNameFromGitSource will extract the kcl package name from the git url.

func ParseRepoNameFromGitSource added in v0.3.3

func ParseRepoNameFromGitSource(gitSrc Git) string

ParseRepoNameFromGitSource will extract the kcl package name from the git url.

Types

type Dependencies added in v0.3.3

type Dependencies struct {
	Deps map[string]Dependency `json:"packages" toml:"dependencies,omitempty"`
}

'Dependencies' is dependencies section of 'kcl.mod'.

func LoadLockDeps added in v0.3.3

func LoadLockDeps(homePath string) (*Dependencies, error)

LoadLockDeps will load all dependencies from 'kcl.mod.lock'.

func (*Dependencies) MarshalLockTOML added in v0.3.3

func (dep *Dependencies) MarshalLockTOML() (string, error)

func (*Dependencies) MarshalTOML added in v0.3.3

func (dep *Dependencies) MarshalTOML() string

func (*Dependencies) ToDepMetadata added in v0.4.5

func (deps *Dependencies) ToDepMetadata() (*Dependencies, error)

ToDepMetadata will transform the dependencies into metadata. And check whether the dependency name conflicts.

func (*Dependencies) UnmarshalLockTOML added in v0.3.3

func (dep *Dependencies) UnmarshalLockTOML(data string) error

func (*Dependencies) UnmarshalModTOML added in v0.3.3

func (deps *Dependencies) UnmarshalModTOML(data interface{}) error

type Dependency added in v0.3.3

type Dependency struct {
	Name     string `json:"name" toml:"name,omitempty"`
	FullName string `json:"-" toml:"full_name,omitempty"`
	Version  string `json:"-" toml:"version,omitempty"`
	Sum      string `json:"-" toml:"sum,omitempty"`
	// The actual local path of the package.
	// In vendor mode is "current_kcl_package/vendor"
	// In non-vendor mode is "$KCL_PKG_PATH"
	LocalFullPath string `json:"manifest_path" toml:"-"`
	Source        `json:"-"`
}

func ParseOpt added in v0.3.3

func ParseOpt(opt *opt.RegistryOptions) (*Dependency, error)

Parse out some information for a Dependency from registry url.

func (*Dependency) FillDepInfo added in v0.3.3

func (dep *Dependency) FillDepInfo() error

FillDepInfo will fill registry information for a dependency.

func (*Dependency) GenDepFullName added in v0.3.3

func (dep *Dependency) GenDepFullName() string

GenDepFullName will generate the full name of a dependency by its name and version based on the '<package_name>_<package_tag>' format.

func (*Dependency) GetAliasName added in v0.4.5

func (d *Dependency) GetAliasName() string

SetName will set the name and alias name of a dependency.

func (*Dependency) GetLocalFullPath added in v0.3.4

func (dep *Dependency) GetLocalFullPath(rootpath string) string

GetLocalFullPath will get the local path of a dependency.

func (*Dependency) IsFromLocal added in v0.3.7

func (dep *Dependency) IsFromLocal() bool

func (*Dependency) MarshalTOML added in v0.3.3

func (dep *Dependency) MarshalTOML() string

func (*Dependency) UnmarshalModTOML added in v0.3.3

func (dep *Dependency) UnmarshalModTOML(data interface{}) error

func (Dependency) WithTheSameVersion added in v0.4.3

func (d Dependency) WithTheSameVersion(other Dependency) bool

WithTheSameVersion will check whether two dependencies have the same version.

type Git added in v0.3.3

type Git struct {
	Url    string `toml:"url,omitempty"`
	Branch string `toml:"branch,omitempty"`
	Commit string `toml:"commit,omitempty"`
	Tag    string `toml:"git_tag,omitempty"`
}

Git is the package source from git registry.

func (*Git) GetValidGitReference added in v0.6.0

func (git *Git) GetValidGitReference() (string, error)

GetValidGitReference will get the valid git reference from git source. Only one of branch, tag or commit is allowed.

func (*Git) MarshalTOML added in v0.3.3

func (git *Git) MarshalTOML() string

func (*Git) UnmarshalModTOML added in v0.3.3

func (git *Git) UnmarshalModTOML(data interface{}) error

type KclPkg

type KclPkg struct {
	ModFile  ModFile
	HomePath string
	// The dependencies in the current kcl package are the dependencies of kcl.mod.lock,
	// not the dependencies in kcl.mod.
	Dependencies
	// The flag 'NoSumCheck' is true if the checksum of the current kcl package is not checked.
	NoSumCheck bool
}

func LoadKclPkg

func LoadKclPkg(pkgPath string) (*KclPkg, error)

func LoadKclPkgFromTar

func LoadKclPkgFromTar(pkgTarPath string) (*KclPkg, error)

func NewKclPkg

func NewKclPkg(opts *opt.InitOptions) KclPkg

func (*KclPkg) CreateDefauleMain added in v0.3.7

func (kclPkg *KclPkg) CreateDefauleMain() error

CreateDefauleMain will create a default main.k file in the current kcl package.

func (*KclPkg) DefaultTarPath

func (kclPkg *KclPkg) DefaultTarPath() string

DefaultTarPath will return "<kcl_package_path>/<package_name>-<package_version>.tar"

func (*KclPkg) GenCheckSum added in v0.4.0

func (KclPkg *KclPkg) GenCheckSum() (string, error)

GenCheckSum generates the checksum of the current kcl package.

func (*KclPkg) GetDepsMetadata added in v0.4.5

func (p *KclPkg) GetDepsMetadata() (*Dependencies, error)

func (*KclPkg) GetEntryKclFilesFromModFile

func (kclPkg *KclPkg) GetEntryKclFilesFromModFile() []string

GetEntryKclFilesFromModFile will return the entry kcl files from kcl.mod.

func (*KclPkg) GetKclOpts

func (kclPkg *KclPkg) GetKclOpts() *kcl.Option

GetKclOpts will return the kcl options from kcl.mod.

func (*KclPkg) GetLockFilePath

func (kclPkg *KclPkg) GetLockFilePath() string

GetLockFilePath returns the abs path of kcl.mod.lock.

func (*KclPkg) GetPkgDescription added in v0.3.7

func (KclPkg *KclPkg) GetPkgDescription() string

GetPkgDescription returns the description of package.

func (*KclPkg) GetPkgEdition added in v0.3.4

func (kclPkg *KclPkg) GetPkgEdition() string

GetPkgEdition returns compile edition of package.

func (*KclPkg) GetPkgFullName

func (kclPkg *KclPkg) GetPkgFullName() string

GetPkgFullName returns the full name of package. The full name is "<pkg_name>-<pkg_version>", <pkg_name> is the name of package. <pkg_version> is the version of package

func (*KclPkg) GetPkgName

func (kclPkg *KclPkg) GetPkgName() string

GetPkgName returns name of package.

func (*KclPkg) GetPkgProfile added in v0.3.4

func (kclPkg *KclPkg) GetPkgProfile() *Profile

GetPkgProfile returns the profile of package.

func (*KclPkg) GetPkgTag

func (kclPkg *KclPkg) GetPkgTag() string

GetPkgTag returns version of package.

func (*KclPkg) GetPkgTarName

func (kclPkg *KclPkg) GetPkgTarName() string

GetPkgTarName returns the kcl package tar name "<package_name>-v<package_version>.tar"

func (*KclPkg) GetPkgVersion added in v0.3.7

func (KclPkg *KclPkg) GetPkgVersion() string

GetPkgVersion returns the version of package.

func (*KclPkg) HasProfile added in v0.4.3

func (kclPkg *KclPkg) HasProfile() bool

HasProfile will return true if the current kcl package has the profile.

func (*KclPkg) IsVendorMode

func (kclPkg *KclPkg) IsVendorMode() bool

func (*KclPkg) LocalVendorPath

func (kclPkg *KclPkg) LocalVendorPath() string

Return the full vendor path.

func (*KclPkg) LockDepsVersion

func (kclPkg *KclPkg) LockDepsVersion() error

LockDepsVersion locks the dependencies of the current kcl package into kcl.mod.lock.

func (*KclPkg) SetVendorMode

func (kclPkg *KclPkg) SetVendorMode(vendorMode bool)

func (*KclPkg) UpdateModAndLockFile

func (kclPkg *KclPkg) UpdateModAndLockFile() error

updateModAndLockFile will update kcl.mod and kcl.mod.lock

func (*KclPkg) ValidateKpmHome

func (kclPkg *KclPkg) ValidateKpmHome(kpmHome string) *reporter.KpmEvent

Verify that the environment variable KPM HOME is set correctly

type Local added in v0.3.3

type Local struct {
	Path string `toml:"path,omitempty"`
}

func (*Local) MarshalTOML added in v0.3.3

func (local *Local) MarshalTOML() string

func (*Local) UnmarshalModTOML added in v0.3.3

func (local *Local) UnmarshalModTOML(data interface{}) error

type ModFile added in v0.3.3

type ModFile struct {
	HomePath string  `toml:"-"`
	Pkg      Package `toml:"package,omitempty"`
	// Whether the current package uses the vendor mode
	// In the vendor mode, kpm will look for the package in the vendor subdirectory
	// in the current package directory.
	VendorMode bool     `toml:"-"`
	Profiles   *Profile `toml:"profile"`
	Dependencies
}

'ModFile' is kcl package file 'kcl.mod'.

func LoadModFile added in v0.3.3

func LoadModFile(homePath string) (*ModFile, error)

LoadModFile load the contents of the 'kcl.mod' file in the path.

func NewModFile added in v0.3.3

func NewModFile(opts *opt.InitOptions) *ModFile

func (*ModFile) FillDependenciesInfo added in v0.3.3

func (modFile *ModFile) FillDependenciesInfo() error

FillDependenciesInfo will fill registry information for all dependencies in a kcl.mod.

func (*ModFile) GetEntries added in v0.4.3

func (modFile *ModFile) GetEntries() []string

GetEntries will get the entry kcl files from kcl.mod.

func (*ModFile) GetModFilePath added in v0.3.3

func (mfile *ModFile) GetModFilePath() string

Returns the path to the kcl.mod file

func (*ModFile) GetModLockFilePath added in v0.3.3

func (mfile *ModFile) GetModLockFilePath() string

Returns the path to the kcl.mod.lock file

func (*ModFile) LoadModFile added in v0.4.0

func (mod *ModFile) LoadModFile(filepath string) error

Load the kcl.mod file.

func (*ModFile) MarshalTOML added in v0.3.3

func (mod *ModFile) MarshalTOML() string

func (*ModFile) StoreModFile added in v0.3.3

func (mfile *ModFile) StoreModFile() error

Write the contents of 'ModFile' to 'kcl.mod' file

func (*ModFile) UnmarshalTOML added in v0.3.3

func (mod *ModFile) UnmarshalTOML(data interface{}) error

type Oci added in v0.3.3

type Oci struct {
	Reg  string `toml:"reg,omitempty"`
	Repo string `toml:"repo,omitempty"`
	Tag  string `toml:"oci_tag,omitempty"`
}

func (*Oci) MarshalTOML added in v0.3.3

func (oci *Oci) MarshalTOML() string

func (*Oci) UnmarshalModTOML added in v0.3.3

func (oci *Oci) UnmarshalModTOML(data interface{}) error

type Package added in v0.3.3

type Package struct {
	Name        string `toml:"name,omitempty"`        // kcl package name
	Edition     string `toml:"edition,omitempty"`     // kcl compiler version
	Version     string `toml:"version,omitempty"`     // kcl package version
	Description string `toml:"description,omitempty"` // kcl package description
}

'Package' is the kcl package section of 'kcl.mod'.

func (*Package) MarshalTOML added in v0.3.3

func (pkg *Package) MarshalTOML() string

func (*Package) UnmarshalTOML added in v0.3.3

func (pkg *Package) UnmarshalTOML(data interface{}) error

type Profile added in v0.3.3

type Profile struct {
	Entries     *[]string `toml:"entries"`
	DisableNone *bool     `toml:"disable_none"`
	SortKeys    *bool     `toml:"sort_keys"`
	Selectors   *[]string `toml:"selectors"`
	Overrides   *[]string `toml:"overrides"`
	Options     *[]string `toml:"arguments"`
}

Profile is the profile section of 'kcl.mod'. It is used to specify the compilation options of the current package.

func NewProfile added in v0.3.3

func NewProfile() Profile

NewProfile will create a new profile.

func (*Profile) GetEntries added in v0.4.3

func (profile *Profile) GetEntries() []string

GetEntries will get the entry kcl files from profile.

func (*Profile) IntoKclOptions added in v0.3.3

func (profile *Profile) IntoKclOptions() *kcl.Option

IntoKclOptions will transform the profile into kcl options.

func (*Profile) MarshalTOML added in v0.3.3

func (p *Profile) MarshalTOML() string

type Source added in v0.3.3

type Source struct {
	*Git
	*Oci
	*Local
}

Source is the package source from registry.

func (*Source) MarshalTOML added in v0.3.3

func (source *Source) MarshalTOML() string

func (*Source) UnmarshalModTOML added in v0.3.3

func (source *Source) UnmarshalModTOML(data interface{}) error

Jump to

Keyboard shortcuts

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