[webkit-dev] Removing BUILDING_ON / TARGETING macros in favor of system availability macros
mrowe at apple.com
Tue Jul 10 16:24:04 PDT 2012
I would like to propose removing the BUILDING_ON and TARGETING family of macros that are used to build code conditionally for different versions of OS X. I propose this in order to address several problems:
The checks are verbose, and getting worse.
For instance, in order to write code targeting OS X 10.8 and newer I have to enumerate all other supported OS versions:
#if !defined(TARGETING_LEOPARD) && !defined(TARGETING_SNOW_LEOPARD) && !defined(TARGETING_LION)
This problem has become worse over time as the number of supported OS X versions in the WebKit code base has increased.
The nature of the version checks are often not obvious at first glance.
In order to understand the checks you have to first remember the marketing names of the various OS X releases. You must then reason about the conditional logic of the check itself, which will often contains multiple negated clauses.
Almost all current uses are incorrect in the context of SDKs.
The vast majority of the checks in WebKit use the BUILDING_ON macros where the TARGETING macros would be more appropriate. This hasn't cause many problems to date since builds of WebKit on OS X for the most part do not use SDKs. This means that they build with __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_OS_X_VERSION_MAX_ALLOWED, resulting in the BUILDING_ON and TARGETING macros being equivalent. However, when building with a deployment target of an older OS release than the SDK you're building against, the BUILDING_ON and TARGETING macros will have different behavior. The result is that WebKit fails to build against an SDK when targeting an older OS release.
My proposed solution to these problems is to remove the BUILDING_ON and TARGETING macros. The vast majority of the BUILDING_ON uses and all of the TARGETING uses would be replaced with tests against __MAC_OS_X_VERSION_MIN_REQUIRED. The small number of uses of BUILDING_ON that are being used correctly would be replaced with tests against __MAC_OS_X_VERSION_MAX_ALLOWED.
The example above of code targeting OS X 10.8 and newer would become:
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
Code that wishes to target only OS X 10.6 and older would become:
#if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1060
This is much more concise and understandable than the current approach.
I'm open to feedback on this proposal, but I'd like to move forward with this change in the next day or two if no one objects.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the webkit-dev