aboutsummaryrefslogtreecommitdiffhomepage
path: root/deps
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2020-02-25 21:40:02 +0100
committerBjørn Erik Pedersen <[email protected]>2020-04-07 21:59:20 +0200
commit2f721f8ec69c52202815cd1b543ca4bf535c0901 (patch)
treecae7d1ee9ce867a4bffc70e94513f09e2aebe162 /deps
parent8568928aa8e82a6bd7de4555c3703d8835fbd25b (diff)
downloadhugo-2f721f8ec69c52202815cd1b543ca4bf535c0901.tar.gz
hugo-2f721f8ec69c52202815cd1b543ca4bf535c0901.zip
Add basic "post resource publish support"
Fixes #7146
Diffstat (limited to 'deps')
-rw-r--r--deps/deps.go26
-rw-r--r--deps/deps_test.go10
2 files changed, 27 insertions, 9 deletions
diff --git a/deps/deps.go b/deps/deps.go
index e482b2df7..82a16ba59 100644
--- a/deps/deps.go
+++ b/deps/deps.go
@@ -2,6 +2,7 @@ package deps
import (
"sync"
+ "sync/atomic"
"time"
"github.com/pkg/errors"
@@ -92,8 +93,9 @@ type Deps struct {
// BuildStartListeners will be notified before a build starts.
BuildStartListeners *Listeners
- // Atomic flags set during a build.
- BuildFlags *BuildFlags
+ // Atomic values set during a build.
+ // This is common/global for all sites.
+ BuildState *BuildState
*globalErrHandler
}
@@ -236,8 +238,9 @@ func New(cfg DepsCfg) (*Deps, error) {
}
errorHandler := &globalErrHandler{}
+ buildState := &BuildState{}
- resourceSpec, err := resources.NewSpec(ps, fileCaches, logger, errorHandler, cfg.OutputFormats, cfg.MediaTypes)
+ resourceSpec, err := resources.NewSpec(ps, fileCaches, buildState, logger, errorHandler, cfg.OutputFormats, cfg.MediaTypes)
if err != nil {
return nil, err
}
@@ -275,7 +278,7 @@ func New(cfg DepsCfg) (*Deps, error) {
Site: cfg.Site,
FileCaches: fileCaches,
BuildStartListeners: &Listeners{},
- BuildFlags: &BuildFlags{},
+ BuildState: buildState,
Timeout: time.Duration(timeoutms) * time.Millisecond,
globalErrHandler: errorHandler,
}
@@ -308,7 +311,7 @@ func (d Deps) ForLanguage(cfg DepsCfg, onCreated func(d *Deps) error) (*Deps, er
// The resource cache is global so reuse.
// TODO(bep) clean up these inits.
resourceCache := d.ResourceSpec.ResourceCache
- d.ResourceSpec, err = resources.NewSpec(d.PathSpec, d.ResourceSpec.FileCaches, d.Log, d.globalErrHandler, cfg.OutputFormats, cfg.MediaTypes)
+ d.ResourceSpec, err = resources.NewSpec(d.PathSpec, d.ResourceSpec.FileCaches, d.BuildState, d.Log, d.globalErrHandler, cfg.OutputFormats, cfg.MediaTypes)
if err != nil {
return nil, err
}
@@ -376,10 +379,15 @@ type DepsCfg struct {
Running bool
}
-// BuildFlags are flags that may be turned on during a build.
-type BuildFlags struct {
+// BuildState are flags that may be turned on during a build.
+type BuildState struct {
+ counter uint64
}
-func NewBuildFlags() BuildFlags {
- return BuildFlags{}
+func (b *BuildState) Incr() int {
+ return int(atomic.AddUint64(&b.counter, uint64(1)))
+}
+
+func NewBuildState() BuildState {
+ return BuildState{}
}
diff --git a/deps/deps_test.go b/deps/deps_test.go
index a7450a41c..5c58ed7a3 100644
--- a/deps/deps_test.go
+++ b/deps/deps_test.go
@@ -15,8 +15,18 @@ package deps
import (
"testing"
+
+ qt "github.com/frankban/quicktest"
)
func TestBuildFlags(t *testing.T) {
+ c := qt.New(t)
+ var bf BuildState
+ bf.Incr()
+ bf.Incr()
+ bf.Incr()
+
+ c.Assert(bf.Incr(), qt.Equals, 4)
+
}