Skip to content

Commit 646d945

Browse files
authored
chore: add comments to overlayed spec file for macro file and header (#408)
1 parent 3eb2d88 commit 646d945

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

internal/app/azldev/core/sources/sourceprep.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/gim-home/azldev-preview/internal/utils/fileperms"
2020
"github.com/gim-home/azldev-preview/internal/utils/fileutils"
2121
"github.com/samber/lo"
22+
"go.szostok.io/version"
2223
)
2324

2425
// MacrosFileExtension is the file extension used for azldev-generated macros files.
@@ -201,6 +202,9 @@ func (p *sourcePreparerImpl) postProcessSources(
201202
return fmt.Errorf("failed to compute macros load overlays:\n%w", err)
202203
}
203204

205+
// Get the file header overlay.
206+
headerOverlay := generateFileHeaderOverlay()
207+
204208
// Apply those overlays *first*, in sequence.
205209
for _, overlay := range macroOverlays {
206210
err = ApplyOverlayToSources(p.dryRunnable, p.fs, overlay, sourcesDirPath, absSpecPath)
@@ -220,6 +224,14 @@ func (p *sourcePreparerImpl) postProcessSources(
220224
}
221225
}
222226

227+
// Finally, apply the file header overlay.
228+
for _, overlay := range headerOverlay {
229+
err = ApplyOverlayToSources(p.dryRunnable, p.fs, overlay, sourcesDirPath, absSpecPath)
230+
if err != nil {
231+
return fmt.Errorf("failed to apply file header overlay to sources for component %#q:\n%w", component.GetName(), err)
232+
}
233+
}
234+
223235
return nil
224236
}
225237

@@ -240,7 +252,10 @@ func synthesizeMacroLoadOverlays(macrosFileName string) ([]projectconfig.Compone
240252
// Prepend the %{load:...} directive to the spec.
241253
Type: projectconfig.ComponentOverlayPrependSpecLines,
242254
Lines: []string{
255+
"# All Azure Linux specs with overlays include this macro file, irrespective of" +
256+
" whether new macros have been added.",
243257
fmt.Sprintf("%%{load:%%{_sourcedir}/%s}", macrosFileName),
258+
"",
244259
},
245260
},
246261
{
@@ -256,6 +271,23 @@ func synthesizeMacroLoadOverlays(macrosFileName string) ([]projectconfig.Compone
256271
}, nil
257272
}
258273

274+
// generateFileHeaderOverlay generates an overlay that prepends a header to the spec.
275+
// It should be applied after all other overlays, as it should be the first thing in the spec file.
276+
func generateFileHeaderOverlay() []projectconfig.ComponentOverlay {
277+
ver := version.Get()
278+
279+
return []projectconfig.ComponentOverlay{
280+
{
281+
Type: projectconfig.ComponentOverlayPrependSpecLines,
282+
Lines: []string{
283+
"# This spec file has been modified by azldev to include build configuration overlays. Version: " + ver.Version,
284+
"# Do not edit manually; changes may be overwritten.",
285+
"",
286+
},
287+
},
288+
}
289+
}
290+
259291
func findSpecInDir(
260292
fs opctx.FS, component components.Component, dirPath string,
261293
) (string, error) {

0 commit comments

Comments
 (0)