getbuildinfo.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "Python.h"
  2. #ifndef DONT_HAVE_STDIO_H
  3. #include <stdio.h>
  4. #endif
  5. #ifndef DATE
  6. #ifdef __DATE__
  7. #define DATE __DATE__
  8. #else
  9. #define DATE "xx/xx/xx"
  10. #endif
  11. #endif
  12. #ifndef TIME
  13. #ifdef __TIME__
  14. #define TIME __TIME__
  15. #else
  16. #define TIME "xx:xx:xx"
  17. #endif
  18. #endif
  19. /* XXX Only unix build process has been tested */
  20. #ifndef GITVERSION
  21. #define GITVERSION ""
  22. #endif
  23. #ifndef GITTAG
  24. #define GITTAG ""
  25. #endif
  26. #ifndef GITBRANCH
  27. #define GITBRANCH ""
  28. #endif
  29. static int initialized = 0;
  30. static char buildinfo[50 + sizeof(GITVERSION) +
  31. ((sizeof(GITTAG) > sizeof(GITBRANCH)) ?
  32. sizeof(GITTAG) : sizeof(GITBRANCH))];
  33. const char *
  34. Py_GetBuildInfo(void)
  35. {
  36. if (initialized) {
  37. return buildinfo;
  38. }
  39. initialized = 1;
  40. const char *revision = _Py_gitversion();
  41. const char *sep = *revision ? ":" : "";
  42. const char *gitid = _Py_gitidentifier();
  43. if (!(*gitid)) {
  44. gitid = "main";
  45. }
  46. PyOS_snprintf(buildinfo, sizeof(buildinfo),
  47. "%s%s%s, %.20s, %.9s", gitid, sep, revision,
  48. DATE, TIME);
  49. return buildinfo;
  50. }
  51. const char *
  52. _Py_gitversion(void)
  53. {
  54. return GITVERSION;
  55. }
  56. const char *
  57. _Py_gitidentifier(void)
  58. {
  59. const char *gittag, *gitid;
  60. gittag = GITTAG;
  61. if ((*gittag) && strcmp(gittag, "undefined") != 0)
  62. gitid = gittag;
  63. else
  64. gitid = GITBRANCH;
  65. return gitid;
  66. }