forked from rosa/hakurei
internal/pkg: collection helper-artifact
This was moved from internal/rosa because it is considered generally useful. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -527,7 +527,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
presets[i] = p
|
presets[i] = p
|
||||||
}
|
}
|
||||||
root := make(rosa.Collect, 0, 6+len(args))
|
root := make(pkg.Collect, 0, 6+len(args))
|
||||||
root = rosa.Std.AppendPresets(root, presets...)
|
root = rosa.Std.AppendPresets(root, presets...)
|
||||||
|
|
||||||
if flagWithToolchain {
|
if flagWithToolchain {
|
||||||
@@ -543,7 +543,7 @@ func main() {
|
|||||||
|
|
||||||
if _, _, err := cache.Cure(&root); err == nil {
|
if _, _, err := cache.Cure(&root); err == nil {
|
||||||
return errors.New("unreachable")
|
return errors.New("unreachable")
|
||||||
} else if !errors.Is(err, rosa.Collected{}) {
|
} else if !pkg.IsCollected(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ type TrivialArtifact interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// KnownIdent is optionally implemented by [Artifact] and is used instead of
|
// KnownIdent is optionally implemented by [Artifact] and is used instead of
|
||||||
// [Kind.Ident] when it is available.
|
// [Cache.Ident] when it is available.
|
||||||
//
|
//
|
||||||
// This is very subtle to use correctly. The implementation must ensure that
|
// This is very subtle to use correctly. The implementation must ensure that
|
||||||
// this value is globally unique, otherwise [Cache] can enter an inconsistent
|
// this value is globally unique, otherwise [Cache] can enter an inconsistent
|
||||||
@@ -439,6 +439,11 @@ const (
|
|||||||
KindCustomOffset = 1 << 31
|
KindCustomOffset = 1 << 31
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// kindCollection is the kind of [Collect]. It never cures successfully.
|
||||||
|
kindCollection Kind = KindCustomOffset - 1 - iota
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// fileLock is the file name appended to Cache.base for guaranteeing
|
// fileLock is the file name appended to Cache.base for guaranteeing
|
||||||
// exclusive access to the cache directory.
|
// exclusive access to the cache directory.
|
||||||
@@ -1890,3 +1895,33 @@ func open(
|
|||||||
|
|
||||||
return &c, nil
|
return &c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collected is returned by [Collect.Cure] to indicate a successful collection.
|
||||||
|
type Collected struct{}
|
||||||
|
|
||||||
|
// Error returns a constant string to satisfy error, but should never be seen
|
||||||
|
// by the user.
|
||||||
|
func (Collected) Error() string { return "artifacts successfully collected" }
|
||||||
|
|
||||||
|
// IsCollected returns whether the underlying error contains that of the result
|
||||||
|
// of curing a [Collect] helper.
|
||||||
|
func IsCollected(err error) bool { return errors.As(err, new(Collected)) }
|
||||||
|
|
||||||
|
// Collect implements [pkg.FloodArtifact] to concurrently cure multiple
|
||||||
|
// [pkg.Artifact]. It returns [Collected].
|
||||||
|
type Collect []Artifact
|
||||||
|
|
||||||
|
// Cure returns [Collected].
|
||||||
|
func (*Collect) Cure(*FContext) error { return Collected{} }
|
||||||
|
|
||||||
|
// Kind returns the hardcoded [pkg.Kind] value.
|
||||||
|
func (*Collect) Kind() Kind { return kindCollection }
|
||||||
|
|
||||||
|
// Params is a noop: dependencies are already represented in the header.
|
||||||
|
func (*Collect) Params(*IContext) {}
|
||||||
|
|
||||||
|
// Dependencies returns [Collect] as is.
|
||||||
|
func (c *Collect) Dependencies() []Artifact { return *c }
|
||||||
|
|
||||||
|
// IsExclusive returns false: Cure is a noop.
|
||||||
|
func (*Collect) IsExclusive() bool { return false }
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ const (
|
|||||||
|
|
||||||
// kindBusyboxBin is the kind of [pkg.Artifact] of busyboxBin.
|
// kindBusyboxBin is the kind of [pkg.Artifact] of busyboxBin.
|
||||||
kindBusyboxBin
|
kindBusyboxBin
|
||||||
|
|
||||||
// kindCollection is the kind of [Collect]. It never cures successfully.
|
|
||||||
kindCollection
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// mustDecode is like [pkg.MustDecode], but replaces the zero value and prints
|
// mustDecode is like [pkg.MustDecode], but replaces the zero value and prints
|
||||||
@@ -591,29 +588,3 @@ cd '/usr/src/` + name + `/'
|
|||||||
})...,
|
})...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collected is returned by [Collect.Cure] to indicate a successful collection.
|
|
||||||
type Collected struct{}
|
|
||||||
|
|
||||||
// Error returns a constant string to satisfy error, but should never be seen
|
|
||||||
// by the user.
|
|
||||||
func (Collected) Error() string { return "artifacts successfully collected" }
|
|
||||||
|
|
||||||
// Collect implements [pkg.FloodArtifact] to concurrently cure multiple
|
|
||||||
// [pkg.Artifact]. It returns [Collected].
|
|
||||||
type Collect []pkg.Artifact
|
|
||||||
|
|
||||||
// Cure returns [Collected].
|
|
||||||
func (*Collect) Cure(*pkg.FContext) error { return Collected{} }
|
|
||||||
|
|
||||||
// Kind returns the hardcoded [pkg.Kind] value.
|
|
||||||
func (*Collect) Kind() pkg.Kind { return kindCollection }
|
|
||||||
|
|
||||||
// Params does not write anything, dependencies are already represented in the header.
|
|
||||||
func (*Collect) Params(*pkg.IContext) {}
|
|
||||||
|
|
||||||
// Dependencies returns [Collect] as is.
|
|
||||||
func (c *Collect) Dependencies() []pkg.Artifact { return *c }
|
|
||||||
|
|
||||||
// IsExclusive returns false: Cure is a noop.
|
|
||||||
func (*Collect) IsExclusive() bool { return false }
|
|
||||||
|
|||||||
Reference in New Issue
Block a user