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
- Variables
- func GenSource(sourceType string, uri string, tagName string) (downloader.Source, error)
- func ModFileExists(path string) (bool, error)
- func ModLockFileExists(path string) (bool, error)
- func ParseRepoFullNameFromGitSource(gitSrc downloader.Git) (string, error)
- func ParseRepoNameFromGitSource(gitSrc downloader.Git) string
- type Dependencies
- func (deps *Dependencies) CheckForLocalDeps() bool
- func (dep *Dependencies) MarshalLockTOML() (string, error)
- func (dep *Dependencies) MarshalTOML() string
- func (deps *Dependencies) ToDepMetadata() (*DependenciesUI, error)
- func (dep *Dependencies) UnmarshalLockTOML(data string) error
- func (deps *Dependencies) UnmarshalModTOML(data interface{}) error
- type DependenciesUI
- type Dependency
- func (d Dependency) Equals(other Dependency) bool
- func (dep *Dependency) FillDepInfo(homepath string) error
- func (d *Dependency) FromKclPkg(pkg *KclPkg)
- func (dep *Dependency) GenDepFullName() string
- func (d *Dependency) GenPathSuffix() string
- func (d *Dependency) GetAliasName() string
- func (dep *Dependency) GetDownloadPath() string
- func (dep *Dependency) GetLocalFullPath(rootpath string) string
- func (dep *Dependency) GetSourceType() string
- func (dep *Dependency) IsFromLocal() bool
- func (dep *Dependency) MarshalTOML() string
- func (dep *Dependency) UnmarshalModTOML(data interface{}) error
- func (d *Dependency) VersionLessThan(other *Dependency) (bool, error)
- type KclPkg
- func (p *KclPkg) BackupDepUI(name string, dep *Dependency)
- func (kclPkg *KclPkg) CreateDefaultMain() error
- func (kclPkg *KclPkg) DefaultTarPath() string
- func (KclPkg *KclPkg) GenCheckSum() (string, error)
- func (kclPkg *KclPkg) GenOciManifestFromPkg() (map[string]string, error)
- func (p *KclPkg) GetDepsMetadata() (*DependenciesUI, error)
- func (kclPkg *KclPkg) GetEntryKclFilesFromModFile() []string
- func (kclPkg *KclPkg) GetKclOpts() *kcl.Option
- func (kclPkg *KclPkg) GetLockFilePath() string
- func (KclPkg *KclPkg) GetPkgDescription() string
- func (kclPkg *KclPkg) GetPkgEdition() string
- func (KclPkg *KclPkg) GetPkgExclude() []string
- func (kclPkg *KclPkg) GetPkgFullName() string
- func (KclPkg *KclPkg) GetPkgInclude() []string
- func (kclPkg *KclPkg) GetPkgName() string
- func (kclPkg *KclPkg) GetPkgProfile() *Profile
- func (kclPkg *KclPkg) GetPkgTag() string
- func (kclPkg *KclPkg) GetPkgTarName() string
- func (KclPkg *KclPkg) GetPkgVersion() string
- func (kclPkg *KclPkg) HasProfile() bool
- func (kclPkg *KclPkg) IsVendorMode() bool
- func (kclPkg *KclPkg) LocalVendorPath() string
- func (kclPkg *KclPkg) LockDepsVersion() error
- func (kclPkg *KclPkg) SetVendorMode(vendorMode bool)
- func (kclPkg *KclPkg) UpdateModAndLockFile() error
- func (kclPkg *KclPkg) ValidateKpmHome(kpmHome string) *reporter.KpmEvent
- type LoadOption
- type LoadOptions
- type ModFile
- func (modFile *ModFile) FillDependenciesInfo() error
- func (modFile *ModFile) GetEntries() []string
- func (mfile *ModFile) GetModFilePath() string
- func (mfile *ModFile) GetModLockFilePath() string
- func (mod *ModFile) LoadModFile(name string) error
- func (mod *ModFile) MarshalTOML() string
- func (mfile *ModFile) StoreModFile() error
- func (mod *ModFile) UnmarshalTOML(data interface{}) error
- type Package
- type Profile
Constants ¶
const ( MOD_FILE = "kcl.mod" MOD_LOCK_FILE = "kcl.mod.lock" GIT = "git" OCI = "oci" LOCAL = "local" )
const ( PACKAGE_FLAG = "package" DEPS_FLAG = "dependencies" PROFILES_FLAG = "profile" )
const ( NAME_FLAG = "name" EDITION_FLAG = "edition" VERSION_FLAG = "version" DESCRIPTION_FLAG = "description" INCLUDE_FLAG = "include" EXCLUDE_FLAG = "exclude" )
const DEPS_PATTERN = "[dependencies]"
const DEP_PATTERN = "%s = %s"
const LOCK_FILE_NAME = "kcl.mod.lock"
const NEWLINE = "\n"
const PACKAGE_PATTERN = "[package]"
const PKG_NAME_PATTERN = "%s_%s"
const PROFILE_PATTERN = "[profile]"
const TAR_SUFFIX = ".tar"
Variables ¶
var TestPkgDependency = Dependency{
Name: "kcl",
FullName: "kcl",
Version: "0.0.0",
Sum: "Sum",
}
Functions ¶
func ModFileExists ¶ added in v0.3.3
ModFileExists returns whether a 'kcl.mod' file exists in the path.
func ModLockFileExists ¶ added in v0.3.3
ModLockFileExists returns whether a 'kcl.mod.lock' file exists in the path.
func ParseRepoFullNameFromGitSource ¶ added in v0.3.3
func ParseRepoFullNameFromGitSource(gitSrc downloader.Git) (string, error)
ParseRepoFullNameFromGitSource will extract the kcl package name from the git url. If the package flag is passed then it will be used as the package name.
func ParseRepoNameFromGitSource ¶ added in v0.3.3
func ParseRepoNameFromGitSource(gitSrc downloader.Git) string
ParseRepoNameFromGitSource will extract the kcl package name from the git url. If the package flag is passed then it will be used
Types ¶
type Dependencies ¶ added in v0.3.3
type Dependencies struct {
Deps *orderedmap.OrderedMap[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) CheckForLocalDeps ¶ added in v0.8.7
func (deps *Dependencies) CheckForLocalDeps() bool
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() (*DependenciesUI, 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 DependenciesUI ¶ added in v0.9.0
type DependenciesUI struct {
Deps map[string]Dependency `json:"packages" toml:"dependencies,omitempty"`
}
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:"-"` downloader.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) Equals ¶ added in v0.8.7
func (d Dependency) Equals(other Dependency) bool
func (*Dependency) FillDepInfo ¶ added in v0.3.3
func (dep *Dependency) FillDepInfo(homepath string) error
FillDepInfo will fill registry information for a dependency.
func (*Dependency) FromKclPkg ¶ added in v0.8.3
func (d *Dependency) FromKclPkg(pkg *KclPkg)
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) GenPathSuffix ¶ added in v0.9.3
func (d *Dependency) GenPathSuffix() string
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) GetDownloadPath ¶ added in v0.8.7
func (dep *Dependency) GetDownloadPath() string
GetDownloadPath will get the download path 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) GetSourceType ¶ added in v0.8.7
func (dep *Dependency) GetSourceType() string
GetSourceType will get the source type 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) VersionLessThan ¶ added in v0.10.0
func (d *Dependency) VersionLessThan(other *Dependency) (bool, error)
VersionGreaterThan will compare the version of a dependency with another dependency.
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 // contains filtered or unexported fields }
func FindFirstKclPkgFrom ¶ added in v0.8.3
FindFirstKclPkgFrom will find the first kcl package from the 'path' The default oci registry in '$KCL_PKG_PATH/.kpm/config/kpm.json' will be used.
func LoadKclPkg ¶
LoadKclPkg will load a package from the 'pkgPath' The default oci registry in '$KCL_PKG_PATH/.kpm/config/kpm.json' will be used.
func LoadKclPkgFromTar ¶
LoadKclPkgFromTar loads a package *.tar file from the 'pkgTarPath' The default oci registry in '$KCL_PKG_PATH/.kpm/config/kpm.json' will be used.
func LoadKclPkgWithOpts ¶ added in v0.11.0
func LoadKclPkgWithOpts(options ...LoadOption) (*KclPkg, error)
LoadKclPkgWithOpts loads a module from the file system with options. The options include the module path and the settings with default oci registry.
func NewKclPkg ¶
func NewKclPkg(opts *opt.InitOptions) KclPkg
func (*KclPkg) BackupDepUI ¶ added in v0.11.0
func (p *KclPkg) BackupDepUI(name string, dep *Dependency)
func (*KclPkg) CreateDefaultMain ¶ added in v0.10.0
CreateDefaultMain will create a default main.k file in the current kcl package.
func (*KclPkg) DefaultTarPath ¶
DefaultTarPath will return "<kcl_package_path>/<package_name>-<package_version>.tar"
func (*KclPkg) GenCheckSum ¶ added in v0.4.0
GenCheckSum generates the checksum of the current kcl package.
func (*KclPkg) GenOciManifestFromPkg ¶ added in v0.9.0
GenOciManifestFromPkg will generate the oci manifest from the kcl package.
func (*KclPkg) GetDepsMetadata ¶ added in v0.4.5
func (p *KclPkg) GetDepsMetadata() (*DependenciesUI, error)
func (*KclPkg) GetEntryKclFilesFromModFile ¶
GetEntryKclFilesFromModFile will return the entry kcl files from kcl.mod.
func (*KclPkg) GetKclOpts ¶
GetKclOpts will return the kcl options from kcl.mod.
func (*KclPkg) GetLockFilePath ¶
GetLockFilePath returns the abs path of kcl.mod.lock.
func (*KclPkg) GetPkgDescription ¶ added in v0.3.7
GetPkgDescription returns the description of package.
func (*KclPkg) GetPkgEdition ¶ added in v0.3.4
GetPkgEdition returns compile edition of package.
func (*KclPkg) GetPkgExclude ¶ added in v0.8.7
GetPkgExclude returns the exclude of package.
func (*KclPkg) GetPkgFullName ¶
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) GetPkgInclude ¶ added in v0.8.7
GetPkgInclude returns the include of package.
func (*KclPkg) GetPkgName ¶
GetPkgName returns name of package.
func (*KclPkg) GetPkgProfile ¶ added in v0.3.4
GetPkgProfile returns the profile of package.
func (*KclPkg) GetPkgTarName ¶
GetPkgTarName returns the kcl package tar name "<package_name>-v<package_version>.tar"
func (*KclPkg) GetPkgVersion ¶ added in v0.3.7
GetPkgVersion returns the version of package.
func (*KclPkg) HasProfile ¶ added in v0.4.3
HasProfile will return true if the current kcl package has the profile.
func (*KclPkg) IsVendorMode ¶
func (*KclPkg) LocalVendorPath ¶
Return the full vendor path.
func (*KclPkg) LockDepsVersion ¶
LockDepsVersion locks the dependencies of the current kcl package into kcl.mod.lock.
func (*KclPkg) SetVendorMode ¶
func (*KclPkg) UpdateModAndLockFile ¶
updateModAndLockFile will update kcl.mod and kcl.mod.lock
type LoadOption ¶ added in v0.11.0
type LoadOption func(*LoadOptions)
func WithPath ¶ added in v0.11.0
func WithPath(path string) LoadOption
WithPath sets the module path.
func WithSettings ¶ added in v0.11.0
func WithSettings(settings *settings.Settings) LoadOption
WithSettings sets the settings with default oci registry.
type LoadOptions ¶ added in v0.11.0
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 LoadAndFillModFileWithOpts ¶ added in v0.11.0
func LoadAndFillModFileWithOpts(options ...LoadOption) (*ModFile, error)
LoadAndFillModFileWithOpts loads a mod file from the file system with options. It will load the mod file, convert the local path to the absolute path, and fill the default oci registry.
func LoadModFile ¶ added in v0.3.3
LoadModFile load the contents of the 'kcl.mod' file in the path. Deprecated: Use 'LoadAndFillModFileWithOpts' instead.
func NewModFile ¶ added in v0.3.3
func NewModFile(opts *opt.InitOptions) *ModFile
func (*ModFile) FillDependenciesInfo ¶ added in v0.3.3
FillDependenciesInfo will fill registry information for all dependencies in a kcl.mod.
func (*ModFile) GetEntries ¶ added in v0.4.3
GetEntries will get the entry kcl files from kcl.mod.
func (*ModFile) GetModFilePath ¶ added in v0.3.3
Returns the path to the kcl.mod file
func (*ModFile) GetModLockFilePath ¶ added in v0.3.3
Returns the path to the kcl.mod.lock file
func (*ModFile) LoadModFile ¶ added in v0.4.0
Load the kcl.mod file, and make sure the `ModFile` is the same as the content in the kcl.mod file. For the dependency like "helloworld=0.1.0", `ModFile` will lack the source information. The `ModFile` will be filled with the source information loaded by `LoadAndFillModFileWithOpts`
func (*ModFile) MarshalTOML ¶ added in v0.3.3
func (*ModFile) StoreModFile ¶ added in v0.3.3
Write the contents of 'ModFile' to 'kcl.mod' file
func (*ModFile) UnmarshalTOML ¶ added in v0.3.3
type Package ¶ added in v0.3.3
type Package struct { // The name of the package. Name string `toml:"name,omitempty"` // The kcl compiler version Edition string `toml:"edition,omitempty"` // The version of the package. Version string `toml:"version,omitempty"` // Description denotes the description of the package. Description string `toml:"description,omitempty"` // kcl package description // Exclude denote the files to include when publishing. Include []string `toml:"include,omitempty"` // Exclude denote the files to exclude when publishing. Exclude []string `toml:"exclude,omitempty"` }
'Package' is the kcl package section of 'kcl.mod'.
func (*Package) MarshalTOML ¶ added in v0.3.3
func (*Package) UnmarshalTOML ¶ added in v0.3.3
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 (*Profile) GetEntries ¶ added in v0.4.3
GetEntries will get the entry kcl files from profile.
func (*Profile) IntoKclOptions ¶ added in v0.3.3
IntoKclOptions will transform the profile into kcl options.