python.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "vars.h"
  4. #include <util/system/platform.h>
  5. #define main RealMain
  6. #include "Modules/python.c"
  7. #undef main
  8. int main(int argc, char** argv) {
  9. char* distArcPath = getenv("ARCADIA_ROOT_DISTBUILD");
  10. char* pyPath = NULL;
  11. char* mx = 0;
  12. char* x = 0;
  13. int ret;
  14. putenv("PYTHONHOME=");
  15. putenv("PY_IGNORE_ENVIRONMENT=");
  16. putenv("PYTHONDONTWRITEBYTECODE=x");
  17. if (distArcPath) {
  18. pyPath = malloc(strlen("PYTHONPATH=") + strlen(distArcPath) + strlen(GetPyLib()) + 2);
  19. if (!pyPath)
  20. abort();
  21. mx = strdup(GetPyLib());
  22. x = mx;
  23. if (!x)
  24. abort();
  25. if (*x && *x == '"') {
  26. x += 1;
  27. x[strlen(x) - 1] = 0;
  28. }
  29. sprintf(pyPath, "PYTHONPATH=%s/%s", distArcPath, x);
  30. } else {
  31. pyPath = malloc(strlen("PYTHONPATH=") + strlen(GetLibDir()) + 1);
  32. sprintf(pyPath, "PYTHONPATH=%s", GetLibDir());
  33. }
  34. putenv(pyPath);
  35. ret = RealMain(argc, argv);
  36. if (pyPath)
  37. free(pyPath);
  38. if (mx)
  39. free(mx);
  40. return ret;
  41. }