Merge #14492: fix some bugs in Tools/scripts/pdeps.py.

Initial patch by Popa Claudiu.