O3DE_SDK_Launcher.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/Component/ComponentApplication.h>
  9. #include <AzCore/Memory/SystemAllocator.h>
  10. #include <AzCore/Settings/SettingsRegistryMergeUtils.h>
  11. #include <AzCore/Utils/Utils.h>
  12. #include <AzFramework/Process/ProcessWatcher.h>
  13. #include <cstdlib>
  14. #include <mach-o/dyld.h>
  15. int main(int argc, char* argv[])
  16. {
  17. const AZ::Debug::Trace tracer;
  18. // We need to pass in the engine path since we won't be able to find it by searching upwards.
  19. // We can't use any containers that use our custom allocator till after the call to ComponentApplication::Create()
  20. AZ::IO::FixedMaxPath processPath = AZ::Utils::GetExecutableDirectory();
  21. AZ::IO::FixedMaxPath enginePath = (processPath / "../Engine").LexicallyNormal();
  22. auto enginePathParam = AZ::SettingsRegistryInterface::FixedValueString::format(R"(--engine-path="%s")", enginePath.c_str());
  23. // Uses the fixed_vector deduction guide to determine the type is AZStd::fixed_vector<char*, 2>
  24. AZStd::fixed_vector commandLineParams{ processPath.Native().data(), enginePathParam.data() };
  25. // Create a ComponentApplication to initialize the AZ::SystemAllocator and initialize the SettingsRegistry
  26. AZ::ComponentApplication application(static_cast<int>(commandLineParams.size()), commandLineParams.data());
  27. application.Create(AZ::ComponentApplication::Descriptor());
  28. AZ::IO::FixedMaxPath installedBinariesFolder;
  29. if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
  30. {
  31. if (settingsRegistry->Get(installedBinariesFolder.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_InstalledBinaryFolder))
  32. {
  33. installedBinariesFolder = enginePath / installedBinariesFolder;
  34. }
  35. }
  36. AZ::IO::FixedMaxPath shellPath = "/bin/sh";
  37. AZStd::string parameters = AZStd::string::format("-c \"export LY_CMAKE_PATH=/usr/local/bin && \"%s/python/get_python.sh\"\"", enginePath.c_str());
  38. AzFramework::ProcessLauncher::ProcessLaunchInfo shellProcessLaunch;
  39. shellProcessLaunch.m_processExecutableString = AZStd::move(shellPath.Native());
  40. shellProcessLaunch.m_commandlineParameters = parameters;
  41. shellProcessLaunch.m_showWindow = true;
  42. shellProcessLaunch.m_workingDirectory = enginePath.String();
  43. AZStd::unique_ptr<AzFramework::ProcessWatcher> shellProcess(AzFramework::ProcessWatcher::LaunchProcess(shellProcessLaunch, AzFramework::ProcessCommunicationType::COMMUNICATOR_TYPE_NONE));
  44. shellProcess->WaitForProcessToExit(120);
  45. shellProcess.reset();
  46. parameters = AZStd::string::format("-c \"%s/scripts/o3de.sh register --this-engine\"", enginePath.c_str());
  47. shellProcessLaunch.m_commandlineParameters = parameters;
  48. shellProcess.reset(AzFramework::ProcessWatcher::LaunchProcess(shellProcessLaunch, AzFramework::ProcessCommunicationType::COMMUNICATOR_TYPE_NONE));
  49. shellProcess->WaitForProcessToExit(120);
  50. shellProcess.reset();
  51. AZ::IO::FixedMaxPath projectManagerPath = installedBinariesFolder/"o3de.app"/"Contents"/"MacOS"/"o3de";
  52. AzFramework::ProcessLauncher::ProcessLaunchInfo processLaunchInfo;
  53. processLaunchInfo.m_processExecutableString = AZStd::move(projectManagerPath.Native());
  54. processLaunchInfo.m_showWindow = true;
  55. AzFramework::ProcessLauncher::LaunchUnwatchedProcess(processLaunchInfo);
  56. application.Destroy();
  57. return 0;
  58. }