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
- func ModFileExists(path string) (bool, error)
- func ModLockFileExists(path string) (bool, error)
- func ParseRepoFullNameFromGitSource(gitSrc Git) string
- func ParseRepoNameFromGitSource(gitSrc Git) string
- type Dependencies
- type Dependency
- func (dep *Dependency) Download(localPath string) (*Dependency, error)
- func (dep *Dependency) FillDepInfo() error
- func (dep *Dependency) GenDepFullName() string
- func (dep *Dependency) GetLocalFullPath(rootpath string) string
- func (dep *Dependency) MarshalTOML() string
- func (dep *Dependency) UnmarshalModTOML(data interface{}) error
- type Git
- type KclPkg
- func (kclPkg *KclPkg) AddDeps(opt *opt.AddOptions) error
- func (kclPkg *KclPkg) Compile(kpmHome string, kclvmCompiler *runner.Compiler) (*kcl.KCLResultList, error)
- func (kclPkg *KclPkg) CreateDefaultKclProgram() error
- func (kclPkg *KclPkg) DefaultTarPath() string
- func (kclPkg *KclPkg) DownloadDep(d *Dependency, localPath string) error
- func (kclPkg *KclPkg) GetEntryKclFilesFromModFile() []string
- func (kclPkg *KclPkg) GetKclOpts() *kcl.Option
- func (kclPkg *KclPkg) GetLockFilePath() string
- func (kclPkg *KclPkg) GetPkgEdition() string
- func (kclPkg *KclPkg) GetPkgFullName() string
- func (kclPkg *KclPkg) GetPkgName() string
- func (kclPkg *KclPkg) GetPkgProfile() Profile
- func (kclPkg *KclPkg) GetPkgTag() string
- func (kclPkg *KclPkg) GetPkgTarName() string
- func (kclPkg *KclPkg) InitEmptyPkg() error
- func (kclPkg *KclPkg) IsVendorMode() bool
- func (kclPkg *KclPkg) LocalVendorPath() string
- func (kclPkg *KclPkg) LockDepsVersion() error
- func (kclPkg *KclPkg) PackageCurrentPkgPath(vendorMode bool) (string, error)
- func (kclPkg *KclPkg) PackageKclPkg(kpmHome string, tarPath string, vendorMode bool) error
- func (kclPkg *KclPkg) PackageToTarball(tarPath string, vendorMode bool) error
- func (kclPkg *KclPkg) ResolveDeps(kpmHome string) (map[string]string, error)
- func (kclPkg *KclPkg) ResolveDepsMetadata(kpmHome string, update bool) error
- func (kclPkg *KclPkg) ResolveDepsMetadataInJsonStr(kpmHome string, update bool) (string, error)
- func (kclPkg *KclPkg) SetVendorMode(vendorMode bool)
- func (kclPkg *KclPkg) UpdateModAndLockFile() error
- func (kclPkg *KclPkg) ValidateKpmHome(kpmHome string) *reporter.KpmEvent
- func (kclPkg *KclPkg) VendorDeps(cachePath string) error
- type Local
- type ModFile
- type Oci
- type Package
- type Profile
- type Source
Constants ¶
const ( MOD_FILE = "kcl.mod" MOD_LOCK_FILE = "kcl.mod.lock" )
const DEFAULT_KCL_FILE_CONTENT = "The_first_kcl_program = 'Hello World!'"
const DEFAULT_KCL_FILE_NAME = "main.k"
const DEPS_FLAG = "dependencies"
const DEPS_PATTERN = "[dependencies]"
const DEP_PATTERN = "%s = %s"
const EDITION_FLAG = "edition"
const GTI_TAG_FLAG = "tag"
const GTI_TAG_PATTERN = "tag = \"%s\""
const GTI_URL_FLAG = "git"
const GTI_URL_PATTERN = "git = \"%s\""
const LOCAL_PATH_FLAG = "path"
const LOCAL_PATH_PATTERN = "path = %s"
const LOCK_FILE_NAME = "kcl.mod.lock"
const NAME_FLAG = "name"
const NEWLINE = "\n"
const PACKAGE_FLAG = "package"
const PACKAGE_PATTERN = "[package]"
const PKG_NAME_PATTERN = "%s_%s"
const PROFILES_FLAG = "profile"
const PROFILE_PATTERN = "[profile]"
const SEPARATOR = ", "
const SOURCE_PATTERN = "{ %s }"
const TAR_SUFFIX = ".tar"
const VERSION_FLAG = "version"
Variables ¶
This section is empty.
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
ParseRepoFullNameFromGitSource will extract the kcl package name from the git url.
func ParseRepoNameFromGitSource ¶ added in v0.3.3
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) 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) Download ¶ added in v0.3.3
func (dep *Dependency) Download(localPath string) (*Dependency, error)
Download will download the kcl package to localPath from registory.
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) GetLocalFullPath ¶ added in v0.3.4
func (dep *Dependency) GetLocalFullPath(rootpath string) string
GetLocalFullPath will get the local path of a dependency.
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
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) Download ¶ added in v0.3.3
Download will download the kcl package to localPath from git url.
func (*Git) MarshalTOML ¶ added in v0.3.3
func (*Git) UnmarshalModTOML ¶ added in v0.3.3
type KclPkg ¶
type KclPkg struct { HomePath string // The dependencies in the current kcl package are the dependencies of kcl.mod.lock, // not the dependencies in kcl.mod. Dependencies // contains filtered or unexported fields }
func LoadKclPkg ¶
Load the kcl package from directory containing kcl.mod and kcl.mod.lock file.
func LoadKclPkgFromTar ¶
LoadKclPkgFromTar will load a kcl package from a tar path.
func NewKclPkg ¶
func NewKclPkg(opts *opt.InitOptions) KclPkg
func (*KclPkg) AddDeps ¶
func (kclPkg *KclPkg) AddDeps(opt *opt.AddOptions) error
AddDeps will add the dependencies to current kcl package and update kcl.mod and kcl.mod.lock.
func (*KclPkg) Compile ¶
func (kclPkg *KclPkg) Compile(kpmHome string, kclvmCompiler *runner.Compiler) (*kcl.KCLResultList, error)
CompileWithEntryFile will call kcl compiler to compile the current kcl package and its dependent packages.
func (*KclPkg) CreateDefaultKclProgram ¶
CreateDefaultKclProgram will create a default kcl program "The_first_kcl_program = 'Hello World!'" in 'main.k'.
func (*KclPkg) DefaultTarPath ¶
DefaultTarPath will return "<kcl_package_path>/<package_name>-<package_version>.tar"
func (*KclPkg) DownloadDep ¶
func (kclPkg *KclPkg) DownloadDep(d *Dependency, localPath string) error
DownloadDep will download the corresponding dependency.
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) GetPkgEdition ¶ added in v0.3.4
GetPkgEdition returns compile edition 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) 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) InitEmptyPkg ¶
InitEmptyModule inits an empty kcl module and create a default kcl.modfile.
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) PackageCurrentPkgPath ¶
PackageCurrentPkg will package the current kcl package into the current path and return the tar path. And the tar will be named "<package_name>-<package_version>.tar" <package_name> is the package name specified in kcl.mod. <package_version> is the package version specified in kcl.mod.
func (*KclPkg) PackageKclPkg ¶
PackageKclPkg will save all dependencies to the 'vendor' in current pacakge and package the current package into tar
func (*KclPkg) PackageToTarball ¶
PkgCurrentPackageIntoTarPath will package the current kcl package into 'tarPath'.
func (*KclPkg) ResolveDeps ¶
ResolveDeps will return a map between dependency name and its local path, and analyze the dependencies of the current kcl package, look for the package in the $KCL_PKG_PATH or kcl package vendor subdirectory, if find it, ResolveDeps will remember the local path of the dependency, if can’t find it, re-download the dependency and remember the local path.
func (*KclPkg) ResolveDepsMetadata ¶
ResolveDepsMetadata will calculate the local storage path of the external package, and check whether the package exists locally. If the package does not exist, it will re-download to the local.
func (*KclPkg) ResolveDepsMetadataInJsonStr ¶
ResolveDepsMetadataInJsonStr will calculate the local storage path of the external package, and check whether the package exists locally. If the package does not exist, it will re-download to the local. Finally, the calculated metadata of the dependent packages is serialized into a json string and returned.
func (*KclPkg) SetVendorMode ¶
func (*KclPkg) UpdateModAndLockFile ¶
updateModAndLockFile will update kcl.mod and kcl.mod.lock
func (*KclPkg) ValidateKpmHome ¶
Verify that the environment variable KPM HOME is set correctly
func (*KclPkg) VendorDeps ¶
Vendor all dependencies to the 'vendor' in current pacakge.
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) UnmarshalModTOML ¶ added in v0.3.3
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
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
FillDependenciesInfo will fill registry information for all dependencies in a 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) 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 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) UnmarshalModTOML ¶ added in v0.3.3
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 }
'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"`
}
Profile is the profile section of 'kcl.mod'. It is used to specify the compilation options of the current package.
func (*Profile) IntoKclOptions ¶ added in v0.3.3
IntoKclOptions will transform the profile into kcl options.
func (*Profile) MarshalTOML ¶ added in v0.3.3
type Source ¶ added in v0.3.3
Source is the package source from registry.