The topological structure of supergravity: an application to supersymmetric localization