Listing all modules `@_exported` by a particular module?

given a module that contains several @_exported import statements, (some of which may be conditional, or transitive), is there a way to query what those @_exported modules are?

The first thing that comes to mind would be to do a syntax scan of each module to determine which ones it @_exported imports, and then do swiftc -scan-dependencies of a dummy module that imports the root module to collect the full dependency graph. Compute the closure by walking the graph from the top and recursively walking into any modules that were @_exported.

-scan-dependencies will respect the conditional imports based on target, -D, etc. The syntax scan won't but that would only be a problem if you have branches involving the same module where it's only conditionally @_exported in some branches.

1 Like

does SwiftPM expose any interfaces for -scan-dependencies? from playing around with it a little, it seems like it basically requires you to implement a package build system parallel to SwiftPM.

to zoom out a little, the thing i want to do is “group” some individual ABI modules into one logical “module”. for example, if i have

  • _BSON
  • _BSONDecoding
  • _BSONEncoding
  • BSON

and BSON re-exports the other three modules, i would like to be able to infer that the four modules are one logical “module”.

I'm not sure; I don't see anything from a quick search. The only reference to -scan-dependencies is here where it uses the "import prescan" mode, which isn't enough—that only gives you the names of the modules imported by the specific module that you point it at.