diff --git a/api/download.go b/api/download.go index f1511e1..4c8ee73 100644 --- a/api/download.go +++ b/api/download.go @@ -11,7 +11,7 @@ import ( "strings" ) -// retrieves the Source directory of a given Source +// Generate the destination path for the source based on its type and module name func GetSourcePath(source Source, moduleName string) string { switch source.Type { case "git": @@ -30,8 +30,7 @@ func GetSourcePath(source Source, moduleName string) string { return "" } -// DownloadSource downloads a source to the downloads directory -// according to its type (git, tar, ...) +// Download the source based on its type and validate its checksum func DownloadSource(downloadPath string, source Source, moduleName string) error { fmt.Printf("Downloading source: %s\n", source.URL) @@ -60,6 +59,7 @@ func DownloadSource(downloadPath string, source Source, moduleName string) error } } +// Clone a specific tag from a Git repository to the destination directory func gitCloneTag(url, tag, dest string) error { cmd := exec.Command( "git", @@ -71,6 +71,7 @@ func gitCloneTag(url, tag, dest string) error { return cmd.Run() } +// Retrieve the latest Git repository commit hash for a given branch from the destination directory func gitGetLatestCommit(branch, dest string) (string, error) { cmd := exec.Command("git", "--no-pager", "log", "-n", "1", "--pretty=format:\"%H\"", branch) cmd.Dir = dest @@ -82,6 +83,7 @@ func gitGetLatestCommit(branch, dest string) (string, error) { return strings.Trim(string(latest_tag), "\""), nil } +// Check out a specific Git repository branch or commit in the destination directory func gitCheckout(value, dest string) error { cmd := exec.Command("git", "checkout", value) cmd.Stdout = os.Stdout @@ -90,8 +92,7 @@ func gitCheckout(value, dest string) error { return cmd.Run() } -// DownloadGitSource downloads a git source to the downloads directory -// and checks out the commit or tag +// Download a Git source repository based on the specified tag, branch, or commit func DownloadGitSource(downloadPath string, source Source, moduleName string) error { fmt.Printf("Downloading git source: %s\n", source.URL) @@ -136,7 +137,7 @@ func DownloadGitSource(downloadPath string, source Source, moduleName string) er return gitCheckout(source.Commit, dest) } -// DownloadTarSource downloads a tar archive to the downloads directory +// Download a tarball from the specified URL and save it to the destination path func DownloadTarSource(downloadPath string, source Source, moduleName string) error { fmt.Printf("Source is tar: %s\n", source.URL) // Create the destination path @@ -165,8 +166,7 @@ func DownloadTarSource(downloadPath string, source Source, moduleName string) er return nil } -// MoveSources moves all sources from the downloads directory to the -// sources directory +// Move downloaded sources from the download path to the sources path func MoveSources(downloadPath string, sourcesPath string, sources []Source, moduleName string) error { fmt.Println("Moving sources") @@ -180,9 +180,9 @@ func MoveSources(downloadPath string, sourcesPath string, sources []Source, modu return nil } -// MoveSource moves a source from the downloads directory to the -// sources directory, by extracting if a tar archive or moving if a -// git repository +// Move or extract a source from the download path to the sources path depending on its type +// tarballs: extract +// git repositories: move func MoveSource(downloadPath string, sourcesPath string, source Source, moduleName string) error { fmt.Printf("Moving source: %s\n", moduleName) @@ -211,7 +211,7 @@ func MoveSource(downloadPath string, sourcesPath string, source Source, moduleNa } } -// checksumValidation validates the checksum of a file +// Validate the checksum of the downloaded file func checksumValidation(source Source, path string) error { // No checksum provided if len(strings.TrimSpace(source.Checksum)) == 0 { @@ -243,6 +243,8 @@ func checksumValidation(source Source, path string) error { return nil } +// Download a file source from a URL and save it to the specified download path. +// Create necessary directories and handle file naming based on the URL extension. func DownloadFileSource(downloadPath string, source Source, moduleName string) error { fmt.Printf("Source is file: %s\n", source.URL) diff --git a/api/finalize-scopes.go b/api/finalize-scopes.go index 18795b9..6822f34 100644 --- a/api/finalize-scopes.go +++ b/api/finalize-scopes.go @@ -15,6 +15,7 @@ var RUNTIME int32 = 8 // / Get a read-only filesystem of the Image var FS int32 = 16 +// Information about the image, recipe, runtime, and file system mountpoint type ScopeData struct { ImageName string ImageID string diff --git a/api/structs.go b/api/structs.go index 8fe7cf7..5e10b7e 100644 --- a/api/structs.go +++ b/api/structs.go @@ -1,5 +1,6 @@ package api +// Configuration for a source type Source struct { URL string `json:"url"` Checksum string `json:"checksum"` @@ -12,6 +13,7 @@ type Source struct { Paths []string `json:"paths"` } +// Configuration for a recipe type Recipe struct { Name string Id string @@ -25,6 +27,7 @@ type Recipe struct { Finalize []interface{} } +// Configuration for a stage in the recipe type Stage struct { Id string `json:"id"` Base string `json:"base"` @@ -48,32 +51,38 @@ const ( FinalizePlugin ) +// Information about a plugin type PluginInfo struct { Name string Type PluginType } +// Configuration for copying files or directories in a stage type Copy struct { From string SrcDst map[string]string Workdir string } +// Configuration for adding files or directories in a stage type Add struct { SrcDst map[string]string Workdir string } +// Configuration for the entrypoint of a container type Entrypoint struct { Exec []string Workdir string } +// Configuration for a command to run in the container type Cmd struct { Exec []string Workdir string } +// Configuration for commands to run in the container type Run struct { Commands []string Workdir string diff --git a/cmd/build.go b/cmd/build.go index 91e0b60..5bdcdaa 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -11,6 +11,9 @@ import ( "github.com/vanilla-os/vib/core" ) +// Create a new build command for the Cobra CLI +// +// Returns: new Cobra command for building a recipe func NewBuildCommand() *cobra.Command { cmd := &cobra.Command{ Use: "build", @@ -28,6 +31,7 @@ func NewBuildCommand() *cobra.Command { return cmd } +// Handle the build command for the Cobra CLI func buildCommand(cmd *cobra.Command, args []string) error { commonNames := []string{ "recipe.yml", diff --git a/cmd/compile.go b/cmd/compile.go index c550f5d..f003b1a 100644 --- a/cmd/compile.go +++ b/cmd/compile.go @@ -9,6 +9,7 @@ import ( "github.com/vanilla-os/vib/core" ) +// Create and return a new compile command for the Cobra CLI func NewCompileCommand() *cobra.Command { cmd := &cobra.Command{ Use: "compile", @@ -26,6 +27,7 @@ func NewCompileCommand() *cobra.Command { return cmd } +// Execute the compile command: compile the given recipe into a container image func compileCommand(cmd *cobra.Command, args []string) error { commonNames := []string{ "recipe.yml", @@ -68,6 +70,9 @@ func compileCommand(cmd *cobra.Command, args []string) error { return nil } +// Detect the container runtime by checking the system path +// +// Returns: runtime name or an empty string if no runtime is found func detectRuntime() string { path, _ := exec.LookPath("docker") if path != "" { diff --git a/cmd/root.go b/cmd/root.go index be13b65..33e6e54 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -23,12 +23,14 @@ var rootCmd = &cobra.Command{ Version: Version, } +// Initialize the root command with build, test, and compile commands func init() { rootCmd.AddCommand(NewBuildCommand()) rootCmd.AddCommand(NewTestCommand()) rootCmd.AddCommand(NewCompileCommand()) } +// Execute the root command, handling root user environment setup and privilege dropping func Execute() error { if os.Getuid() == 0 { IsRoot = true diff --git a/cmd/test.go b/cmd/test.go index af18c03..e93deb8 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -7,6 +7,7 @@ import ( "github.com/vanilla-os/vib/core" ) +// Create and return a new test command for the Cobra CLI func NewTestCommand() *cobra.Command { cmd := &cobra.Command{ Use: "test", @@ -19,6 +20,7 @@ func NewTestCommand() *cobra.Command { return cmd } +// Validate the provided recipe by testing it func testCommand(cmd *cobra.Command, args []string) error { if len(args) == 0 { return fmt.Errorf("no recipe path specified") diff --git a/core/build.go b/core/build.go index 911aa3d..049b5ef 100644 --- a/core/build.go +++ b/core/build.go @@ -10,6 +10,7 @@ import ( "github.com/vanilla-os/vib/api" ) +// Add a WORKDIR instruction to the containerfile func ChangeWorkingDirectory(workdir string, containerfile *os.File) error { if workdir != "" { _, err := containerfile.WriteString( @@ -22,6 +23,7 @@ func ChangeWorkingDirectory(workdir string, containerfile *os.File) error { return nil } +// Add a WORKDIR instruction to reset to the root directory func RestoreWorkingDirectory(workdir string, containerfile *os.File) error { if workdir != "" { _, err := containerfile.WriteString( @@ -35,7 +37,7 @@ func RestoreWorkingDirectory(workdir string, containerfile *os.File) error { return nil } -// BuildRecipe builds a Containerfile from a recipe path +// Load and build a Containerfile from the specified recipe func BuildRecipe(recipePath string) (api.Recipe, error) { // load the recipe recipe, err := LoadRecipe(recipePath) @@ -63,8 +65,7 @@ func BuildRecipe(recipePath string) (api.Recipe, error) { return *recipe, nil } -// BuildContainerfile builds a Containerfile from a recipe -// and a list of modules commands +// Generate a Containerfile from the recipe func BuildContainerfile(recipe *api.Recipe) error { containerfile, err := os.Create(recipe.Containerfile) if err != nil { @@ -357,7 +358,7 @@ func BuildContainerfile(recipe *api.Recipe) error { return nil } -// BuildModules builds a list of modules commands from a list of modules +// Build commands for each module in the recipe func BuildModules(recipe *api.Recipe, modules []interface{}) ([]ModuleCommand, error) { cmds := []ModuleCommand{} for _, moduleInterface := range modules { @@ -382,9 +383,7 @@ func BuildModules(recipe *api.Recipe, modules []interface{}) ([]ModuleCommand, e return cmds, nil } -// BuildModule builds a module command from a module -// this is done by calling the appropriate module builder -// function based on the module type +// Build a command string for the given module in the recipe func BuildModule(recipe *api.Recipe, moduleInterface interface{}) (string, error) { var module Module err := mapstructure.Decode(moduleInterface, &module) diff --git a/core/compile.go b/core/compile.go index 1d16fab..cbbffca 100644 --- a/core/compile.go +++ b/core/compile.go @@ -10,7 +10,7 @@ import ( "github.com/vanilla-os/vib/api" ) -// CompileRecipe compiles a recipe into a runnable image. +// Compile and build the recipe using the specified runtime func CompileRecipe(recipePath string, runtime string, isRoot bool, origGid int, origUid int) error { recipe, err := BuildRecipe(recipePath) if err != nil { @@ -56,6 +56,7 @@ func CompileRecipe(recipePath string, runtime string, isRoot bool, origGid int, return nil } +// Build an OCI image using the specified recipe through Docker func compileDocker(recipe api.Recipe, gid int, uid int) error { docker, err := exec.LookPath("docker") if err != nil { @@ -75,6 +76,7 @@ func compileDocker(recipe api.Recipe, gid int, uid int) error { return cmd.Run() } +// Build an OCI image using the specified recipe through Podman func compilePodman(recipe api.Recipe, gid int, uid int) error { podman, err := exec.LookPath("podman") if err != nil { diff --git a/core/finalize.go b/core/finalize.go index a48b0cb..e318e59 100644 --- a/core/finalize.go +++ b/core/finalize.go @@ -7,12 +7,14 @@ import ( "strings" ) +// Configuration for storage drivers type StorageConf struct { Driver string Runroot string Graphroot string } +// Retrieve the container storage configuration based on the runtime func GetContainerStorage(runtime string) (cstorage.Store, error) { storageconfig := &StorageConf{} if runtime == "podman" { @@ -50,6 +52,7 @@ func GetContainerStorage(runtime string) (cstorage.Store, error) { return store, err } +// Retrieve the image ID for a given image name from the storage func GetImageID(name string, store cstorage.Store) (string, error) { images, err := store.Images() if err != nil { @@ -65,6 +68,7 @@ func GetImageID(name string, store cstorage.Store) (string, error) { return "", fmt.Errorf("image not found") } +// Retrieve the top layer ID for a given image ID from the storage func GetTopLayerID(imageid string, store cstorage.Store) (string, error) { images, err := store.Images() if err != nil { @@ -78,6 +82,7 @@ func GetTopLayerID(imageid string, store cstorage.Store) (string, error) { return "", fmt.Errorf("no top layer for id %s found", imageid) } +// Mount the image and return the mount directory func MountImage(imagename string, imageid string, runtime string) (string, error) { store, err := GetContainerStorage(runtime) if err != nil { diff --git a/core/resolver_test.go b/core/resolver_test.go index 568b608..2624dcc 100644 --- a/core/resolver_test.go +++ b/core/resolver_test.go @@ -8,6 +8,7 @@ import ( "github.com/vanilla-os/vib/api" ) +// Test the DownloadSource function to ensure it downloads and verifies the source file func TestDownloadSource(t *testing.T) { tmp := t.TempDir() @@ -29,6 +30,7 @@ func TestDownloadSource(t *testing.T) { defer os.Remove("/tmp/example") // clean up } +// Test the DownloadTarSource function to ensure it downloads and verifies the tar file func TestDownloadTarSource(t *testing.T) { tmp := t.TempDir() diff --git a/core/shell.go b/core/shell.go index c4f03aa..7f48ed5 100644 --- a/core/shell.go +++ b/core/shell.go @@ -8,6 +8,7 @@ import ( "github.com/vanilla-os/vib/api" ) +// Configuration for shell modules type ShellModule struct { Name string `json:"name"` Type string `json:"type"` @@ -15,6 +16,9 @@ type ShellModule struct { Commands []string } +// Build shell module commands and return them as a single string +// +// Returns: Concatenated shell commands or an error if any step fails func BuildShellModule(moduleInterface interface{}, recipe *api.Recipe) (string, error) { var module ShellModule err := mapstructure.Decode(moduleInterface, &module) diff --git a/core/structs.go b/core/structs.go index e8431dc..bc56dbb 100644 --- a/core/structs.go +++ b/core/structs.go @@ -2,6 +2,7 @@ package core import "C" +// Configuration for a module type Module struct { Name string `json:"name"` Workdir string @@ -10,24 +11,28 @@ type Module struct { Content []byte // The entire module unparsed as a []byte, used by plugins } +// Configuration for finalization steps type Finalize struct { Name string `json:"name"` Type string `json:"type"` Content []byte // The entire module unparsed as a []byte, used by plugins } +// Configuration for including other modules or recipes type IncludesModule struct { Name string `json:"name"` Type string `json:"type"` Includes []string `json:"includes"` } +// Information for building a module type ModuleCommand struct { Name string Command string Workdir string } +// Configuration for a plugin type Plugin struct { Name string BuildFunc func(*C.char, *C.char) string diff --git a/finalize-plugins/genimage.go b/finalize-plugins/genimage.go index 6e255b5..ec67897 100644 --- a/finalize-plugins/genimage.go +++ b/finalize-plugins/genimage.go @@ -10,6 +10,7 @@ import ( "strings" ) +// Configuration for generating an image type Genimage struct { Name string `json:"name"` Type string `json:"type"` @@ -20,6 +21,8 @@ type Genimage struct { Outputpath string `json:"outputpath"` } +// Provide plugin information as a JSON string +// //export PlugInfo func PlugInfo() *C.char { plugininfo := &api.PluginInfo{Name: "genimage", Type: api.FinalizePlugin} @@ -30,17 +33,27 @@ func PlugInfo() *C.char { return C.CString(string(pluginjson)) } +// Provide the plugin scope +// //export PluginScope func PluginScope() int32 { // int32 is defined as GoInt32 in cgo which is the same as a C int return api.IMAGENAME | api.FS | api.RECIPE } +// Replace placeholders in the path with actual values from ScopeData +// $PROJROOT -> Recipe.ParentPath +// $FSROOT -> FS func ParsePath(path string, data *api.ScopeData) string { path = strings.Replace(path, "$PROJROOT", data.Recipe.ParentPath, 1) path = strings.Replace(path, "$FSROOT", data.FS, 1) return path } +// Complete the build process for a generated image module. +// Find the binary if not specified, replace path placeholders +// in the module paths, and run the command +// with the provided configuration +// //export FinalizeBuild func FinalizeBuild(moduleInterface *C.char, extraData *C.char) *C.char { var module *Genimage diff --git a/finalize-plugins/shell-final.go b/finalize-plugins/shell-final.go index cce250b..03f0da4 100644 --- a/finalize-plugins/shell-final.go +++ b/finalize-plugins/shell-final.go @@ -10,6 +10,7 @@ import ( "strings" ) +// Configuration for a set of shell commands type Shell struct { Name string `json:"name"` Type string `json:"type"` @@ -17,6 +18,8 @@ type Shell struct { Cwd string `json:"cwd"` } +// Provide plugin information as a JSON string +// //export PlugInfo func PlugInfo() *C.char { plugininfo := &api.PluginInfo{Name: "shell-final", Type: api.FinalizePlugin} @@ -27,17 +30,24 @@ func PlugInfo() *C.char { return C.CString(string(pluginjson)) } +// Provide the plugin scope +// //export PluginScope func PluginScope() int32 { // int32 is defined as GoInt32 in cgo which is the same as a C int return api.IMAGENAME | api.FS | api.RECIPE } +// Replace placeholders in the path with actual values from ScopeData +// $PROJROOT -> Recipe.ParentPath +// $FSROOT -> FS func parsePath(path string, data *api.ScopeData) string { path = strings.ReplaceAll(path, "$PROJROOT", data.Recipe.ParentPath) path = strings.ReplaceAll(path, "$FSROOT", data.FS) return path } +// Check if the command is in $PATH or includes a directory path. +// Return the full path if found, otherwise return the command unchanged. func baseCommand(command string, data *api.ScopeData) string { commandParts := strings.Split(command, " ") if strings.Contains(commandParts[0], "/") { @@ -51,17 +61,24 @@ func baseCommand(command string, data *api.ScopeData) string { } } +// Extract and return arguments from a command string func getArgs(command string, data *api.ScopeData) []string { commandParts := strings.Split(parsePath(command, data), " ") return commandParts[1:] } +// Generate an executable command by resolving the base command and arguments +// and wrapping them with appropriate syntax for execution. func genCommand(command string, data *api.ScopeData) []string { baseCommand := baseCommand(command, data) args := getArgs(command, data) return append(append(append([]string{"-c", "'"}, strings.Join(args, " ")), baseCommand), "'") } +// Execute shell commands from a Shell struct using the provided ScopeData. +// It parses and runs each command in the context of the provided working directory, +// or the recipe's parent path if no specific directory is given. +// //export FinalizeBuild func FinalizeBuild(moduleInterface *C.char, extraData *C.char) *C.char { var module *Shell diff --git a/finalize-plugins/sysext.go b/finalize-plugins/sysext.go index 5b4d0c2..3851adf 100644 --- a/finalize-plugins/sysext.go +++ b/finalize-plugins/sysext.go @@ -12,6 +12,7 @@ import ( "github.com/vanilla-os/vib/api" ) +// Configuration for system extensions type Sysext struct { Name string `json:"name"` Type string `json:"type"` @@ -19,6 +20,8 @@ type Sysext struct { OSReleaseVersionID string `json:"osreleaseversionid"` } +// Provide plugin information as a JSON string +// //export PlugInfo func PlugInfo() *C.char { plugininfo := &api.PluginInfo{Name: "sysext", Type: api.FinalizePlugin} @@ -29,11 +32,16 @@ func PlugInfo() *C.char { return C.CString(string(pluginjson)) } +// Provide the plugin scope +// //export PluginScope func PluginScope() int32 { // int32 is defined as GoInt32 in cgo which is the same as a C int return api.IMAGENAME | api.FS | api.RECIPE } +// Process and finalize the build by creating an extension release file and +// creating a SquashFS image from the filesystem +// //export FinalizeBuild func FinalizeBuild(moduleInterface *C.char, extraData *C.char) *C.char { var module *Sysext diff --git a/finalize-plugins/systemd-repart.go b/finalize-plugins/systemd-repart.go index 8d6a331..455f91c 100644 --- a/finalize-plugins/systemd-repart.go +++ b/finalize-plugins/systemd-repart.go @@ -10,6 +10,7 @@ import ( "strings" ) +// Configuration for systemd repartitioning type SystemdRepart struct { Name string `json:"name"` Type string `json:"type"` @@ -22,6 +23,8 @@ type SystemdRepart struct { DeferPartitions []string `json:"defer_partitions"` } +// Provide plugin information as a JSON string +// //export PlugInfo func PlugInfo() *C.char { plugininfo := &api.PluginInfo{Name: "systemd-repart", Type: api.FinalizePlugin} @@ -32,11 +35,16 @@ func PlugInfo() *C.char { return C.CString(string(pluginjson)) } +// Provide the plugin scope +// //export PluginScope func PluginScope() int32 { // int32 is defined as GoInt32 in cgo which is the same as a C int return api.IMAGENAME | api.FS | api.RECIPE } +// Finalize the build by executing systemd-repart with the provided configuration +// to generate and apply partitioning specifications and output results +// //export FinalizeBuild func FinalizeBuild(moduleInterface *C.char, extraData *C.char) *C.char { var module *SystemdRepart diff --git a/plugins/apt.go b/plugins/apt.go index 353849e..6e5aee2 100644 --- a/plugins/apt.go +++ b/plugins/apt.go @@ -12,6 +12,7 @@ import ( "github.com/vanilla-os/vib/api" ) +// Configuration for an APT module type AptModule struct { Name string `json:"name"` Type string `json:"type"` @@ -19,6 +20,7 @@ type AptModule struct { Source api.Source `json:"source"` } +// Options for APT package management type AptOptions struct { NoRecommends bool `json:"no_recommends"` InstallSuggests bool `json:"install_suggests"` @@ -26,6 +28,8 @@ type AptOptions struct { FixBroken bool `json:"fix_broken"` } +// Provide plugin information as a JSON string +// //export PlugInfo func PlugInfo() *C.char { plugininfo := &api.PluginInfo{Name: "apt", Type: api.BuildPlugin} @@ -36,8 +40,8 @@ func PlugInfo() *C.char { return C.CString(string(pluginjson)) } -// BuildAptModule builds a module that installs packages -// using the apt package manager +// Generate an apt-get install command from the provided module and recipe. +// Handle package installation and apply appropriate options. // //export BuildModule func BuildModule(moduleInterface *C.char, recipeInterface *C.char) *C.char { diff --git a/plugins/cmake.go b/plugins/cmake.go index 28e8e8f..1562c04 100644 --- a/plugins/cmake.go +++ b/plugins/cmake.go @@ -9,6 +9,7 @@ import ( "github.com/vanilla-os/vib/api" ) +// Configuration for a CMake module type CMakeModule struct { Name string `json:"name"` Type string `json:"type"` @@ -17,6 +18,8 @@ type CMakeModule struct { Source api.Source } +// Provide plugin information as a JSON string +// //export PlugInfo func PlugInfo() *C.char { plugininfo := &api.PluginInfo{Name: "cmake", Type: api.BuildPlugin} @@ -27,7 +30,8 @@ func PlugInfo() *C.char { return C.CString(string(pluginjson)) } -// BuildCMakeModule builds a module that builds a CMake project +// Generate a shell command to build a CMake project based on the provided module and recipe. +// Download and move the source, set up build variables and flags, and construct the CMake build command. // //export BuildModule func BuildModule(moduleInterface *C.char, recipeInterface *C.char) *C.char { diff --git a/plugins/dpkg-buildpackage.go b/plugins/dpkg-buildpackage.go index 1db1985..5f92dbd 100644 --- a/plugins/dpkg-buildpackage.go +++ b/plugins/dpkg-buildpackage.go @@ -9,12 +9,15 @@ import ( "github.com/vanilla-os/vib/api" ) +// Configuration for building a Debian package using dpkg type DpkgBuildModule struct { Name string `json:"name"` Type string `json:"type"` Source api.Source } +// Provide plugin information as a JSON string +// //export PlugInfo func PlugInfo() *C.char { plugininfo := &api.PluginInfo{Name: "dpkg-buildpackage", Type: api.BuildPlugin} @@ -25,8 +28,9 @@ func PlugInfo() *C.char { return C.CString(string(pluginjson)) } -// BuildDpkgModule builds a module that builds a dpkg project -// and installs the resulting .deb package +// Generate a command to build a Debian package using dpkg and install +// the resulting .deb package. Handle downloading, moving the source, +// and running dpkg-buildpackage with appropriate options. // //export BuildModule func BuildModule(moduleInterface *C.char, recipeInterface *C.char) *C.char { diff --git a/plugins/flatpak.go b/plugins/flatpak.go index 0f128f6..74580da 100644 --- a/plugins/flatpak.go +++ b/plugins/flatpak.go @@ -13,6 +13,7 @@ import ( "strings" ) +// Configuration for managing Flatpak repositories and packages type innerFlatpakModule struct { Repourl string `json:"repo-url"` Reponame string `json:"repo-name"` @@ -20,6 +21,8 @@ type innerFlatpakModule struct { Remove []string `json:"remove"` } +// Configuration for managing Flatpak repositories and packages +// for both system and user contexts type FlatpakModule struct { Name string `json:"name"` Type string `json:"type"` @@ -59,6 +62,8 @@ RestartSec=30 WantedBy=default.target ` +// Provide plugin information as a JSON string +// //export PlugInfo func PlugInfo() *C.char { plugininfo := &api.PluginInfo{Name: "flatpak", Type: api.BuildPlugin} @@ -69,6 +74,8 @@ func PlugInfo() *C.char { return C.CString(string(pluginjson)) } +// Generate a command to add a Flatpak remote repository. +// Add appropriate flags for system-wide or user-specific installation. func createRepo(module innerFlatpakModule, isSystem bool) string { fmt.Println("Adding remote ", isSystem, " ", module) command := "flatpak remote-add --if-not-exists" @@ -80,6 +87,10 @@ func createRepo(module innerFlatpakModule, isSystem bool) string { return fmt.Sprintf("%s %s %s", command, module.Reponame, module.Repourl) } +// Generate setup commands for Flatpak module configuration. +// Create scripts for system-wide and user-specific Flatpak setups, +// including repository addition, package installation, and service configuration. +// //export BuildModule func BuildModule(moduleInterface *C.char, recipeInterface *C.char) *C.char { var module *FlatpakModule diff --git a/plugins/go.go b/plugins/go.go index 5860717..c7d2eaf 100644 --- a/plugins/go.go +++ b/plugins/go.go @@ -8,6 +8,7 @@ import ( ) import "encoding/json" +// Configuration for building a Go module type GoModule struct { Name string `json:"name"` Type string `json:"type"` @@ -16,6 +17,8 @@ type GoModule struct { BuildFlags string } +// Provide plugin information as a JSON string +// //export PlugInfo func PlugInfo() *C.char { plugininfo := &api.PluginInfo{Name: "go", Type: api.BuildPlugin} @@ -26,9 +29,9 @@ func PlugInfo() *C.char { return C.CString(string(pluginjson)) } -// BuildGoModule builds a module that builds a Go project -// buildVars are used to customize the build command -// like setting the output binary name and location +// Generate a command to build a Go project. Add options for +// setting the output binary name and location based on the provided buildVars +// and BuildFlags, and handle downloading and moving the source. // //export BuildModule func BuildModule(moduleInterface *C.char, recipeInterface *C.char) *C.char { diff --git a/plugins/make.go b/plugins/make.go index b16ea8e..b93f412 100644 --- a/plugins/make.go +++ b/plugins/make.go @@ -8,12 +8,15 @@ import ( "github.com/vanilla-os/vib/api" ) +// Configuration for building a project using Make type MakeModule struct { Name string `json:"name"` Type string `json:"type"` Source api.Source } +// Provide plugin information as a JSON string +// //export PlugInfo func PlugInfo() *C.char { plugininfo := &api.PluginInfo{Name: "make", Type: api.BuildPlugin} @@ -24,7 +27,9 @@ func PlugInfo() *C.char { return C.CString(string(pluginjson)) } -// BuildMakeModule builds a module that builds a Make project +// Generate a command to build a Make project. Change directory +// to the source path, run 'make' to build the project, and 'make install' +// to install the built project. Handle downloading and moving the source. // //export BuildModule func BuildModule(moduleInterface *C.char, recipeInterface *C.char) *C.char { diff --git a/plugins/meson.go b/plugins/meson.go index 8002751..c6808d6 100644 --- a/plugins/meson.go +++ b/plugins/meson.go @@ -8,12 +8,15 @@ import ( "github.com/vanilla-os/vib/api" ) +// Configuration for building a Meson project type MesonModule struct { Name string Type string Source api.Source } +// Provide plugin information as a JSON string +// //export PlugInfo func PlugInfo() *C.char { plugininfo := &api.PluginInfo{Name: "meson", Type: api.BuildPlugin} @@ -24,7 +27,8 @@ func PlugInfo() *C.char { return C.CString(string(pluginjson)) } -// BuildMesonModule builds a module that builds a Meson project +// Generate a command to build a Meson project. Handle source downloading, moving, +// and use Meson and Ninja build tools with a temporary build directory based on the checksum. // //export BuildModule func BuildModule(moduleInterface *C.char, recipeInterface *C.char) *C.char { diff --git a/plugins/shim.go b/plugins/shim.go index f5da39d..bc37ee9 100644 --- a/plugins/shim.go +++ b/plugins/shim.go @@ -14,12 +14,15 @@ import ( "path/filepath" ) +// Configuration for a shim module type ShimModule struct { Name string `json:"name"` Type string `json:"type"` ShimType string `json:"shimtype"` } +// Provide plugin information as a JSON string +// //export PlugInfo func PlugInfo() *C.char { plugininfo := &api.PluginInfo{Name: "shim", Type: api.BuildPlugin} @@ -30,6 +33,10 @@ func PlugInfo() *C.char { return C.CString(string(pluginjson)) } +// Generate a command to build a shim module. Create temporary directories, +// write module and recipe data to files, and execute the plugin command with +// the paths to these files. +// //export BuildModule func BuildModule(moduleInterface *C.char, recipeInterface *C.char) *C.char { var module *ShimModule