From 7c2ebdef75c0247c0c44543cde1e0d6ecabd956a Mon Sep 17 00:00:00 2001 From: LaMont Jones Date: Tue, 11 Jul 2023 19:58:01 +0000 Subject: [PATCH] Wrap singleton ninjaString Eval calls This avoids a concurrent map read and write error in parallel singletons. Bug: 290795374 Test: manual, treehugger Change-Id: I7f89909a98c4f530da92a3d2cc01ca8eaeddbfa0 --- live_tracker.go | 6 ++++++ singleton_ctx.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/live_tracker.go b/live_tracker.go index e2c4057..e62dc59 100644 --- a/live_tracker.go +++ b/live_tracker.go @@ -229,6 +229,12 @@ func (l *liveTracker) innerAddNinjaStringDeps(str *ninjaString) error { return nil } +func (l *liveTracker) Eval(n *ninjaString) (string, error) { + l.Lock() + defer l.Unlock() + return n.Eval(l.variables) +} + func (l *liveTracker) RemoveVariableIfLive(v Variable) bool { l.Lock() defer l.Unlock() diff --git a/singleton_ctx.go b/singleton_ctx.go index 95c29c4..176aa25 100644 --- a/singleton_ctx.go +++ b/singleton_ctx.go @@ -289,7 +289,7 @@ func (s *singletonContext) Eval(pctx PackageContext, str string) (string, error) return "", err } - return ninjaStr.Eval(s.globals.variables) + return s.globals.Eval(ninjaStr) } func (s *singletonContext) RequireNinjaVersion(major, minor, micro int) {