The dependency scanner relies on the module map filtering logic in ASTWriter. The algorithm currently considers all system module maps affecting, which is not only sub-optimal, but can also cause failures when building a module explicitly (see attached test case).
This patch applies the same filtering logic to system module maps.