Skip to content

Conversation

@jtdavis777
Copy link
Collaborator

@jtdavis777 jtdavis777 commented Nov 19, 2025

Fixes #8784

Adds (my best attempt at) a minimally invasive implementation of --file-names-only.

Note that this version prints every file the program attempts to write -- during testing I found #8787 where python tries and silently fails to make a file. Other languages may have the same problem.

@jtdavis777
Copy link
Collaborator Author

image

@jtdavis777 jtdavis777 requested a review from aardappel November 25, 2025 12:18
}

private:
bool SaveStub(const std::string& filename, const Imports& imports,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, if making these private is needed for the functionality, sure, but if its a drive-by "I am making the code better" you better be damn sure its near impossible nobody could be calling these.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agreed - in this case I think this is safe -- these were just free functions present in this cc file. I've just moved them to a more convenient location. Technically speaking these may have been accessible as they had external linkage... but anyone accessing these particular functions seems like a stretch.

struct IDLOptions {
// file saver
// shared pointer since this object gets copied and modified.
std::shared_ptr<FileSaver> file_saver = std::make_shared<RealFileSaver>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am definitely on team "shared_ptr is a code smell", and I don't think we use them anywhere else in FlatBuffers unless they have crept in. If you made this a unique_ptr, what exactly would not work and why would that result in worse code? This is a new variable and I only see very basic references to it in this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

100% agree -- I forget the exact thinking I had here but I believe it was because unique_ptr makes IDLOptions non-copyable, and I need someone to own the file saver. I can look into if idloptions can be safely moved around, or have idloptions just hold a raw pointer and have flatc own the saver (the latter is probably best)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

managed to refactor this to use an external unique_ptr and just have the options hold onto a raw pointer. IDLOptions is copied around way too many places to refactor, and we do need a single resource for the file name collection.

Copy link
Collaborator Author

@jtdavis777 jtdavis777 left a comment

Choose a reason for hiding this comment

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

@aardappel thanks for the thorough review! I can go back and not be so heavy handed with my cleanup.

Most of the file manager code that I cleaned up was brought in #7821, which was never used in our repo. I respect the callout that other people ingesting our code base may take advantage of them though.

struct IDLOptions {
// file saver
// shared pointer since this object gets copied and modified.
std::shared_ptr<FileSaver> file_saver = std::make_shared<RealFileSaver>();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

100% agree -- I forget the exact thinking I had here but I believe it was because unique_ptr makes IDLOptions non-copyable, and I need someone to own the file saver. I can look into if idloptions can be safely moved around, or have idloptions just hold a raw pointer and have flatc own the saver (the latter is probably best)

@aardappel
Copy link
Collaborator

Ok, I'd agree any code that comes from an incomplete/non-functional PR that was merged is probably good to delete if not used in your fix. Still would prefer to minimize renames.

@jtdavis777
Copy link
Collaborator Author

seems like a decent middle ground. I'll compare with the original and roll back to being less aggressive, and will put back the helper functions.

@jtdavis777 jtdavis777 requested a review from aardappel November 27, 2025 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--file-names-only Option exists but not fully implemented

2 participants