internal/pkg: pass impure job count
All checks were successful
Test / Create distribution (push) Successful in 1m6s
Test / Sandbox (push) Successful in 2m58s
Test / Hakurei (push) Successful in 3m56s
Test / ShareFS (push) Successful in 4m6s
Test / Sandbox (race detector) (push) Successful in 5m24s
Test / Hakurei (race detector) (push) Successful in 6m49s
Test / Flake checks (push) Successful in 1m27s
All checks were successful
Test / Create distribution (push) Successful in 1m6s
Test / Sandbox (push) Successful in 2m58s
Test / Hakurei (push) Successful in 3m56s
Test / ShareFS (push) Successful in 4m6s
Test / Sandbox (race detector) (push) Successful in 5m24s
Test / Hakurei (race detector) (push) Successful in 6m49s
Test / Flake checks (push) Successful in 1m27s
This is cleaner than checking cpu count during cure, it is impossible to avoid impurity in both situations but this is configurable. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -72,6 +72,7 @@ func main() {
|
|||||||
var (
|
var (
|
||||||
flagQuiet bool
|
flagQuiet bool
|
||||||
flagCures int
|
flagCures int
|
||||||
|
flagJobs int
|
||||||
flagBase string
|
flagBase string
|
||||||
flagIdle bool
|
flagIdle bool
|
||||||
|
|
||||||
@@ -99,7 +100,7 @@ func main() {
|
|||||||
if flagHostAbstract {
|
if flagHostAbstract {
|
||||||
flags |= pkg.CHostAbstract
|
flags |= pkg.CHostAbstract
|
||||||
}
|
}
|
||||||
cache, err = pkg.Open(ctx, msg, flags, flagCures, base)
|
cache, err = pkg.Open(ctx, msg, flags, flagCures, flagJobs, base)
|
||||||
|
|
||||||
return
|
return
|
||||||
}).Flag(
|
}).Flag(
|
||||||
@@ -110,6 +111,10 @@ func main() {
|
|||||||
&flagCures,
|
&flagCures,
|
||||||
"cures", command.IntFlag(0),
|
"cures", command.IntFlag(0),
|
||||||
"Maximum number of dependencies to cure at any given time",
|
"Maximum number of dependencies to cure at any given time",
|
||||||
|
).Flag(
|
||||||
|
&flagJobs,
|
||||||
|
"jobs", command.IntFlag(0),
|
||||||
|
"Preferred number of jobs to run, when applicable",
|
||||||
).Flag(
|
).Flag(
|
||||||
&flagBase,
|
&flagBase,
|
||||||
"d", command.StringFlag("$MBF_CACHE_DIR"),
|
"d", command.StringFlag("$MBF_CACHE_DIR"),
|
||||||
|
|||||||
@@ -188,6 +188,10 @@ func (c *common) Unwrap() context.Context { return c.cache.ctx }
|
|||||||
// GetMessage returns [message.Msg] held by the underlying [Cache].
|
// GetMessage returns [message.Msg] held by the underlying [Cache].
|
||||||
func (c *common) GetMessage() message.Msg { return c.cache.msg }
|
func (c *common) GetMessage() message.Msg { return c.cache.msg }
|
||||||
|
|
||||||
|
// GetJobs returns the preferred number of jobs to run, when applicable. Its
|
||||||
|
// value must not affect cure outcome.
|
||||||
|
func (c *common) GetJobs() int { return c.cache.jobs }
|
||||||
|
|
||||||
// GetWorkDir returns a pathname to a directory which [Artifact] is expected to
|
// GetWorkDir returns a pathname to a directory which [Artifact] is expected to
|
||||||
// write its output to. This is not the final resting place of the [Artifact]
|
// write its output to. This is not the final resting place of the [Artifact]
|
||||||
// and this pathname should not be directly referred to in the final contents.
|
// and this pathname should not be directly referred to in the final contents.
|
||||||
@@ -552,6 +556,8 @@ type Cache struct {
|
|||||||
base *check.Absolute
|
base *check.Absolute
|
||||||
// Immutable cure options set by [Open].
|
// Immutable cure options set by [Open].
|
||||||
flags int
|
flags int
|
||||||
|
// Immutable job count, when applicable.
|
||||||
|
jobs int
|
||||||
|
|
||||||
// Artifact to [unique.Handle] of identifier cache.
|
// Artifact to [unique.Handle] of identifier cache.
|
||||||
artifact sync.Map
|
artifact sync.Map
|
||||||
@@ -1818,7 +1824,7 @@ func (c *Cache) Close() {
|
|||||||
// caller-supplied value, however direct calls to [Cache.Cure] is not subject
|
// caller-supplied value, however direct calls to [Cache.Cure] is not subject
|
||||||
// to this limitation.
|
// to this limitation.
|
||||||
//
|
//
|
||||||
// A cures value of 0 or lower is equivalent to the value returned by
|
// A cures or jobs value of 0 or lower is equivalent to the value returned by
|
||||||
// [runtime.NumCPU].
|
// [runtime.NumCPU].
|
||||||
//
|
//
|
||||||
// A successful call to Open guarantees exclusive access to the on-filesystem
|
// A successful call to Open guarantees exclusive access to the on-filesystem
|
||||||
@@ -1828,10 +1834,10 @@ func (c *Cache) Close() {
|
|||||||
func Open(
|
func Open(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
msg message.Msg,
|
msg message.Msg,
|
||||||
flags, cures int,
|
flags, cures, jobs int,
|
||||||
base *check.Absolute,
|
base *check.Absolute,
|
||||||
) (*Cache, error) {
|
) (*Cache, error) {
|
||||||
return open(ctx, msg, flags, cures, base, true)
|
return open(ctx, msg, flags, cures, jobs, base, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// open implements Open but allows omitting the [lockedfile] lock when called
|
// open implements Open but allows omitting the [lockedfile] lock when called
|
||||||
@@ -1839,13 +1845,16 @@ func Open(
|
|||||||
func open(
|
func open(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
msg message.Msg,
|
msg message.Msg,
|
||||||
flags, cures int,
|
flags, cures, jobs int,
|
||||||
base *check.Absolute,
|
base *check.Absolute,
|
||||||
lock bool,
|
lock bool,
|
||||||
) (*Cache, error) {
|
) (*Cache, error) {
|
||||||
if cures < 1 {
|
if cures < 1 {
|
||||||
cures = runtime.NumCPU()
|
cures = runtime.NumCPU()
|
||||||
}
|
}
|
||||||
|
if jobs < 1 {
|
||||||
|
jobs = runtime.NumCPU()
|
||||||
|
}
|
||||||
|
|
||||||
for _, name := range []string{
|
for _, name := range []string{
|
||||||
dirIdentifier,
|
dirIdentifier,
|
||||||
@@ -1862,6 +1871,7 @@ func open(
|
|||||||
c := Cache{
|
c := Cache{
|
||||||
cures: make(chan struct{}, cures),
|
cures: make(chan struct{}, cures),
|
||||||
flags: flags,
|
flags: flags,
|
||||||
|
jobs: jobs,
|
||||||
|
|
||||||
msg: msg,
|
msg: msg,
|
||||||
base: base,
|
base: base,
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import (
|
|||||||
func unsafeOpen(
|
func unsafeOpen(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
msg message.Msg,
|
msg message.Msg,
|
||||||
flags, cures int,
|
flags, cures, jobs int,
|
||||||
base *check.Absolute,
|
base *check.Absolute,
|
||||||
lock bool,
|
lock bool,
|
||||||
) (*pkg.Cache, error)
|
) (*pkg.Cache, error)
|
||||||
@@ -230,7 +230,7 @@ func TestIdent(t *testing.T) {
|
|||||||
var cache *pkg.Cache
|
var cache *pkg.Cache
|
||||||
if a, err := check.NewAbs(t.TempDir()); err != nil {
|
if a, err := check.NewAbs(t.TempDir()); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if cache, err = pkg.Open(t.Context(), msg, 0, 0, a); err != nil {
|
} else if cache, err = pkg.Open(t.Context(), msg, 0, 0, 0, a); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
t.Cleanup(cache.Close)
|
t.Cleanup(cache.Close)
|
||||||
@@ -304,7 +304,7 @@ func checkWithCache(t *testing.T, testCases []cacheTestCase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var scrubFunc func() error // scrub after hashing
|
var scrubFunc func() error // scrub after hashing
|
||||||
if c, err := pkg.Open(t.Context(), msg, flags, 1<<4, base); err != nil {
|
if c, err := pkg.Open(t.Context(), msg, flags, 1<<4, 0, base); err != nil {
|
||||||
t.Fatalf("Open: error = %v", err)
|
t.Fatalf("Open: error = %v", err)
|
||||||
} else {
|
} else {
|
||||||
t.Cleanup(c.Close)
|
t.Cleanup(c.Close)
|
||||||
@@ -606,7 +606,7 @@ func TestCache(t *testing.T) {
|
|||||||
if c0, err := unsafeOpen(
|
if c0, err := unsafeOpen(
|
||||||
t.Context(),
|
t.Context(),
|
||||||
message.New(nil),
|
message.New(nil),
|
||||||
0, 0, base, false,
|
0, 0, 0, base, false,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
t.Fatalf("open: error = %v", err)
|
t.Fatalf("open: error = %v", err)
|
||||||
} else {
|
} else {
|
||||||
@@ -1263,7 +1263,7 @@ func TestNew(t *testing.T) {
|
|||||||
if _, err := pkg.Open(
|
if _, err := pkg.Open(
|
||||||
t.Context(),
|
t.Context(),
|
||||||
message.New(nil),
|
message.New(nil),
|
||||||
0, 0, check.MustAbs(container.Nonexistent),
|
0, 0, 0, check.MustAbs(container.Nonexistent),
|
||||||
); !reflect.DeepEqual(err, wantErr) {
|
); !reflect.DeepEqual(err, wantErr) {
|
||||||
t.Errorf("Open: error = %#v, want %#v", err, wantErr)
|
t.Errorf("Open: error = %#v, want %#v", err, wantErr)
|
||||||
}
|
}
|
||||||
@@ -1291,7 +1291,7 @@ func TestNew(t *testing.T) {
|
|||||||
if _, err := pkg.Open(
|
if _, err := pkg.Open(
|
||||||
t.Context(),
|
t.Context(),
|
||||||
message.New(nil),
|
message.New(nil),
|
||||||
0, 0, tempDir.Append("cache"),
|
0, 0, 0, tempDir.Append("cache"),
|
||||||
); !reflect.DeepEqual(err, wantErr) {
|
); !reflect.DeepEqual(err, wantErr) {
|
||||||
t.Errorf("Open: error = %#v, want %#v", err, wantErr)
|
t.Errorf("Open: error = %#v, want %#v", err, wantErr)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func getCache(t *testing.T) *pkg.Cache {
|
|||||||
msg := message.New(log.New(os.Stderr, "rosa: ", 0))
|
msg := message.New(log.New(os.Stderr, "rosa: ", 0))
|
||||||
msg.SwapVerbose(true)
|
msg.SwapVerbose(true)
|
||||||
|
|
||||||
if buildTestCache, err = pkg.Open(ctx, msg, 0, 0, a); err != nil {
|
if buildTestCache, err = pkg.Open(ctx, msg, 0, 0, 0, a); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user