forked from rosa/hakurei
internal/rosa: read overridden version string from source
This is more correct than the hardcoded string and is generally more robust against relative paths. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
+12
-1
@@ -7,6 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"iter"
|
"iter"
|
||||||
@@ -1255,6 +1256,16 @@ func (s *S) RegisterFS(fsys fs.FS) error {
|
|||||||
// The resulting IR is curable on the daemon. Must not be used concurrently with
|
// The resulting IR is curable on the daemon. Must not be used concurrently with
|
||||||
// any other method.
|
// any other method.
|
||||||
func (s *S) SetSource(fsys fs.FS) error {
|
func (s *S) SetSource(fsys fs.FS) error {
|
||||||
|
var version string
|
||||||
|
if p, err := fs.ReadFile(fsys, "cmd/dist/VERSION"); err != nil {
|
||||||
|
return err
|
||||||
|
} else if len(p) < 2 {
|
||||||
|
return fmt.Errorf("invalid version string %q", string(p))
|
||||||
|
} else {
|
||||||
|
version = unsafe.String(unsafe.SliceData(p), len(p))
|
||||||
|
}
|
||||||
|
version = version[1:len(version)-1] + "-CURRENT"
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
w, err := gzip.NewWriterLevel(&buf, gzip.BestSpeed)
|
w, err := gzip.NewWriterLevel(&buf, gzip.BestSpeed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1326,7 +1337,7 @@ func (s *S) SetSource(fsys fs.FS) error {
|
|||||||
return &Metadata{
|
return &Metadata{
|
||||||
Name: name,
|
Name: name,
|
||||||
Description: "hakurei source tree (current)",
|
Description: "hakurei source tree (current)",
|
||||||
Version: "1.0.0-CURRENT",
|
Version: version,
|
||||||
Exclude: true,
|
Exclude: true,
|
||||||
}, pkg.NewTar(pkg.NewDecompress(a, pkg.Gzip))
|
}, pkg.NewTar(pkg.NewDecompress(a, pkg.Gzip))
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user