Skip to content

feat(spec): preserve referenced macros during removal - #334

Open
Thien Trung Vuong (trungams) wants to merge 1 commit into
tvuong/structural-spec-editor-implementationfrom
tvuong/structural-spec-editor-macro-preservation
Open

feat(spec): preserve referenced macros during removal#334
Thien Trung Vuong (trungams) wants to merge 1 commit into
tvuong/structural-spec-editor-implementationfrom
tvuong/structural-spec-editor-macro-preservation

Conversation

@trungams

@trungams Thien Trung Vuong (trungams) commented Sep 2, 2026

Copy link
Copy Markdown
Member

Summary

Removing a section or subpackage can also remove %define or %global declarations that happen to live inside it. When surviving content still references one of those macros, the rendered spec is left with a dangling reference and often fails much later during the build.

This PR teaches the structural editor to preserve the complete declarations that surviving content still needs. It follows transitive dependencies and keeps declaration ordering intact. When a relocation is ambiguous or clearly unsafe, the removal fails without modifying the spec.

Motivation

Issue #203 documents this with QEMU: %define testsdir lives in the tests subpackage, but %install continues to use it after that subpackage is removed. The macro declaration must survive even though the package sections do not.

Changes

  • Select removed macro declarations referenced by surviving content.
  • Follow transitive dependencies at the relevant use order.
  • Preserve complete multiline declarations and original declaration order.
  • Scan section-header arguments while excluding the section marker itself.
  • Avoid duplicate hoists when a safe surviving definition already supplies the binding.
  • Log automatic macro preservation.
  • Reject unsafe cases with ErrUnsafeMacroHoist without modifying the spec, including:
    • ambiguous conditional declarations;
    • unsafe eager %global dependencies or redefinitions;
    • selected dynamic macro names;
    • self-referential selected %global declarations;
    • incompatible same-name bindings.
  • Add QEMU-shaped spec-remove-subpackage drops %define macros inside the removed subpackage that are referenced elsewhere #203 coverage and focused rejection tests.

Validation

  • mage build
  • mage unit

The completed structural editor also rendered the full Azure Linux evaluation corpus without parser or overlay errors, including automatic preservation of QEMU's testsdir macro.

Known limitations

This is conservative structural and lexical analysis, not RPM macro evaluation. If azldev cannot establish a safe binding, it rejects the removal instead of guessing. Conditional same-name bindings that would require evaluating the condition remain best-effort.

@trungams
Thien Trung Vuong (trungams) force-pushed the tvuong/structural-spec-editor-macro-preservation branch from 4a298a0 to 740f791 Compare September 2, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant