internal/rosa: IR-curable source override
All checks were successful
Test / Hakurei (push) Successful in 4m16s
Test / Hakurei (race detector) (push) Successful in 6m40s
Test / Create distribution (push) Successful in 1m4s
Test / Sandbox (push) Successful in 1m54s
Test / ShareFS (push) Successful in 2m36s
Test / Sandbox (race detector) (push) Successful in 2m41s
Test / Flake checks (push) Successful in 1m18s
All checks were successful
Test / Hakurei (push) Successful in 4m16s
Test / Hakurei (race detector) (push) Successful in 6m40s
Test / Create distribution (push) Successful in 1m4s
Test / Sandbox (push) Successful in 1m54s
Test / ShareFS (push) Successful in 2m36s
Test / Sandbox (race detector) (push) Successful in 2m41s
Test / Flake checks (push) Successful in 1m18s
This creates a tarball in-memory for overriding hakurei-source. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package rosa
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -1173,6 +1176,90 @@ func (s *S) RegisterFS(fsys fs.FS) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetSource overrides the hakurei-source package with a cached tarball of fsys.
|
||||
// The resulting IR is curable on the daemon. Must not be used concurrently with
|
||||
// any other method.
|
||||
func (s *S) SetSource(fsys fs.FS) error {
|
||||
var buf bytes.Buffer
|
||||
w, err := gzip.NewWriterLevel(&buf, gzip.BestSpeed)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tw := tar.NewWriter(w)
|
||||
|
||||
if err = fs.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if d.IsDir() && d.Name() == ".git" {
|
||||
return fs.SkipDir
|
||||
}
|
||||
|
||||
var fi fs.FileInfo
|
||||
if fi, err = d.Info(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var linkname string
|
||||
if fi.Mode()&fs.ModeSymlink != 0 {
|
||||
if linkname, err = fs.ReadLink(fsys, path); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var h *tar.Header
|
||||
if h, err = tar.FileInfoHeader(fi, linkname); err != nil {
|
||||
return err
|
||||
}
|
||||
h.Name = path
|
||||
|
||||
if err = tw.WriteHeader(h); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if fi.Mode().IsRegular() {
|
||||
var f io.ReadCloser
|
||||
if f, err = fsys.Open(path); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.Copy(tw, f)
|
||||
if _err := f.Close(); err == nil {
|
||||
err = _err
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = tw.Close(); err != nil {
|
||||
return err
|
||||
} else if err = w.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
const name = "hakurei-source"
|
||||
a := pkg.NewFile("hakurei-src-current.tar.gz", buf.Bytes())
|
||||
s.artifacts.Store(
|
||||
H(name),
|
||||
Artifact(func(t Toolchain) (*Metadata, pkg.Artifact) {
|
||||
return &Metadata{
|
||||
Name: name,
|
||||
Description: "hakurei source tree (current)",
|
||||
Version: "1.0.0-CURRENT",
|
||||
Exclude: true,
|
||||
}, pkg.NewTar(a, pkg.TarGzip)
|
||||
}),
|
||||
)
|
||||
s.DropCaches(s.Arch(), s.Flags())
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetGentooStage3 sets the Gentoo stage3 tarball url and checksum. It panics
|
||||
// if given zero values or if these values have already been set.
|
||||
func (s *S) SetGentooStage3(url string, checksum pkg.Checksum) {
|
||||
|
||||
Reference in New Issue
Block a user