Skip to content

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented Jul 29, 2025

Please check if the PR fulfills these requirements

See how to contribute

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • configuration.schema.json updated if new parameters are added.

What kind of change does this PR introduce?

Improves the checks made to the sketch to avoid useless recompilation and preprocessing.

What is the current behavior?

The sketch source code, before being compiled, undergoes a two-phase processing:

  1. If the sketch has multiple source files, these files are merged, forming a single .cpp file.
  2. The merged .cpp file is then "preprocessed" to automatically obtain the forward declarations of the functions defined in the sketch.

Previously, these two operations were always performed, touching the final sketch.cpp. This resulted in sketch.cpp being recompiled every time. Moreover, the library discovery cache could not be exploited because of the sketch.cpp timestamp change.

What is the new behavior?

The merged sketch file is saved in a separate sketch.cpp.merged file, and it is compared to the newly generated content. If they match, the already preprocessed sketch.cpp and sketch.cpp.merged are left untouched.
This is enough for the current build system to recognize that the file is already up-to-date and skip both compilation and library discovery, which greatly improves compile times.

Does this PR introduce a breaking change, and is titled accordingly?

Unless I'm missing some convoluted case, it shouldn't.

Other information

@cmaglie cmaglie self-assigned this Jul 29, 2025
@cmaglie cmaglie added type: enhancement Proposed improvement topic: build-process Related to the sketch build process labels Jul 29, 2025
@cmaglie cmaglie force-pushed the do-not-recompile-sketch branch 2 times, most recently from 18335b6 to aa33373 Compare July 29, 2025 15:33
Copy link

codecov bot commented Jul 29, 2025

Codecov Report

❌ Patch coverage is 75.67568% with 54 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (master@3eecf20). Learn more about missing BASE report.
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...l/arduino/builder/internal/detector/source_file.go 54.54% 19 Missing and 6 partials ⚠️
internal/arduino/builder/internal/utils/utils.go 56.52% 7 Missing and 3 partials ⚠️
...nternal/arduino/builder/internal/detector/cache.go 40.00% 4 Missing and 2 partials ⚠️
...rnal/arduino/builder/internal/detector/detector.go 81.48% 3 Missing and 2 partials ⚠️
...nal/arduino/builder/internal/preprocessor/ctags.go 71.42% 1 Missing and 3 partials ⚠️
internal/arduino/builder/sketch.go 66.66% 2 Missing and 1 partial ⚠️
...lder/internal/preprocessor/arduino_preprocessor.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #2961   +/-   ##
=========================================
  Coverage          ?   68.31%           
=========================================
  Files             ?      242           
  Lines             ?    22831           
  Branches          ?        0           
=========================================
  Hits              ?    15596           
  Misses            ?     6029           
  Partials          ?     1206           
Flag Coverage Δ
unit 68.31% <75.67%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cmaglie cmaglie force-pushed the do-not-recompile-sketch branch from aa33373 to aa41179 Compare August 25, 2025 07:54
@cmaglie cmaglie force-pushed the do-not-recompile-sketch branch from aa41179 to 1ca362c Compare August 25, 2025 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: build-process Related to the sketch build process topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not recompile the sketch if there are no changes and libraries have not changed Sketch re-compiled when unnecessary
2 participants