hcl2template: remove unused shouldContinue bool

Not sure why this was defined and returned, but the value was set, but
never used, as such this is not useful to keep in the code, so let's
simplify this now.
backport_use_squash
Lucas Bajolet 3 years ago committed by Lucas Bajolet
parent 8dcc6b9fd9
commit 8438d81d4d

@ -380,7 +380,7 @@ func (cfg *PackerConfig) evaluateDatasources(skipExecution bool) hcl.Diagnostics
// Now that most of our data sources have been started and executed, we can // Now that most of our data sources have been started and executed, we can
// try to execute the ones that depend on other data sources. // try to execute the ones that depend on other data sources.
for ref := range dependencies { for ref := range dependencies {
_, moreDiags, _ := cfg.recursivelyEvaluateDatasources(ref, dependencies, skipExecution, 0) _, moreDiags := cfg.recursivelyEvaluateDatasources(ref, dependencies, skipExecution, 0)
// Deduplicate diagnostics to prevent recursion messes. // Deduplicate diagnostics to prevent recursion messes.
cleanedDiags := map[string]*hcl.Diagnostic{} cleanedDiags := map[string]*hcl.Diagnostic{}
for _, diag := range moreDiags { for _, diag := range moreDiags {
@ -395,10 +395,9 @@ func (cfg *PackerConfig) evaluateDatasources(skipExecution bool) hcl.Diagnostics
return diags return diags
} }
func (cfg *PackerConfig) recursivelyEvaluateDatasources(ref DatasourceRef, dependencies map[DatasourceRef][]DatasourceRef, skipExecution bool, depth int) (map[DatasourceRef][]DatasourceRef, hcl.Diagnostics, bool) { func (cfg *PackerConfig) recursivelyEvaluateDatasources(ref DatasourceRef, dependencies map[DatasourceRef][]DatasourceRef, skipExecution bool, depth int) (map[DatasourceRef][]DatasourceRef, hcl.Diagnostics) {
var diags hcl.Diagnostics var diags hcl.Diagnostics
var moreDiags hcl.Diagnostics var moreDiags hcl.Diagnostics
shouldContinue := true
if depth > 10 { if depth > 10 {
// Add a comment about recursion. // Add a comment about recursion.
@ -410,7 +409,7 @@ func (cfg *PackerConfig) recursivelyEvaluateDatasources(ref DatasourceRef, depen
"other data sources, or your data sources have a cyclic " + "other data sources, or your data sources have a cyclic " +
"dependency. Please simplify your config to continue. ", "dependency. Please simplify your config to continue. ",
}) })
return dependencies, diags, false return dependencies, diags
} }
ds := cfg.Datasources[ref] ds := cfg.Datasources[ref]
@ -421,11 +420,11 @@ func (cfg *PackerConfig) recursivelyEvaluateDatasources(ref DatasourceRef, depen
// If this dependency is not in the map, it means we've already // If this dependency is not in the map, it means we've already
// launched and executed this datasource. Otherwise, it means // launched and executed this datasource. Otherwise, it means
// we still need to run it. RECURSION TIME!! // we still need to run it. RECURSION TIME!!
dependencies, moreDiags, shouldContinue = cfg.recursivelyEvaluateDatasources(dep, dependencies, skipExecution, depth) dependencies, moreDiags = cfg.recursivelyEvaluateDatasources(dep, dependencies, skipExecution, depth)
diags = append(diags, moreDiags...) diags = append(diags, moreDiags...)
if moreDiags.HasErrors() { if moreDiags.HasErrors() {
diags = append(diags, moreDiags...) diags = append(diags, moreDiags...)
return dependencies, diags, shouldContinue return dependencies, diags
} }
} }
} }
@ -435,14 +434,14 @@ func (cfg *PackerConfig) recursivelyEvaluateDatasources(ref DatasourceRef, depen
datasource, startDiags := cfg.startDatasource(cfg.parser.PluginConfig.DataSources, ref, true) datasource, startDiags := cfg.startDatasource(cfg.parser.PluginConfig.DataSources, ref, true)
if startDiags.HasErrors() { if startDiags.HasErrors() {
diags = append(diags, startDiags...) diags = append(diags, startDiags...)
return dependencies, diags, shouldContinue return dependencies, diags
} }
if skipExecution { if skipExecution {
placeholderValue := cty.UnknownVal(hcldec.ImpliedType(datasource.OutputSpec())) placeholderValue := cty.UnknownVal(hcldec.ImpliedType(datasource.OutputSpec()))
ds.value = placeholderValue ds.value = placeholderValue
cfg.Datasources[ref] = ds cfg.Datasources[ref] = ds
return dependencies, diags, shouldContinue return dependencies, diags
} }
opts, _ := decodeHCL2Spec(ds.block.Body, cfg.EvalContext(DatasourceContext, nil), datasource) opts, _ := decodeHCL2Spec(ds.block.Body, cfg.EvalContext(DatasourceContext, nil), datasource)
@ -455,14 +454,14 @@ func (cfg *PackerConfig) recursivelyEvaluateDatasources(ref DatasourceRef, depen
Subject: &cfg.Datasources[ref].block.DefRange, Subject: &cfg.Datasources[ref].block.DefRange,
Severity: hcl.DiagError, Severity: hcl.DiagError,
}) })
return dependencies, diags, shouldContinue return dependencies, diags
} }
ds.value = realValue ds.value = realValue
cfg.Datasources[ref] = ds cfg.Datasources[ref] = ds
// remove ref from the dependencies map. // remove ref from the dependencies map.
delete(dependencies, ref) delete(dependencies, ref)
return dependencies, diags, shouldContinue return dependencies, diags
} }
// getCoreBuildProvisioners takes a list of provisioner block, starts according // getCoreBuildProvisioners takes a list of provisioner block, starts according

Loading…
Cancel
Save