diff options
| author | Nicolas Paul <n@nc0.fr> | 2023-05-31 00:44:17 +0200 |
|---|---|---|
| committer | Nicolas Paul <n@nc0.fr> | 2023-05-31 00:48:47 +0200 |
| commit | 1724bd8d98d791faf253aeddcfce02a1accd1ff9 (patch) | |
| tree | 6034f364e100e87124d90c0ac22c12c6993348e3 /pkg/config/lib/git/git.go | |
| parent | 43be0e328a0e4c8c3d1ff88eb81b82402fcfa7c1 (diff) | |
Add Git library for Starlark
The Git library provides Starlark macros to easily index Go modules hosted on Git repositories. It also provides macros for services like GitHub, Bitbucket, Source Hut, Gitiles (via Gerrit)...
Signed-off-by: Nicolas Paul <n@nc0.fr>
Diffstat (limited to 'pkg/config/lib/git/git.go')
| -rw-r--r-- | pkg/config/lib/git/git.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/pkg/config/lib/git/git.go b/pkg/config/lib/git/git.go new file mode 100644 index 0000000..f1e0607 --- /dev/null +++ b/pkg/config/lib/git/git.go @@ -0,0 +1,34 @@ +// Package git provides Starlark macros to declare modules hosted on Git +// repositories. +package git + +import ( + _ "embed" + "go.nc0.fr/svgu/pkg/config" + "go.starlark.net/starlark" + "go.starlark.net/starlarkstruct" + "sync" +) + +var ( + once = sync.Once{} + git = starlark.StringDict{} + //go:embed git.star + gitFile string + gitErr error +) + +// LoadGitModule loads the git module. +func LoadGitModule(t *starlark.Thread) (starlark.StringDict, error) { + once.Do(func() { + env := starlark.StringDict{ + "module": starlark.NewBuiltin("module", + config.InternModule), + "make_module": starlark.NewBuiltin("mod", + starlarkstruct.MakeModule), + } + git, gitErr = starlark.ExecFile(t, "git.star", gitFile, env) + }) + + return git, gitErr +} |
