udf_version.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include <util/generic/fwd.h>
  3. #include <util/system/types.h>
  4. namespace NYql {
  5. namespace NUdf {
  6. #define CURRENT_UDF_ABI_VERSION_MAJOR 2
  7. #define CURRENT_UDF_ABI_VERSION_MINOR 41
  8. #define CURRENT_UDF_ABI_VERSION_PATCH 0
  9. #ifdef USE_CURRENT_UDF_ABI_VERSION
  10. #define UDF_ABI_VERSION_MAJOR CURRENT_UDF_ABI_VERSION_MAJOR
  11. #define UDF_ABI_VERSION_MINOR CURRENT_UDF_ABI_VERSION_MINOR
  12. #define UDF_ABI_VERSION_PATCH CURRENT_UDF_ABI_VERSION_PATCH
  13. #else
  14. #if !defined(UDF_ABI_VERSION_MAJOR) || !defined(UDF_ABI_VERSION_MINOR) || !defined(UDF_ABI_VERSION_PATCH)
  15. #error Please use UDF_ABI_VERSION macro to define ABI version
  16. #endif
  17. #endif
  18. inline const char* CurrentAbiVersionStr()
  19. {
  20. #define str(s) #s
  21. #define xstr(s) str(s)
  22. return xstr(UDF_ABI_VERSION_MAJOR) "."
  23. xstr(UDF_ABI_VERSION_MINOR) "."
  24. xstr(UDF_ABI_VERSION_PATCH);
  25. #undef str
  26. #undef xstr
  27. }
  28. #define UDF_ABI_COMPATIBILITY_VERSION(MAJOR, MINOR) ((MAJOR) * 100 + (MINOR))
  29. #define UDF_ABI_COMPATIBILITY_VERSION_CURRENT UDF_ABI_COMPATIBILITY_VERSION(UDF_ABI_VERSION_MAJOR, UDF_ABI_VERSION_MINOR)
  30. static_assert(UDF_ABI_COMPATIBILITY_VERSION_CURRENT <=
  31. UDF_ABI_COMPATIBILITY_VERSION(CURRENT_UDF_ABI_VERSION_MAJOR, CURRENT_UDF_ABI_VERSION_MINOR),
  32. "UDF ABI version " Y_STRINGIZE(UDF_ABI_VERSION_MAJOR) "." Y_STRINGIZE(UDF_ABI_VERSION_MINOR)
  33. " is above " Y_STRINGIZE(CURRENT_UDF_ABI_VERSION_MAJOR) "." Y_STRINGIZE(CURRENT_UDF_ABI_VERSION_MINOR));
  34. constexpr ui32 MakeAbiVersion(ui8 major, ui8 minor, ui8 patch)
  35. {
  36. return major * 10000 + minor * 100 + patch;
  37. }
  38. constexpr ui16 MakeAbiCompatibilityVersion(ui8 major, ui8 minor)
  39. {
  40. return major * 100 + minor;
  41. }
  42. constexpr ui32 CurrentAbiVersion()
  43. {
  44. return MakeAbiVersion(UDF_ABI_VERSION_MAJOR, UDF_ABI_VERSION_MINOR, UDF_ABI_VERSION_PATCH);
  45. }
  46. constexpr ui32 CurrentCompatibilityAbiVersion()
  47. {
  48. return MakeAbiCompatibilityVersion(UDF_ABI_VERSION_MAJOR, UDF_ABI_VERSION_MINOR);
  49. }
  50. constexpr bool IsAbiCompatible(ui32 version)
  51. {
  52. // backward compatibility in greater minor versions of host
  53. return version / 10000 == UDF_ABI_VERSION_MAJOR &&
  54. (version / 100) % 100 <= UDF_ABI_VERSION_MINOR;
  55. }
  56. TString AbiVersionToStr(ui32 version);
  57. } // namspace NUdf
  58. } // namspace NYql
  59. namespace NKikimr { namespace NUdf = ::NYql::NUdf; }