PythonSystemComponent_windows.cpp 2.2 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. bool InsertPythonLibraryPath(AZStd::unordered_set<AZStd::string>& paths, const char* pythonPackage, const char* engineRoot, const char* subPath)
  16. {
  17. // append lib path to Python paths
  18. AZ::IO::FixedMaxPath libPath = engineRoot;
  19. libPath /= AZ::IO::FixedMaxPathString::format(subPath, pythonPackage);
  20. libPath = libPath.LexicallyNormal();
  21. if (AZ::IO::SystemFile::Exists(libPath.c_str()))
  22. {
  23. paths.insert(libPath.c_str());
  24. return true;
  25. }
  26. AZ_Warning("python", false, "Python library path should exist! path:%s", libPath.c_str());
  27. return false;
  28. }
  29. bool InsertPythonBinaryLibraryPaths(AZStd::unordered_set<AZStd::string>& paths, const char* pythonPackage, const char* engineRoot)
  30. {
  31. // append lib path to Python paths
  32. bool succeeded = true;
  33. succeeded = succeeded && InsertPythonLibraryPath(paths, pythonPackage, engineRoot, "python/runtime/%s/python");
  34. succeeded = succeeded && InsertPythonLibraryPath(paths, pythonPackage, engineRoot, "python/runtime/%s/python/lib");
  35. succeeded = succeeded && InsertPythonLibraryPath(paths, pythonPackage, engineRoot, "python/runtime/%s/python/lib/site-packages");
  36. succeeded = succeeded && InsertPythonLibraryPath(paths, pythonPackage, engineRoot, "python/runtime/%s/python/DLLs");
  37. return succeeded;
  38. }
  39. AZStd::string GetPythonHomePath(const char* pythonPackage, const char* engineRoot)
  40. {
  41. // append lib path to Python paths
  42. AZ::IO::FixedMaxPath libPath = engineRoot;
  43. libPath /= AZ::IO::FixedMaxPathString::format("python/runtime/%s/python", pythonPackage);
  44. libPath = libPath.LexicallyNormal();
  45. return libPath.String();
  46. }
  47. }