I am writing a very simple "hook" for Cabal which works fine with the last version but it stops to work when I "downgrade" Cabal to older versions 1.22, 1.20, etc.
The cause looks due to the path of some modules that keep on change, like for example: import Distribution.Simple.LocalBuildInfo
Is there any way to manage those changes across different versions? Do I need a "CPP" macro (in case which one) or there are better ways to manage it?
Usually yes, code that is dependent on a version of a library manages it via CPP macros, using macros defined by Cabal itself. See http://www.edsko.net/2014/09/13/haskell-cpp-macros/ for some examples. In your case:
#if MIN_VERSION_Cabal(1,22,0)
-- something working in Cabal 1.22 or above
#else
-- something working in Cabal versions prior to 1.22
#endif
It's not ideal, I'll give you that.