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.
Before this patch, this would fail with duplicate definition of module 'X'. It would be reached from the explicitly-provided -fmodule-map-file=%t/zeroth/module.modulemap and the implicitly discovered %t/second/module.modulemap.