Pushed the code above in separate PR: https://github.com/facebook/xctool/pull/316.