v.vmod #
The v.vmod module reads and writes v.mod project metadata.
Manifest.catalog stores package names mapped to version strings. Manifest.workspaces stores workspace path strings. Both fields survive decode/encode round trips. Catalog keys may be identifiers or quoted names; duplicate keys and non-string values are errors. Workspaces require an array of strings.
import v.vmod
fn main() {
manifest := vmod.decode("Module { catalog: { foo: '^1.2.0' } workspaces: ['packages/*'] }")!
assert manifest.catalog['foo'] == '^1.2.0'
assert manifest.workspaces == ['packages/*']
decoded := vmod.decode(vmod.encode(manifest))!
assert decoded.catalog == manifest.catalog
}
Manifest.backend stores the backend field, such as backend: 'fastc'. The v command uses it as the default -b value for builds of the project.
Catalog and workspace fields represent metadata; dependency strings retain their literal meaning in the package manager.
fn decode #
fn decode(contents string) !Manifest
fn encode #
fn encode(manifest Manifest) string
encode serializes manifest metadata, including catalog and workspaces.
fn from_file #
fn from_file(vmod_path string) !Manifest
fn get_cache #
fn get_cache() &ModFileCacher
fn new_mod_file_cacher #
fn new_mod_file_cacher() &ModFileCacher
struct Manifest #
struct Manifest {
pub mut:
name string
base_url string
description string
version string
license string
repo_url string
repo_branch string = 'master'
author string
backend string
dependencies []string
unknown map[string][]string
catalog map[string]string
workspaces []string
}
fn (Manifest) resolved_base_url #
fn (manifest Manifest) resolved_base_url(vmod_root string) string
resolved_base_url returns the source folder configured by base_url, resolved relative to the folder containing the v.mod file.
fn (Manifest) source_root #
fn (manifest Manifest) source_root(vmod_root string) string
source_root returns the folder where sources are looked up under a v.mod. When base_url is set, it points at that folder; otherwise it falls back to the folder containing v.mod. The previous implicit src/ fallback is gone.
struct ModFileAndFolder #
struct ModFileAndFolder {
pub:
// vmod_file contains the full path of the found 'v.mod' file, or ''
// if no 'v.mod' file was found in file_path_dir, or in its parent folders.
vmod_file string
// vmod_folder contains the file_path_dir, if there is no 'v.mod' file in
// *any* of the parent folders, otherwise it is the first parent folder,
// where a v.mod file was found.
vmod_folder string
}
This file provides a caching mechanism for seeking quickly whether a given folder has a v.mod file in it or in any of its parent folders.
ModFileCacher.get(folder) works in such a way, that given this tree: examples/hanoi.v vlib/v.mod vlib/v/tests/project_with_c_code/v.mod vlib/v/tests/project_with_c_code/mod1/wrapper.c.v
ModFileCacher.get('examples') => ModFileAndFolder{'', 'examples'} ModFileCacher.get('vlib/v/tests') => ModFileAndFolder{'vlib/v.mod', 'vlib'} ModFileCacher.get('vlib/v') => ModFileAndFolder{'vlib/v.mod', 'vlib'} ModFileCacher.get('vlib/v/tests/project_with_c_code/mod1') => ModFileAndFolder{'vlib/v/tests/project_with_c_code/v.mod', 'vlib/v/tests/project_with_c_code'}
struct ModFileCacher #
struct ModFileCacher {
mut:
cache map[string]ModFileAndFolder
// folder_files caches os.ls(key)
folder_files map[string][]string
hits int
misses int
get_files_hits int
get_files_misses int
}
fn (ModFileCacher) debug #
fn (mcache &ModFileCacher) debug()
fn (ModFileCacher) get_by_file #
fn (mut mcache ModFileCacher) get_by_file(vfile string) ModFileAndFolder
fn (ModFileCacher) get_by_folder #
fn (mut mcache ModFileCacher) get_by_folder(vfolder string) ModFileAndFolder