This commit is contained in:
parent
74051861bf
commit
554987325b
49
build.go
49
build.go
|
@ -164,30 +164,6 @@ func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]st
|
||||||
dec.LikeDistros = false
|
dec.LikeDistros = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn, ok := dec.GetFunc("version")
|
|
||||||
if ok {
|
|
||||||
log.Info("Executing version()").Send()
|
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
|
||||||
|
|
||||||
err = fn(
|
|
||||||
ctx,
|
|
||||||
interp.Dir(filepath.Dir(script)),
|
|
||||||
interp.StdIO(os.Stdin, buf, os.Stderr),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
newVer := strings.TrimSpace(buf.String())
|
|
||||||
err = setVersion(ctx, runner, newVer)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("Updating version").Str("new", newVer).Send()
|
|
||||||
}
|
|
||||||
|
|
||||||
var vars BuildVars
|
var vars BuildVars
|
||||||
err = dec.DecodeVars(&vars)
|
err = dec.DecodeVars(&vars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -277,6 +253,31 @@ func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]st
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn, ok := dec.GetFunc("version")
|
||||||
|
if ok {
|
||||||
|
log.Info("Executing version()").Send()
|
||||||
|
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
|
||||||
|
err = fn(
|
||||||
|
ctx,
|
||||||
|
interp.Dir(filepath.Dir(script)),
|
||||||
|
interp.StdIO(os.Stdin, buf, os.Stderr),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
newVer := strings.TrimSpace(buf.String())
|
||||||
|
err = setVersion(ctx, runner, newVer)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
vars.Version = newVer
|
||||||
|
|
||||||
|
log.Info("Updating version").Str("new", newVer).Send()
|
||||||
|
}
|
||||||
|
|
||||||
fn, ok = dec.GetFunc("prepare")
|
fn, ok = dec.GetFunc("prepare")
|
||||||
if ok {
|
if ok {
|
||||||
log.Info("Executing prepare()").Send()
|
log.Info("Executing prepare()").Send()
|
||||||
|
|
|
@ -242,11 +242,11 @@ The rest of the scripts are available in all packages.
|
||||||
|
|
||||||
This section documents user-defined functions that can be added to build scripts. Any functions marked with `(*)` are required.
|
This section documents user-defined functions that can be added to build scripts. Any functions marked with `(*)` are required.
|
||||||
|
|
||||||
All functions except for `version()` are executed in the `$srcdir` directory
|
All functions are executed in the `$srcdir` directory
|
||||||
|
|
||||||
### version
|
### version
|
||||||
|
|
||||||
The `version()` function is the first to run. It updates the `version` variable. This allows for automatically deriving the version from sources. This is most useful for git packages, which usually don't need to be changed, so their `version` variable stays the same.
|
The `version()` function updates the `version` variable. This allows for automatically deriving the version from sources. This is most useful for git packages, which usually don't need to be changed, so their `version` variable stays the same.
|
||||||
|
|
||||||
An example of using this for git:
|
An example of using this for git:
|
||||||
|
|
||||||
|
@ -259,8 +259,6 @@ version() {
|
||||||
|
|
||||||
The AUR equivalent is the [`pkgver()` function](https://wiki.archlinux.org/title/VCS_package_guidelines#The_pkgver()_function)
|
The AUR equivalent is the [`pkgver()` function](https://wiki.archlinux.org/title/VCS_package_guidelines#The_pkgver()_function)
|
||||||
|
|
||||||
This function does not run in `$srcdir` because it is executed before the source directory is even created. Instead, it runs in `$repodir`.
|
|
||||||
|
|
||||||
### prepare
|
### prepare
|
||||||
|
|
||||||
The `prepare()` function is meant to prepare the sources for building and packaging. This is the function in which patches should be applied, for example, by the `patch` command, and where tools like `go generate` should be executed.
|
The `prepare()` function is meant to prepare the sources for building and packaging. This is the function in which patches should be applied, for example, by the `patch` command, and where tools like `go generate` should be executed.
|
||||||
|
|
Loading…
Reference in New Issue