/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace PythonAssetBuilder { void PythonAssetBuilderSystemComponent::Reflect(AZ::ReflectContext* context) { PythonBuilderNotificationHandler::Reflect(context); PythonBuilderWorker::Reflect(context); if (AZ::SerializeContext* serialize = azrtti_cast(context)) { const AZStd::vector systemTags({ AssetBuilderSDK::ComponentTags::AssetBuilder }); serialize->Class() ->Version(0) ->Attribute(AZ::Edit::Attributes::SystemComponentTags, systemTags) ; } if (AZ::BehaviorContext* behaviorContext = azrtti_cast(context)) { behaviorContext->EBus("PythonAssetBuilderRequestBus") ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation) ->Attribute(AZ::Script::Attributes::Module, "asset.builder") ->Event("RegisterAssetBuilder", &PythonAssetBuilderRequestBus::Events::RegisterAssetBuilder) ->Event("GetExecutableFolder", &PythonAssetBuilderRequestBus::Events::GetExecutableFolder) ; } } void PythonAssetBuilderSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC_CE("PythonAssetBuilderService")); } void PythonAssetBuilderSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { incompatible.push_back(AZ_CRC_CE("PythonAssetBuilderService")); } void PythonAssetBuilderSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) { dependent.push_back(EditorPythonBindings::PythonMarshalingService); dependent.push_back(EditorPythonBindings::PythonReflectionService); dependent.push_back(EditorPythonBindings::PythonEmbeddedService); } void PythonAssetBuilderSystemComponent::Init() { m_messageSink = AZStd::make_shared(); } void PythonAssetBuilderSystemComponent::Activate() { PythonAssetBuilderRequestBus::Handler::BusConnect(); if (auto&& pythonInterface = AZ::Interface::Get()) { pythonInterface->StartPython(true); } } void PythonAssetBuilderSystemComponent::Deactivate() { m_messageSink.reset(); if (PythonAssetBuilderRequestBus::HasHandlers()) { PythonAssetBuilderRequestBus::Handler::BusDisconnect(); if (auto&& pythonInterface = AZ::Interface::Get()) { pythonInterface->StopPython(true); } } } AZ::Outcome PythonAssetBuilderSystemComponent::RegisterAssetBuilder(const AssetBuilderSDK::AssetBuilderDesc& desc) { const AZ::Uuid busId = desc.m_busId; if (m_pythonBuilderWorkerMap.find(busId) != m_pythonBuilderWorkerMap.end()) { AZStd::string busIdString(busId.ToString()); AZStd::string failMessage = AZStd::string::format("Asset Builder of JobId:%s has already been created.", busIdString.c_str()); AZ_Warning(PythonBuilder, false, failMessage.c_str()); return AZ::Failure(failMessage); } // create a PythonBuilderWorker instance auto worker = AZStd::make_shared(); if (worker->ConfigureBuilderInformation(desc) == false) { return AZ::Failure(AZStd::string::format("Failed to configure builderId:%s", busId.ToString().c_str())); } m_pythonBuilderWorkerMap[busId] = worker; return AZ::Success(true); } AZ::Outcome PythonAssetBuilderSystemComponent::GetExecutableFolder() const { const char* exeFolderName = nullptr; AZ::ComponentApplicationBus::BroadcastResult(exeFolderName, &AZ::ComponentApplicationRequests::GetExecutableFolder); if (exeFolderName) { return AZ::Success(AZStd::string(exeFolderName)); } return AZ::Failure(AZStd::string("GetExecutableFolder access is missing.")); } }