From 1b5e9aba43986bc0734c97cc82ac83bc22879a57 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Tue, 13 Jun 2023 01:12:12 +0000 Subject: [PATCH] Make skip-cloning blueprint option public This allows non-test integrations to set this mode. Test: Treehugger Change-Id: I4c69be30bd9ac917113ee8e4d0425dd40753f66f --- context.go | 12 +++++++++--- provider_test.go | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/context.go b/context.go index d5f0e41..dac1ed2 100644 --- a/context.go +++ b/context.go @@ -137,8 +137,12 @@ type Context struct { // True for any mutators that have already run over all modules finishedMutators map[*mutatorInfo]bool - // Can be set by tests to avoid invalidating Module values after mutators. - skipCloneModulesAfterMutators bool + // If true, RunBlueprint will skip cloning modules at the end of RunBlueprint. + // Cloning modules intentionally invalidates some Module values after + // mutators run (to ensure that mutators don't set such Module values in a way + // which ruins the integrity of the graph). However, keeping Module values + // changed by mutators may be a desirable outcome (such as for tooling or tests). + SkipCloneModulesAfterMutators bool // String values that can be used to gate build graph traversal includeTags *IncludeTags @@ -1983,9 +1987,11 @@ func (c *Context) resolveDependencies(ctx context.Context, config interface{}) ( } deps = append(deps, mutatorDeps...) - if !c.skipCloneModulesAfterMutators { + c.BeginEvent("clone_modules") + if !c.SkipCloneModulesAfterMutators { c.cloneModules() } + defer c.EndEvent("clone_modules") c.dependenciesReady = true }) diff --git a/provider_test.go b/provider_test.go index 942dd31..4038eae 100644 --- a/provider_test.go +++ b/provider_test.go @@ -283,7 +283,7 @@ func TestInvalidProvidersUsage(t *testing.T) { ctx.RegisterTopDownMutator("parent", invalidProviderUsageParentMutator) // Don't invalidate the parent pointer and before GenerateBuildActions. - ctx.skipCloneModulesAfterMutators = true + ctx.SkipCloneModulesAfterMutators = true var parentBP, moduleUnderTestBP, childBP string