Skip to content

Conversation

jhump
Copy link
Owner

@jhump jhump commented Mar 16, 2022

This adds a new method PruneUnusedDependencies to a *FileBuilder. When creating a builder from an existing file, this can be used to remove its unused imports. If the file is mutated and elements removed such that some imports are no longer necessary, this enables removing those no-longer-used imports from the built descriptor.

This new method effectively removes any explicitly added imports. All imports in the built file will come from analyzing the actual referenced types in the file. Explicitly imported dependencies are typically used to provide knowledge of custom options (which cannot necessarily be found via basic examination of the builder hierarchy). But this patch preserves knowledge of custom options for descriptors created using builder.FromFile so that PruneUnusedDependencies can be safely used on these builders without resulting in inadvertently stripping custom options.

Resolves #504.

…at custom options can be preserved when pruning imports
@devnev
Copy link

devnev commented Mar 16, 2022

Tried it locally for my fairly simple use case and it also seemed to work as expected.

@jhump jhump merged commit 5603151 into master Mar 16, 2022
@jhump jhump deleted the jh/builder-can-autoprune-imports branch March 16, 2022 17:39
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.

Remove unused imports from built descriptor
2 participants