internal/rosa: move azalea builtins
All checks were successful
Test / Create distribution (push) Successful in 1m5s
Test / Sandbox (push) Successful in 2m49s
Test / ShareFS (push) Successful in 3m45s
Test / Hakurei (push) Successful in 3m56s
Test / Sandbox (race detector) (push) Successful in 5m20s
Test / Hakurei (race detector) (push) Successful in 6m36s
Test / Flake checks (push) Successful in 1m21s
All checks were successful
Test / Create distribution (push) Successful in 1m5s
Test / Sandbox (push) Successful in 2m49s
Test / ShareFS (push) Successful in 3m45s
Test / Hakurei (push) Successful in 3m56s
Test / Sandbox (race detector) (push) Successful in 5m20s
Test / Hakurei (race detector) (push) Successful in 6m36s
Test / Flake checks (push) Successful in 1m21s
This improves readability. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
70
internal/rosa/builtins.go
Normal file
70
internal/rosa/builtins.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package rosa
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"hakurei.app/internal/pkg"
|
||||
)
|
||||
|
||||
const (
|
||||
// jobsE is expression for preferred job count set by [pkg].
|
||||
jobsE = `"$` + pkg.EnvJobs + `"`
|
||||
// jobsFlagE is expression for flag with preferred job count.
|
||||
jobsFlagE = `"-j$` + pkg.EnvJobs + `"`
|
||||
// jobsLE is expression for twice of preferred job count set by [pkg].
|
||||
jobsLE = `"$(expr ` + jobsE + ` '*' 2)"`
|
||||
// jobsLFlagE is expression for flag with double of preferred job count.
|
||||
jobsLFlagE = `"-j$(expr ` + jobsE + ` '*' 2)"`
|
||||
)
|
||||
|
||||
// newTar wraps [pkg.NewHTTPGetTar] with a simpler function signature.
|
||||
func newTar(url, checksum string, compression uint32) pkg.Artifact {
|
||||
return pkg.NewHTTPGetTar(nil, url, mustDecode(checksum), compression)
|
||||
}
|
||||
|
||||
// newFromCPAN is a helper for downloading release from CPAN.
|
||||
func newFromCPAN(author, name, version, checksum string) pkg.Artifact {
|
||||
return newTar(
|
||||
"https://cpan.metacpan.org/authors/id/"+
|
||||
author[:1]+"/"+author[:2]+"/"+author+"/"+
|
||||
name+"-"+version+".tar.gz",
|
||||
checksum,
|
||||
pkg.TarGzip,
|
||||
)
|
||||
}
|
||||
|
||||
// newFromGitLab is a helper for downloading source from GitLab.
|
||||
func newFromGitLab(domain, suffix, ref, checksum string) pkg.Artifact {
|
||||
return newTar(
|
||||
"https://"+domain+"/"+suffix+"/-/archive/"+
|
||||
ref+"/"+path.Base(suffix)+"-"+
|
||||
strings.ReplaceAll(ref, "/", "-")+".tar.bz2",
|
||||
checksum,
|
||||
pkg.TarBzip2,
|
||||
)
|
||||
}
|
||||
|
||||
// newFromGitHub is a helper for downloading source from Microsoft Github.
|
||||
func newFromGitHub(suffix, tag, checksum string) pkg.Artifact {
|
||||
return newTar(
|
||||
"https://github.com/"+suffix+
|
||||
"/archive/refs/tags/"+tag+".tar.gz",
|
||||
checksum,
|
||||
pkg.TarGzip,
|
||||
)
|
||||
}
|
||||
|
||||
// newFromGitHubRelease is a helper for downloading release tarball from
|
||||
// Microsoft Github.
|
||||
func newFromGitHubRelease(
|
||||
suffix, tag, name, checksum string,
|
||||
compression uint32,
|
||||
) pkg.Artifact {
|
||||
return newTar(
|
||||
"https://github.com/"+suffix+
|
||||
"/releases/download/"+tag+"/"+name,
|
||||
checksum,
|
||||
compression,
|
||||
)
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -620,68 +619,6 @@ func (attr *GenericHelper) script(t Toolchain, _ string) string {
|
||||
return script
|
||||
}
|
||||
|
||||
const (
|
||||
// jobsE is expression for preferred job count set by [pkg].
|
||||
jobsE = `"$` + pkg.EnvJobs + `"`
|
||||
// jobsFlagE is expression for flag with preferred job count.
|
||||
jobsFlagE = `"-j$` + pkg.EnvJobs + `"`
|
||||
// jobsLE is expression for twice of preferred job count set by [pkg].
|
||||
jobsLE = `"$(expr ` + jobsE + ` '*' 2)"`
|
||||
// jobsLFlagE is expression for flag with double of preferred job count.
|
||||
jobsLFlagE = `"-j$(expr ` + jobsE + ` '*' 2)"`
|
||||
)
|
||||
|
||||
// newTar wraps [pkg.NewHTTPGetTar] with a simpler function signature.
|
||||
func newTar(url, checksum string, compression uint32) pkg.Artifact {
|
||||
return pkg.NewHTTPGetTar(nil, url, mustDecode(checksum), compression)
|
||||
}
|
||||
|
||||
// newFromCPAN is a helper for downloading release from CPAN.
|
||||
func newFromCPAN(author, name, version, checksum string) pkg.Artifact {
|
||||
return newTar(
|
||||
"https://cpan.metacpan.org/authors/id/"+
|
||||
author[:1]+"/"+author[:2]+"/"+author+"/"+
|
||||
name+"-"+version+".tar.gz",
|
||||
checksum,
|
||||
pkg.TarGzip,
|
||||
)
|
||||
}
|
||||
|
||||
// newFromGitLab is a helper for downloading source from GitLab.
|
||||
func newFromGitLab(domain, suffix, ref, checksum string) pkg.Artifact {
|
||||
return newTar(
|
||||
"https://"+domain+"/"+suffix+"/-/archive/"+
|
||||
ref+"/"+path.Base(suffix)+"-"+
|
||||
strings.ReplaceAll(ref, "/", "-")+".tar.bz2",
|
||||
checksum,
|
||||
pkg.TarBzip2,
|
||||
)
|
||||
}
|
||||
|
||||
// newFromGitHub is a helper for downloading source from Microsoft Github.
|
||||
func newFromGitHub(suffix, tag, checksum string) pkg.Artifact {
|
||||
return newTar(
|
||||
"https://github.com/"+suffix+
|
||||
"/archive/refs/tags/"+tag+".tar.gz",
|
||||
checksum,
|
||||
pkg.TarGzip,
|
||||
)
|
||||
}
|
||||
|
||||
// newFromGitHubRelease is a helper for downloading release tarball from
|
||||
// Microsoft Github.
|
||||
func newFromGitHubRelease(
|
||||
suffix, tag, name, checksum string,
|
||||
compression uint32,
|
||||
) pkg.Artifact {
|
||||
return newTar(
|
||||
"https://github.com/"+suffix+
|
||||
"/releases/download/"+tag+"/"+name,
|
||||
checksum,
|
||||
compression,
|
||||
)
|
||||
}
|
||||
|
||||
// native contains natively-implemented and built-in azalea-based [Artifact].
|
||||
// It is generally recommended to clone this instance for custom [Artifact]
|
||||
// registrations.
|
||||
|
||||
Reference in New Issue
Block a user