Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
M0Rf30 committed Oct 21, 2023
1 parent 564fa15 commit 18771b6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/options/strip.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package options

// StripScript is a scriptlet taken from makepkg resources.
// It's executed by mvdan/sh interpreter and provides strip instructions to dpkg-buildpackage.
// Although it's a very dirty solution, for now it's the faster way to have this essential feature.
const StripScript = `
strip_file() {
local binary=$1; shift
Expand Down
13 changes: 13 additions & 0 deletions pkg/packer/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,27 @@ import (
"github.com/M0Rf30/yap/pkg/redhat"
)

// Packer is the common interface implemented by all package managers.
type Packer interface {
// Prepare appends the dependencies required to build all the projects.
// It returns any error if encountered.
Prepare(depends []string) error
// Build reads the path where the final artifact will be written.
// It returns any error if encountered.
Build(output string) error
// Install reads the path where the final artifact will be written.
// It returns any error if encountered.
Install(output string) error
// PrepareEnvironment reads a flag to install golang tools on request, on the build machine.
// It returns any error if encountered.
PrepareEnvironment(flag bool) error
// Update performs a package manager update operation.
// It returns any error if encountered.
Update() error
}

// GetPackageManager reads the pkgBuild structure and the distro name.
// It returns a Packer interface representing the specialized package manager for that distro.
func GetPackageManager(pkgBuild *pkgbuild.PKGBUILD, distro string) Packer {
var packageManager Packer

Expand Down
9 changes: 9 additions & 0 deletions pkg/pkgbuild/pkgbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (

var Verbose bool

// PKGBUILD defines all the fields accepted by the yap specfile (variables, arrays, functions).
// It adds some exotics fields to manage debconfig templating and other rpm/deb descriptors.
type PKGBUILD struct {
Arch []string
Backup []string
Expand Down Expand Up @@ -61,6 +63,10 @@ type PKGBUILD struct {
priorities map[string]int
}

// AddItem reads a key and the related data.
// It checks the key for __ token and give to it a priority value.
// After that binds every element (variable, array, funtion) to the current environment.

Check failure on line 68 in pkg/pkgbuild/pkgbuild.go

View workflow job for this annotation

GitHub Actions / golangci-lint-github-check

[golangci-lint-github-check] pkg/pkgbuild/pkgbuild.go#L68

`funtion` is a misspelling of `function` (misspell)
Raw output
pkg/pkgbuild/pkgbuild.go:68:53: `funtion` is a misspelling of `function` (misspell)
// After that binds every element (variable, array, funtion) to the current environment.
                                                    ^
// It returns any error if encountered.
func (pkgBuild *PKGBUILD) AddItem(key string, data any) error {
key, priority, err := pkgBuild.parseDirective(key)
if err != nil {
Expand Down Expand Up @@ -270,6 +276,9 @@ func (pkgBuild *PKGBUILD) mapVariables(key string, data any) {
}
}

// parseDirective reads a directive string and detect any specialized one (i.e only to be applied for ubuntu).
// It detects if distro codename is given and calculates and assigns a priority to the directive.
// It returns the directive key, assigned priority and any error if occurred.
func (pkgBuild *PKGBUILD) parseDirective(input string) (string, int, error) {
split := strings.Split(input, "__")
key := split[0]
Expand Down
2 changes: 2 additions & 0 deletions pkg/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ func (src *Source) symlinkSources() error {
return err
}

// validate checks that items declared in the source array
// have a valid hashsum. It returns any error encountered.
func (src *Source) validate() error {
info, err := os.Stat(filepath.Join(src.StartDir, src.SourceItemPath))
if err != nil {
Expand Down

0 comments on commit 18771b6

Please sign in to comment.