Skip to content

Generate language-specific compile macro files - #503

Merged
brondani merged 3 commits into
mainfrom
generate-language-specific-compile
Jul 21, 2026
Merged

Generate language-specific compile macro files#503
brondani merged 3 commits into
mainfrom
generate-language-specific-compile

Conversation

@brondani

@brondani brondani commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Fixes

Depends on Open-CMSIS-Pack/devtools#2530

Changes

  • Ensures compile macro dumps use the appropriate C or C++ preprocessing mode and compiler options.
  • Pass -xc or -xc++, or --c++ in case of IAR, plus language-specific and common compiler options to macro dump commands.
  • Update unit coverage and generated CMake reference fixtures across supported toolchains.
  • Generating separate compile_macros_c.h and compile_macros_cxx.h files for enabled C and C++ languages has several advantages over a single-file approach:
    • Each file is a direct dump from the compiler preprocessor for one language mode.
    • No merging, comparison, filtering, or semantic transformation is required.
    • C and C++ differences are preserved exactly as reported by the compiler.
    • The consumer selects the file through the translation unit’s language, not through logic inside the generated file.
    • It avoids relying on any macro/define before the generated macro environment has been established.

Risk / limitations

  • The previous shared compile_macros.h output is replaced by language-specific files, which may affect consumers relying on that filename.
  • Macro generation remains limited to C and C++.

Checklist

  • 🤖 This change is covered by unit tests (if applicable).
  • 🤹 Manual testing has been performed (if necessary).
  • 🛡️ Security impacts have been considered (if relevant).
  • 📖 Documentation updates are complete (if required).
  • 🧠 Third-party dependencies and TPIP updated (if required).

@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@qltysh

qltysh Bot commented Jul 20, 2026

Copy link
Copy Markdown

Qlty


Coverage Impact

⬆️ Merging this pull request will increase total coverage on main by 0.37%.

Modified Files with Diff Coverage (1)

RatingFile% DiffUncovered Line #s
Coverage rating: B Coverage rating: B
pkg/maker/contextlists.go100.0%
Total100.0%
🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Test Results

  5 files  ± 0   15 suites  ±0   1s ⏱️ ±0s
113 tests + 3  113 ✅ + 3  0 💤 ±0  0 ❌ ±0 
565 runs  +15  565 ✅ +15  0 💤 ±0  0 ❌ ±0 

Results for commit 318e971. ± Comparison against base commit a0703f6.

♻️ This comment has been updated with latest results.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates generated context CMakeLists.txt files to produce language-specific preprocessor macro dumps (separate C vs C++) using the appropriate compiler “language mode” flags and language/common compiler options, addressing macro-dump correctness across toolchains.

Changes:

  • Add generation logic for CPP_OPTIONS_<LANG> plus COMPILE_MACROS_C / COMPILE_MACROS_CXX, and emit macro-dump add_custom_command() accordingly.
  • Replace the previous single compile_macros.h output with language-scoped compile_macros_c.h and compile_macros_cxx.h where applicable.
  • Update Go unit tests and a large set of reference CMake fixtures for supported toolchains / scenarios.

Reviewed changes

Copilot reviewed 43 out of 43 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/data/solutions/pre-include/ref/project.IAR+ARMCM0/CMakeLists.txt Reference fixture: switch to language-specific macro outputs and add CPP_OPTIONS_* for IAR.
test/data/solutions/pre-include/ref/project.GCC+ARMCM0/CMakeLists.txt Reference fixture: generate compile_macros_c.h with C-specific preprocessor options for GCC.
test/data/solutions/pre-include/ref/project.CLANG+ARMCM0/CMakeLists.txt Reference fixture: generate compile_macros_c.h with C-specific preprocessor options for Clang.
test/data/solutions/pre-include/ref/project.AC6+ARMCM0/CMakeLists.txt Reference fixture: generate compile_macros_c.h with C-specific preprocessor options for AC6.
test/data/solutions/pre-include-oot/ref/project.IAR+ARMCM0/CMakeLists.txt Reference fixture (OOT): switch to compile_macros_c.h and add IAR preprocessor options.
test/data/solutions/pre-include-oot/ref/project.GCC+ARMCM0/CMakeLists.txt Reference fixture (OOT): switch to compile_macros_c.h and add GCC C options.
test/data/solutions/pre-include-oot/ref/project.CLANG+ARMCM0/CMakeLists.txt Reference fixture (OOT): switch to compile_macros_c.h and add Clang C options.
test/data/solutions/pre-include-oot/ref/project.AC6+ARMCM0/CMakeLists.txt Reference fixture (OOT): switch to compile_macros_c.h and add AC6 C options.
test/data/solutions/linker-pre-processing/ref/project.IAR+ARMCM0/CMakeLists.txt Reference fixture: update macro dump output to compile_macros_c.h and add IAR options.
test/data/solutions/linker-pre-processing/ref/project.GCC+ARMCM0/CMakeLists.txt Reference fixture: update macro dump output to compile_macros_c.h and add GCC C options.
test/data/solutions/linker-pre-processing/ref/project.CLANG+ARMCM0/CMakeLists.txt Reference fixture: update macro dump output to compile_macros_c.h and add Clang C options.
test/data/solutions/linker-pre-processing/ref/project.AC6+ARMCM0/CMakeLists.txt Reference fixture: update macro dump output to compile_macros_c.h and add AC6 C options.
test/data/solutions/link-lib/ref/project.GCC+ARMCM0/CMakeLists.txt Reference fixture: update GCC macro dump output to language-specific C macro file.
test/data/solutions/link-lib/ref/project.CLANG+ARMCM0/CMakeLists.txt Reference fixture: update Clang macro dump output to language-specific C macro file.
test/data/solutions/library-rtos/ref/project.IAR+ARMCM0/CMakeLists.txt Reference fixture: update IAR macro dump output to language-specific C macro file with options.
test/data/solutions/library-rtos/ref/project.GCC+ARMCM0/CMakeLists.txt Reference fixture: update GCC macro dump output to language-specific C macro file with options.
test/data/solutions/library-rtos/ref/project.CLANG+ARMCM0/CMakeLists.txt Reference fixture: update Clang macro dump output to language-specific C macro file with options.
test/data/solutions/library-rtos/ref/project.AC6+ARMCM0/CMakeLists.txt Reference fixture: update AC6 macro dump output to language-specific C macro file with options.
test/data/solutions/language-scope/ref/project.IAR+ARMCM0/CMakeLists.txt Reference fixture: emit both C and CXX macro dumps and per-language options for IAR.
test/data/solutions/language-scope/ref/project.GCC+ARMCM0/CMakeLists.txt Reference fixture: emit both C and CXX macro dumps and per-language options for GCC.
test/data/solutions/language-scope/ref/project.CLANG+ARMCM0/CMakeLists.txt Reference fixture: emit both C and CXX macro dumps and per-language options for Clang.
test/data/solutions/language-scope/ref/project.AC6+ARMCM0/CMakeLists.txt Reference fixture: emit both C and CXX macro dumps and per-language options for AC6.
test/data/solutions/include-define/ref/project.IAR+ARMCM0/CMakeLists.txt Reference fixture: update IAR macro dump output to language-specific C macro file with options.
test/data/solutions/include-define/ref/project.GCC+ARMCM0/CMakeLists.txt Reference fixture: update GCC macro dump output to language-specific C macro file with options.
test/data/solutions/include-define/ref/project.CLANG+ARMCM0/CMakeLists.txt Reference fixture: update Clang macro dump output to language-specific C macro file with options.
test/data/solutions/include-define/ref/project.AC6+ARMCM0/CMakeLists.txt Reference fixture: update AC6 macro dump output to language-specific C macro file with options.
test/data/solutions/executes/ref/project.Release+ARMCM0/CMakeLists.txt Reference fixture: update Release macro dump output to compile_macros_c.h with options.
test/data/solutions/build-cpp/ref/project.IAR+ARMCM55/CMakeLists.txt Reference fixture: emit both C/CXX macro dumps for IAR C++ build scenario.
test/data/solutions/build-cpp/ref/project.GCC+ARMCM55/CMakeLists.txt Reference fixture: emit both C/CXX macro dumps for GCC C++ build scenario.
test/data/solutions/build-cpp/ref/project.CLANG+ARMCM55/CMakeLists.txt Reference fixture: emit both C/CXX macro dumps for Clang C++ build scenario.
test/data/solutions/build-cpp/ref/project.AC6+ARMCM55/CMakeLists.txt Reference fixture: emit both C/CXX macro dumps for AC6 C++ build scenario.
test/data/solutions/build-c/ref/project.IAR+ARMCM0/CMakeLists.txt Reference fixture: update IAR C-only macro dump output to compile_macros_c.h with options.
test/data/solutions/build-c/ref/project.GCC+ARMCM0/CMakeLists.txt Reference fixture: update GCC C-only macro dump output to compile_macros_c.h with options.
test/data/solutions/build-c/ref/project.CLANG+ARMCM0/CMakeLists.txt Reference fixture: update Clang C-only macro dump output to compile_macros_c.h with options.
test/data/solutions/build-c/ref/project.AC6+ARMCM0/CMakeLists.txt Reference fixture: update AC6 C-only macro dump output to compile_macros_c.h with options.
test/data/solutions/build-asm/ref/project.IAR+ARMCM0/CMakeLists.txt Reference fixture: update IAR macro dump output to language-specific C macro file in ASM+C scenario.
test/data/solutions/build-asm/ref/project.GCC+ARMCM0/CMakeLists.txt Reference fixture: update GCC macro dump output to language-specific C macro file in ASM+C scenario.
test/data/solutions/build-asm/ref/project.CLANG+ARMCM0/CMakeLists.txt Reference fixture: update Clang macro dump output to language-specific C macro file in ASM+C scenario.
test/data/solutions/build-asm/ref/project.AC6+ARMCM0/CMakeLists.txt Reference fixture: update AC6 macro dump output to language-specific C macro file in ASM+C scenario.
test/data/solutions/blanks/ref/project X.AC6 X+ARMCM0 X/CMakeLists.txt Reference fixture: update macro dump output to language-specific C macro file with spaced paths scenario.
test/data/solutions/abstractions/ref/project.GCC+ARMCM0/CMakeLists.txt Reference fixture: update GCC macro dump output to language-specific C macro file with options.
pkg/maker/contextlists.go Implement generation of language-specific preprocessor options + macro dump outputs/commands.
pkg/maker/contextlists_test.go Add unit tests for PreprocessorOptions() output (generic + IAR cases).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/maker/contextlists.go
@brondani
brondani marked this pull request as ready for review July 21, 2026 07:30
@brondani
brondani force-pushed the generate-language-specific-compile branch from 8f84492 to 318e971 Compare July 21, 2026 09:02
@brondani
brondani requested a review from soumeh01 July 21, 2026 09:28
@soumeh01

Copy link
Copy Markdown
Collaborator

@grasci-arm Review this change

@grasci-arm

Copy link
Copy Markdown
Contributor

Plan:

Development plan for PR #503:

  1. Confirm dependency readiness: verify Refactor preprocessing arguments across toolchain configs devtools#2530 has landed or that this PR is tested against a cbuild output containing the expected language-specific misc option fields (misc.C, misc.CPP, misc.C-CPP) and toolchain metadata.

  2. Branch/base status: the PR branch is generate-language-specific-compile at 318e971, with three commits ahead of origin/main; origin/main is four CI/dependency workflow commits ahead. The PR source changes are in pkg/maker/contextlists.go, pkg/maker/contextlists_test.go, and generated test/data/solutions/**/ref/**/CMakeLists.txt fixtures, so rebasing onto current origin/main should not require source-level conflict resolution.

  3. Implementation focus: keep macro dump generation centralized in Cbuild.PreprocessorOptions() in pkg/maker/contextlists.go. For each enabled language, generate COMPILE_MACROS_C -> compile_macros_c.h and/or COMPILE_MACROS_CXX -> compile_macros_cxx.h; ignore non-C/CXX languages such as ASM. Include language mode flags (-xc, -xc++; for IAR, no C language flag and --c++ for CXX) plus language-specific and common misc options.

  4. CMake integration: ensure CreateContextCMakeLists() wires the generated macro files into the database target dependencies and emits a single add_custom_command(OUTPUT ...) containing one dump command per enabled C/CXX language. Confirm the previous shared COMPILE_MACROS ${OUT_DIR}/compile_macros.h path is fully removed from generated references.

  5. Option handling: review the split/quoting behavior for misc options with spaces, quoted include paths, escaped quotes, and relative paths adjusted through AdjustRelativePath(). If any edge case is ambiguous, add a narrow unit test before changing the implementation.

  6. Test coverage: keep and, if needed, extend pkg/maker/contextlists_test.go for mixed ASM/C/CXX, C-only, CXX-only, IAR behavior, common C-CPP options, and quoted path handling. Fixture coverage should continue to cover GCC, AC6, CLANG, and IAR contexts under test/data/solutions/**/ref/**/CMakeLists.txt.

  7. Fixture regeneration/validation: regenerate reference CMake outputs using the repository’s normal generator flow, then review fixture diffs to confirm each context only gains the expected CPP_OPTIONS_*, COMPILE_MACROS_*, database dependency, and macro dump command changes.

  8. Verification: run gofmt -s -w on touched Go files, git diff --check, go test ./..., and preferably make test-all in an environment with Go and golangci-lint installed. This container lacks go, so rely on CI or a dev machine for the full test run.

  9. Compatibility check: because compile_macros.h is intentionally replaced, confirm downstream consumers for cmsis-toolbox#625 and vscode-cmsis-solution#335 select compile_macros_c.h or compile_macros_cxx.h based on translation-unit language, and note the filename change in release/consumer-facing documentation if required.

  10. Final review gate: after dependency PR #2530 and CI are green, rebase or update the branch onto current origin/main, verify no generated fixtures drift, and request focused review from maintainers on IAR option handling and downstream consumer expectations.

Reply with a comment mentioning the service account and an approval phrase such as approve, approved, proceed, or go ahead, or add a thumbs-up reaction to this plan comment, before execution.

@soumeh01 soumeh01 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@brondani
brondani merged commit f7baff9 into main Jul 21, 2026
23 checks passed
@brondani
brondani deleted the generate-language-specific-compile branch July 21, 2026 12:38
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.

4 participants