Skip to content

Conversation

@Chkoupinator
Copy link
Contributor

This adds sub-directory detection when gathering sources for SConstruct, it took me a while to figure out why using subfolders in my src folder wasn't working for me to realize that Glob simply does not look at subfolders.

I think this would improve the template for people who want to use it for a serious project as I find it very unlikely that anyone would put all their files on the root src/ folder for anything remotely big

Copy link
Member

@Ivorforce Ivorforce left a comment

Choose a reason for hiding this comment

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

Hello, thank you for opening a PR!
This part of the code is a little bit tricky. At the very least, "variant directory" features of SCons will require sources in the right format.
I get your problem though - not being able to put .cpp files into subfolders, and having to find out why, isn't exactly a nice first impression.

An os.walk implementation could be adopted, for example, one was suggested in 2012 in this StackOverflow thread.

However, most projects are not arbitrarily deep. In my own project, I prefer to just support a 3-deep hierarchy with SCons supported functionality, like suggested here: https://stackoverflow.com/a/10599984

@Chkoupinator
Copy link
Contributor Author

thanks for the feedback!
I updated it, this could probably be improved by adding a layers of depth parameter but this is better than nothing imo

Copy link
Member

@Ivorforce Ivorforce left a comment

Choose a reason for hiding this comment

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

Seems fine to me; this should be good enough for most projects, and it's easy to understand.

@Chkoupinator
Copy link
Contributor Author

@Ivorforce do you know what the process would be to make this PR move forward?

@paddy-exe
Copy link
Collaborator

paddy-exe commented Oct 31, 2025

@Ivorforce do you know what the process would be to make this PR move forward?

That would be my merge. Apologies for the delay.

I am not sure if we shouldn't directly just go for the os.walk implementation you linked @Ivorforce . This feels more like a band aid solution to me even if probably most people will indeed only use max 3 subdirectories.

@Chkoupinator
Copy link
Contributor Author

@paddy-exe no worries! my initial implementation used os.walk. Let me know if I should revert my last commit

@paddy-exe
Copy link
Collaborator

@paddy-exe no worries! my initial implementation used os.walk. Let me know if I should revert my last commit

Thank you. After further discussing on RocketChat with more maintainers, let's go for the explicit subdirectories (the current implementation).

However, could you please squash the two commits into one (and clean up the commit descriptions)?

…o 3 layers of depth

Added automatic file collection using Glob so that source files in directories that are up to 3 layers of depth into src/ get properly detected by SConstruct.
@Chkoupinator
Copy link
Contributor Author

done! @paddy-exe

@paddy-exe paddy-exe merged commit 4d5b306 into godotengine:main Nov 1, 2025
@paddy-exe
Copy link
Collaborator

Merged! Thank you for your contribution!

@doZennn
Copy link

doZennn commented Nov 4, 2025

This seems to be break linking if you have generated docs in src\gen\:

src\gen\doc_data.gen.windows.template_debug.dev.x86_64.obj : warning LNK4042: object specified more than once; extras ignored
LINK : error LNK1218: warning treated as error; no output file generated

@paddy-exe
Copy link
Collaborator

This seems to be break linking if you have generated docs in src\gen\:


src\gen\doc_data.gen.windows.template_debug.dev.x86_64.obj : warning LNK4042: object specified more than once; extras ignored

LINK : error LNK1218: warning treated as error; no output file generated

Would you mind creating an issue for this and link this PR?

@Ivorforce
Copy link
Member

Ivorforce commented Nov 5, 2025

Oh right, I totally forgot that doc_data.cpp exists 😅 sorry!

The solution in my own code is the following:

sources.extend([
    f for f in env.Glob("src/*.cpp") + env.Glob("src/*/*.cpp") + env.Glob("src/*/*/*.cpp")
    # Generated files will be added selectively and maintained by tools.
    if not "/gen/" in str(f.path)
])

However, this is dangerously close to being complicated again, so I'd also be open to using the previously suggested os.walk.

(I suppose this is why David prefers using explicitly adding all source files instead 😆)

@Chkoupinator
Copy link
Contributor Author

I should have a local history of the first implementation I had proposed, I had thought of docs when making it but forgot about them when implementing the version that ended up being merged 😅 (I don't have docs in my project so I didn't test it 😅 😅 )

I'll make a PR for it when I get back home

@Calinou Calinou added the enhancement New feature or request label Nov 6, 2025
@Ivorforce Ivorforce changed the title Add subdirectories to source file collection logic in SConstruct Add subdirectories to source file collection logic in SConstruct (reverted) Nov 8, 2025
@Ivorforce
Copy link
Member

Ivorforce commented Nov 8, 2025

While we're waiting to agree on a different solution, I reverted the commit (directly on main) because I saw people start having issues on Discord.

@Chkoupinator
Copy link
Contributor Author

I finally found some time to get back to this, sorry for the very long delay, you can find the new pull request with the original os.walk implementation in the PR #102 @Ivorforce @paddy-exe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants