Skip to content

Implicit deps resolution: add #embed and fix #include followed by a comment - #4889

Open
vassilit wants to merge 1 commit into
SCons:masterfrom
vassilit:embed
Open

Implicit deps resolution: add #embed and fix #include followed by a comment#4889
vassilit wants to merge 1 commit into
SCons:masterfrom
vassilit:embed

Conversation

@vassilit

Copy link
Copy Markdown

Both a small bug-fix and a new feature.

Tested manually on rmlint:
Before this PR:
#include "header.h" in code.c, modify header.h, code.c get rebuilt.
#include "header.h" /* useful header */ in code.c, modify header.h, code.c do not get rebuilt.
#embed "py.py" in code.c, modify py.py, code.c do not get rebuilt.

After:
#include "header.h" in code.c, modify header.h, code.c get rebuilt.
#include "header.h" /* useful header */ in code.c, modify header.h, code.c do get rebuilt.
#embed "py.py" in code.c, modify py.py, code.c do get rebuilt.

Contributor Checklist:

  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt and RELEASE.txt (and read the README.rst).
  • I have updated the appropriate documentation

The C scanners recognised only #include and C++ #import, so a change to
a resource named by #embed did not mark the embedding source out of date.

Both scanners now track the resource. A quoted name is looked up relative
to the including file, a bracketed name in $CPPPATH:

- CScanner's regex captures the directive keyword, through a new private
  _ClassicCPPEmbed subclass which drops the keyword again when computing
  the sort key, so result ordering is unchanged. ClassicCPP itself keeps
  its documented three-group contract, which IDL, SWIG and RC rely on.
- SCons/cpp.py, which backs the opt-in CConditionalScanner, gains the
  keyword in its directive table plus a do_embed handler, and honours
  #embed in the conditional-branch wiring of start_handling_includes and
  stop_handling_includes.

The resource itself is deliberately not scanned: its contents are
embedded as data (possibly binary) rather than preprocessed. Resolved
resources are tagged on the node and filtered out by recurse_nodes().

Also fixes resolve_include() assuming the closing delimiter is the last
character of the line, which turned `#embed "d.bin" limit(4)` into the
filename `d.bin" limit(4`, and likewise mangled an #include carrying a
trailing comment.

Signed-off-by: Vassili Tchersky <vt+git@vbcy.org>
Assisted-by: Claude Opus 5
@mwichmann

Copy link
Copy Markdown
Collaborator

Thanks for your attention. There are some issues already on missing support for features introduced in newer C++ standards (and C standards too, for that matter)... see for example #4517 and #4518. Aren't there feature test macros for embed too? We can use all the help we can get sorting out the state of these newer features.

@vassilit

vassilit commented Jul 30, 2026

Copy link
Copy Markdown
Author

Aren't there feature test macros for embed too?

Are you referring to __has_embed ?

I use it as a feature test as well, like here.

@mwichmann

Copy link
Copy Markdown
Collaborator

Aren't there feature test macros for embed too?

Are you referring to __has_embed ?

I use it as a feature test as well, like here.

Yes. What happens if you use __has_embed or __has_include on a compiler that doesn't yet have support for the standard each appeared in?

@vassilit

Copy link
Copy Markdown
Author

Aren't there feature test macros for embed too?

Are you referring to __has_embed ?
I use it as a feature test as well, like here.

Yes. What happens if you use __has_embed or __has_include on a compiler that doesn't yet have support for the standard each appeared in?

It fails, with missing binary operator before token "(", that's why we use #if !defined(__has_embed). If the compiler supports C89, it does not fail. For even older compilers (K&R, etc), maybe #ifdef __has_embed works, but I'm not sure.

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.

2 participants