All checks were successful
Test / Create distribution (push) Successful in 1m6s
Test / Sandbox (push) Successful in 2m46s
Test / ShareFS (push) Successful in 3m47s
Test / Hakurei (push) Successful in 3m52s
Test / Sandbox (race detector) (push) Successful in 5m20s
Test / Hakurei (race detector) (push) Successful in 6m29s
Test / Flake checks (push) Successful in 1m23s
This also migrates LLVM LIT via the newly implemented special case. Signed-off-by: Ophestra <cat@gensokyo.uk>
122 lines
2.8 KiB
Go
122 lines
2.8 KiB
Go
package rosa
|
|
|
|
import (
|
|
"slices"
|
|
|
|
"hakurei.app/internal/pkg"
|
|
)
|
|
|
|
// Python is the python interpreter used by [PipHelper].
|
|
var Python = H("python")
|
|
|
|
// PipHelper is the [Python] pip packaging helper.
|
|
type PipHelper struct {
|
|
// Path elements joined with source.
|
|
Append []string
|
|
// Whether to omit --no-build-isolation.
|
|
BuildIsolation bool
|
|
// Whether to enter source after install.
|
|
EnterSource bool
|
|
// Whether to install to build environment after install.
|
|
Install bool
|
|
// Whether to skip running tests.
|
|
SkipCheck bool
|
|
// Replaces pytest if non-empty.
|
|
Check string
|
|
// Runs after install.
|
|
Script string
|
|
}
|
|
|
|
var _ Helper = new(PipHelper)
|
|
|
|
// extra returns python, or pytest if defaults are assumed.
|
|
func (attr *PipHelper) extra(int) P {
|
|
if attr == nil || (!attr.SkipCheck && attr.Check == "") {
|
|
return P{PythonPyTest}
|
|
}
|
|
return P{Python}
|
|
}
|
|
|
|
// wantsChmod returns true.
|
|
func (*PipHelper) wantsChmod() bool { return true }
|
|
|
|
// wantsWrite is equivalent to wantsChmod.
|
|
func (attr *PipHelper) wantsWrite() bool { return attr.wantsChmod() }
|
|
|
|
// scriptEarly is a noop.
|
|
func (*PipHelper) scriptEarly() string { return "" }
|
|
|
|
// createDir returns false.
|
|
func (*PipHelper) createDir() bool { return false }
|
|
|
|
// wantsDir requests a new directory in TMPDIR.
|
|
func (*PipHelper) wantsDir() string { return `"$(mktemp -d)"` }
|
|
|
|
// script generates the pip3 install command.
|
|
func (attr *PipHelper) script(_ Toolchain, name string) string {
|
|
if attr == nil {
|
|
attr = new(PipHelper)
|
|
}
|
|
sourcePath := AbsUsrSrc.Append(name).Append(attr.Append...)
|
|
|
|
var extra string
|
|
if !attr.BuildIsolation {
|
|
extra += `
|
|
--no-build-isolation \`
|
|
}
|
|
|
|
var script string
|
|
if attr.Install {
|
|
script += `pip3 install \
|
|
--no-index \
|
|
--prefix=/system \
|
|
--no-build-isolation \
|
|
'` + sourcePath.String() + `'
|
|
`
|
|
}
|
|
if attr.EnterSource {
|
|
script += "cd '/usr/src/" + name + "'\n"
|
|
}
|
|
if !attr.SkipCheck {
|
|
if attr.Check == "" {
|
|
// some test suites fall apart when ran out-of-tree
|
|
script += "(cd '" + sourcePath.String() + "' && pytest)\n"
|
|
} else {
|
|
script += attr.Check
|
|
}
|
|
}
|
|
script += attr.Script
|
|
|
|
return `
|
|
pip3 install \
|
|
--no-index \
|
|
--prefix=/system \
|
|
--root=/work \` + extra + `
|
|
'` + sourcePath.String() + `'
|
|
` + script
|
|
}
|
|
|
|
// newPythonPackage registers a new [Python] package.
|
|
func (s *S) newPythonPackage(
|
|
name string, id int, description, website, version string,
|
|
source pkg.Artifact, attrP *PackageAttr, attr *PipHelper,
|
|
build P, extra ...ArtifactH,
|
|
) {
|
|
name = "python-" + name
|
|
s.MustRegister(name, func(t Toolchain) (*Metadata, pkg.Artifact) {
|
|
return &Metadata{
|
|
Name: name,
|
|
Description: description,
|
|
Website: website,
|
|
Version: version,
|
|
|
|
Dependencies: slices.Concat(P{Python}, extra),
|
|
|
|
ID: id,
|
|
}, t.NewPackage(name, version, source, attrP, attr, slices.Concat(
|
|
extra,
|
|
build,
|
|
)...)
|
|
})
|
|
}
|