Python_linux.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/PlatformDef.h>
  9. #include <AzCore/std/containers/unordered_set.h>
  10. #include <AzCore/IO/SystemFile.h>
  11. #include <AzCore/IO/Path/Path.h>
  12. #include <AzFramework/StringFunc/StringFunc.h>
  13. namespace Platform
  14. {
  15. extern bool InsertPythonLibraryPath(AZStd::unordered_set<AZStd::string>& paths, const char* pythonPackage, const char* engineRoot, const char* subPath);
  16. bool InsertPythonBinaryLibraryPaths(AZStd::unordered_set<AZStd::string>& paths, const char* pythonPackage, const char* engineRoot)
  17. {
  18. bool succeeded = true;
  19. // PY_VERSION_MAJOR_MINOR must be defined through the build scripts based on the current python package (see cmake/LYPython.cmake)
  20. #if !defined(PY_VERSION_MAJOR_MINOR)
  21. #error "PY_VERSION_MAJOR_MINOR is not defined"
  22. #endif
  23. succeeded = succeeded && InsertPythonLibraryPath(paths, pythonPackage, engineRoot, "python/runtime/%s/python/lib");
  24. succeeded = succeeded && InsertPythonLibraryPath(paths, pythonPackage, engineRoot, "python/runtime/%s/python/lib/python" PY_VERSION_MAJOR_MINOR "/lib-dynload");
  25. succeeded = succeeded && InsertPythonLibraryPath(paths, pythonPackage, engineRoot, "python/runtime/%s/python/lib/python" PY_VERSION_MAJOR_MINOR );
  26. succeeded = succeeded && InsertPythonLibraryPath(paths, pythonPackage, engineRoot, "python/runtime/%s/python/lib/python" PY_VERSION_MAJOR_MINOR "/site-packages");
  27. return succeeded;
  28. }
  29. AZStd::string GetPythonHomePath(const char* pythonPackage, const char* engineRoot)
  30. {
  31. // append lib path to Python paths
  32. AZ::IO::FixedMaxPath libPath = engineRoot;
  33. libPath /= AZ::IO::FixedMaxPathString::format("python/runtime/%s/python", pythonPackage);
  34. libPath = libPath.LexicallyNormal();
  35. return libPath.String();
  36. }
  37. AZStd::string GetPythonExecutablePath(const char* engineRoot)
  38. {
  39. // append lib path to Python paths
  40. AZ::IO::FixedMaxPath libPath = engineRoot;
  41. libPath /= AZ::IO::FixedMaxPathString("python/python.sh");
  42. libPath = libPath.LexicallyNormal();
  43. return libPath.String();
  44. }
  45. }