Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,155 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzTest/AzTest.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/Component/ComponentApplication.h>
#include <EditorPythonBindings/EditorPythonBindingsSymbols.h>
#include "Source/PythonAssetBuilderSystemComponent.h"
#include <PythonAssetBuilder/PythonAssetBuilderBus.h>
#include <PythonAssetBuilder/PythonBuilderRequestBus.h>
#include <AzCore/Asset/AssetCommon.h>
#include <AssetBuilderSDK/AssetBuilderSDK.h>
namespace UnitTest
{
class PythonAssetBuilderTest
: public ScopedAllocatorSetupFixture
{
protected:
AZStd::unique_ptr<AZ::ComponentApplication> m_app;
AZ::Entity* m_systemEntity = nullptr;
void SetUp() override
{
AZ::ComponentApplication::Descriptor appDesc;
m_app = AZStd::make_unique<AZ::ComponentApplication>();
m_systemEntity = m_app->Create(appDesc);
}
void TearDown() override
{
m_app.reset();
}
};
TEST_F(PythonAssetBuilderTest, SystemComponent_InitActivate)
{
m_app->RegisterComponentDescriptor(PythonAssetBuilder::PythonAssetBuilderSystemComponent::CreateDescriptor());
m_systemEntity->CreateComponent<PythonAssetBuilder::PythonAssetBuilderSystemComponent>();
m_systemEntity->Init();
EXPECT_EQ(AZ::Entity::State::Init, m_systemEntity->GetState());
m_systemEntity->Activate();
EXPECT_EQ(AZ::Entity::State::Active, m_systemEntity->GetState());
}
TEST_F(PythonAssetBuilderTest, SystemComponent_RegisterAssetBuilder)
{
using namespace PythonAssetBuilder;
m_app->RegisterComponentDescriptor(PythonAssetBuilderSystemComponent::CreateDescriptor());
m_systemEntity->CreateComponent<PythonAssetBuilderSystemComponent>();
m_systemEntity->Init();
m_systemEntity->Activate();
AssetBuilderSDK::AssetBuilderDesc mockAssetBuilderDesc;
mockAssetBuilderDesc.m_busId = AZ::Uuid::CreateString("{C68C8E96-223A-46BD-8D4A-E159A85AC02A}");
AZ::Outcome<bool, AZStd::string> result;
PythonAssetBuilderRequestBus::BroadcastResult(result, &PythonAssetBuilderRequestBus::Events::RegisterAssetBuilder, mockAssetBuilderDesc);
EXPECT_TRUE(result.IsSuccess());
}
TEST_F(PythonAssetBuilderTest, PythonAssetBuilderRequestBus_GetExecutableFolder_Works)
{
using namespace PythonAssetBuilder;
EXPECT_FALSE(PythonAssetBuilderRequestBus::HasHandlers());
m_app->RegisterComponentDescriptor(PythonAssetBuilderSystemComponent::CreateDescriptor());
m_systemEntity->CreateComponent<PythonAssetBuilderSystemComponent>();
m_systemEntity->Init();
m_systemEntity->Activate();
EXPECT_TRUE(PythonAssetBuilderRequestBus::HasHandlers());
AZ::Outcome<AZStd::string, AZStd::string> result;
PythonAssetBuilderRequestBus::BroadcastResult(
result,
&PythonAssetBuilderRequestBus::Events::GetExecutableFolder);
EXPECT_TRUE(result.IsSuccess());
}
// test bus API exists
TEST_F(PythonAssetBuilderTest, PythonBuilderRequestBus_CreateEditorEntity_Exists)
{
using namespace PythonAssetBuilder;
EXPECT_FALSE(PythonBuilderRequestBus::HasHandlers());
// Some static tests to make sure the public API has not changed since that
// would break Python asset builders using this EBus
{
AZ::Outcome<AZ::EntityId, AZStd::string> result;
AZStd::string name;
PythonBuilderRequestBus::BroadcastResult(
result,
&PythonBuilderRequestBus::Events::CreateEditorEntity,
name);
EXPECT_FALSE(result.IsSuccess());
}
m_app->RegisterComponentDescriptor(PythonAssetBuilderSystemComponent::CreateDescriptor());
m_systemEntity->CreateComponent<PythonAssetBuilderSystemComponent>();
m_systemEntity->Init();
m_systemEntity->Activate();
EXPECT_TRUE(PythonBuilderRequestBus::HasHandlers());
}
TEST_F(PythonAssetBuilderTest, PythonBuilderRequestBus_WriteSliceFile_Exists)
{
using namespace PythonAssetBuilder;
EXPECT_FALSE(PythonBuilderRequestBus::HasHandlers());
// Some static tests to make sure the public API has not changed since that
// would break Python asset builders using this EBus
{
AZ::Outcome<AZ::Data::AssetType, AZStd::string> result;
AZStd::string_view filename;
AZStd::vector<AZ::EntityId> entities;
bool makeDynamic = {};
PythonBuilderRequestBus::BroadcastResult(
result,
&PythonBuilderRequestBus::Events::WriteSliceFile,
filename,
entities,
makeDynamic);
EXPECT_FALSE(result.IsSuccess());
}
m_app->RegisterComponentDescriptor(PythonAssetBuilderSystemComponent::CreateDescriptor());
m_systemEntity->CreateComponent<PythonAssetBuilderSystemComponent>();
m_systemEntity->Init();
m_systemEntity->Activate();
EXPECT_TRUE(PythonBuilderRequestBus::HasHandlers());
}
}
AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV);
@@ -0,0 +1,119 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzTest/AzTest.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/Component/ComponentApplication.h>
#include <EditorPythonBindings/EditorPythonBindingsSymbols.h>
#include "Source/PythonAssetBuilderSystemComponent.h"
#include <PythonAssetBuilder/PythonAssetBuilderBus.h>
#include <PythonAssetBuilder/PythonBuilderNotificationBus.h>
#include "PythonBuilderTestShared.h"
namespace UnitTest
{
// fixtures
class PythonBuilderCreateJobsTest
: public ScopedAllocatorSetupFixture
{
protected:
AZStd::unique_ptr<AZ::ComponentApplication> m_app;
AZ::Entity* m_systemEntity = nullptr;
void SetUp() override
{
AZ::ComponentApplication::Descriptor appDesc;
m_app = AZStd::make_unique<AZ::ComponentApplication>();
m_systemEntity = m_app->Create(appDesc);
}
void TearDown() override
{
m_app.reset();
}
};
// tests
TEST_F(PythonBuilderCreateJobsTest, PythonBuilder_CreateJobs_Success)
{
using namespace PythonAssetBuilder;
using namespace AssetBuilderSDK;
const AZ::Uuid builderId = RegisterAssetBuilder(m_app.get(), m_systemEntity);
MockJobHandler mockJobHandler;
mockJobHandler.BusConnect(builderId);
AssetBuilderSDK::CreateJobsRequest request;
request.m_builderid = builderId;
request.m_sourceFileUUID = AZ::Uuid::CreateRandom();
AssetBuilderSDK::CreateJobsResponse response;
response.m_result = AssetBuilderSDK::CreateJobsResultCode::Failed;
PythonBuilderNotificationBus::EventResult(
response,
builderId,
&PythonBuilderNotificationBus::Events::OnCreateJobsRequest,
request);
EXPECT_EQ(AssetBuilderSDK::CreateJobsResultCode::Success, response.m_result);
EXPECT_EQ(0, mockJobHandler.m_onShutdownCount);
}
TEST_F(PythonBuilderCreateJobsTest, PythonBuilder_CreateJobs_Failed)
{
using namespace PythonAssetBuilder;
using namespace AssetBuilderSDK;
const AZ::Uuid builderId = RegisterAssetBuilder(m_app.get(), m_systemEntity);
EXPECT_NE(AZ::Uuid::CreateNull(), builderId);
MockJobHandler mockJobHandler;
mockJobHandler.BusConnect(builderId);
AssetBuilderSDK::CreateJobsRequest request;
request.m_builderid = builderId;
request.m_sourceFileUUID = AZ::Uuid::CreateNull();
AssetBuilderSDK::CreateJobsResponse response;
response.m_result = AssetBuilderSDK::CreateJobsResultCode::Success;
PythonBuilderNotificationBus::EventResult(
response,
request.m_builderid,
&PythonBuilderNotificationBus::Events::OnCreateJobsRequest,
request);
EXPECT_EQ(AssetBuilderSDK::CreateJobsResultCode::Failed, response.m_result);
EXPECT_EQ(0, mockJobHandler.m_onShutdownCount);
}
TEST_F(PythonBuilderCreateJobsTest, PythonBuilder_CreateJobs_OnShutdown)
{
using namespace PythonAssetBuilder;
using namespace AssetBuilderSDK;
const AZ::Uuid builderId = RegisterAssetBuilder(m_app.get(), m_systemEntity);
EXPECT_NE(AZ::Uuid::CreateNull(), builderId);
MockJobHandler mockJobHandler;
mockJobHandler.BusConnect(builderId);
PythonBuilderNotificationBus::Event(builderId, &PythonBuilderNotificationBus::Events::OnShutdown);
EXPECT_EQ(1, mockJobHandler.m_onShutdownCount);
}
}
@@ -0,0 +1,126 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzTest/AzTest.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/Component/ComponentApplication.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <EditorPythonBindings/EditorPythonBindingsSymbols.h>
#include "Source/PythonAssetBuilderSystemComponent.h"
#include <PythonAssetBuilder/PythonAssetBuilderBus.h>
#include "PythonBuilderTestShared.h"
namespace UnitTest
{
class PythonBuilderProcessJobTest
: public ScopedAllocatorSetupFixture
{
protected:
AZStd::unique_ptr<AZ::ComponentApplication> m_app;
AZ::Entity* m_systemEntity = nullptr;
void SetUp() override
{
AZ::ComponentApplication::Descriptor appDesc;
m_app = AZStd::make_unique<AZ::ComponentApplication>();
m_systemEntity = m_app->Create(appDesc);
}
void TearDown() override
{
m_app.reset();
}
};
TEST_F(PythonBuilderProcessJobTest, PythonBuilder_ProcessJob_ResultSuccess)
{
using namespace PythonAssetBuilder;
using namespace AssetBuilderSDK;
const AZ::Uuid builderId = RegisterAssetBuilder(m_app.get(), m_systemEntity);
MockJobHandler mockJobHandler;
mockJobHandler.BusConnect(builderId);
AssetBuilderSDK::ProcessJobRequest request;
request.m_builderGuid = builderId;
request.m_sourceFileUUID = AZ::Uuid::CreateRandom();
AssetBuilderSDK::ProcessJobResponse response;
response.m_resultCode = AssetBuilderSDK::ProcessJobResult_NetworkIssue;
PythonBuilderNotificationBus::EventResult(
response,
builderId,
&PythonBuilderNotificationBus::Events::OnProcessJobRequest,
request);
EXPECT_EQ(AssetBuilderSDK::ProcessJobResult_Success, response.m_resultCode);
EXPECT_EQ(0, mockJobHandler.m_onCancelCount);
}
TEST_F(PythonBuilderProcessJobTest, PythonBuilder_ProcessJob_ResultFailed)
{
using namespace PythonAssetBuilder;
using namespace AssetBuilderSDK;
const AZ::Uuid builderId = RegisterAssetBuilder(m_app.get(), m_systemEntity);
MockJobHandler mockJobHandler;
mockJobHandler.BusConnect(builderId);
AssetBuilderSDK::ProcessJobRequest request;
request.m_builderGuid = builderId;
request.m_sourceFileUUID = AZ::Uuid::CreateNull();
AssetBuilderSDK::ProcessJobResponse response;
response.m_resultCode = AssetBuilderSDK::ProcessJobResult_Success;
PythonBuilderNotificationBus::EventResult(
response,
builderId,
&PythonBuilderNotificationBus::Events::OnProcessJobRequest,
request);
EXPECT_EQ(AssetBuilderSDK::ProcessJobResult_Failed, response.m_resultCode);
EXPECT_EQ(0, mockJobHandler.m_onCancelCount);
}
TEST_F(PythonBuilderProcessJobTest, PythonBuilder_ProcessJob_OnCancel)
{
using namespace PythonAssetBuilder;
using namespace AssetBuilderSDK;
const AZ::Uuid builderId = RegisterAssetBuilder(m_app.get(), m_systemEntity);
MockJobHandler mockJobHandler;
mockJobHandler.BusConnect(builderId);
PythonBuilderNotificationBus::Event(builderId, &PythonBuilderNotificationBus::Events::OnCancel);
EXPECT_EQ(1, mockJobHandler.m_onCancelCount);
}
TEST_F(PythonBuilderProcessJobTest, PythonBuilderRequestBus_Behavior_Exists)
{
using namespace PythonAssetBuilder;
using namespace AssetBuilderSDK;
RegisterAssetBuilder(m_app.get(), m_systemEntity);
auto entry = m_app->GetBehaviorContext()->m_ebuses.find("PythonBuilderRequestBus");
ASSERT_NE(m_app->GetBehaviorContext()->m_ebuses.end(), entry);
EXPECT_NE(entry->second->m_events.end(), entry->second->m_events.find("WriteSliceFile"));
EXPECT_NE(entry->second->m_events.end(), entry->second->m_events.find("CreateEditorEntity"));
}
}
@@ -0,0 +1,93 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzTest/AzTest.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/Component/ComponentApplication.h>
#include <AssetBuilderSDK/AssetBuilderSDK.h>
#include <EditorPythonBindings/EditorPythonBindingsSymbols.h>
#include "Source/PythonAssetBuilderSystemComponent.h"
#include <PythonAssetBuilder/PythonAssetBuilderBus.h>
namespace UnitTest
{
class PythonBuilderRegisterJobsTest
: public ScopedAllocatorSetupFixture
{
protected:
AZStd::unique_ptr<AZ::ComponentApplication> m_app;
AZ::Entity* m_systemEntity = nullptr;
void SetUp() override
{
AZ::ComponentApplication::Descriptor appDesc;
m_app = AZStd::make_unique<AZ::ComponentApplication>();
m_systemEntity = m_app->Create(appDesc);
}
void TearDown() override
{
m_app.reset();
}
};
TEST_F(PythonBuilderRegisterJobsTest, PythonBuilder_RegisterBuilder_Regex)
{
using namespace PythonAssetBuilder;
m_app->RegisterComponentDescriptor(PythonAssetBuilderSystemComponent::CreateDescriptor());
m_systemEntity->CreateComponent<PythonAssetBuilderSystemComponent>();
m_systemEntity->Init();
m_systemEntity->Activate();
AssetBuilderSDK::AssetBuilderPattern buildPattern;
buildPattern.m_pattern = R"_(^.*\.foo$)_";
buildPattern.m_type = AssetBuilderSDK::AssetBuilderPattern::Regex;
AssetBuilderSDK::AssetBuilderDesc builderDesc;
builderDesc.m_busId = AZ::Uuid::CreateRandom();
builderDesc.m_name = "Mock Builder Regex";
builderDesc.m_patterns.push_back(buildPattern);
builderDesc.m_version = 0;
AZ::Outcome<bool, AZStd::string> result;
PythonAssetBuilderRequestBus::BroadcastResult(result, &PythonAssetBuilderRequestBus::Events::RegisterAssetBuilder, builderDesc);
EXPECT_TRUE(result.IsSuccess());
}
TEST_F(PythonBuilderRegisterJobsTest, PythonBuilder_RegisterBuilder_Wildcard)
{
using namespace PythonAssetBuilder;
m_app->RegisterComponentDescriptor(PythonAssetBuilderSystemComponent::CreateDescriptor());
m_systemEntity->CreateComponent<PythonAssetBuilderSystemComponent>();
m_systemEntity->Init();
m_systemEntity->Activate();
AssetBuilderSDK::AssetBuilderPattern buildPattern;
buildPattern.m_pattern = "a/path/to/*.foo";
buildPattern.m_type = AssetBuilderSDK::AssetBuilderPattern::Wildcard;
AssetBuilderSDK::AssetBuilderDesc builderDesc;
builderDesc.m_busId = AZ::Uuid::CreateRandom();
builderDesc.m_name = "Mock Builder Wildcard";
builderDesc.m_patterns.push_back(buildPattern);
builderDesc.m_version = 0;
AZ::Outcome<bool, AZStd::string> result;
PythonAssetBuilderRequestBus::BroadcastResult(result, &PythonAssetBuilderRequestBus::Events::RegisterAssetBuilder, builderDesc);
EXPECT_TRUE(result.IsSuccess());
}
}
@@ -0,0 +1,94 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzTest/AzTest.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/Component/ComponentApplication.h>
#include <EditorPythonBindings/EditorPythonBindingsSymbols.h>
#include "Source/PythonAssetBuilderSystemComponent.h"
#include <PythonAssetBuilder/PythonAssetBuilderBus.h>
#include <PythonAssetBuilder/PythonBuilderNotificationBus.h>
namespace UnitTest
{
struct MockJobHandler final
: public PythonAssetBuilder::PythonBuilderNotificationBus::Handler
{
int m_onShutdownCount = 0;
int m_onCancelCount = 0;
AssetBuilderSDK::CreateJobsResponse OnCreateJobsRequest(const AssetBuilderSDK::CreateJobsRequest& request) override
{
if (request.m_sourceFileUUID.IsNull())
{
return AssetBuilderSDK::CreateJobsResponse{};
}
AssetBuilderSDK::CreateJobsResponse response;
response.m_result = AssetBuilderSDK::CreateJobsResultCode::Success;
return response;
}
AssetBuilderSDK::ProcessJobResponse OnProcessJobRequest(const AssetBuilderSDK::ProcessJobRequest& request)
{
if (request.m_sourceFileUUID.IsNull())
{
return AssetBuilderSDK::ProcessJobResponse{};
}
AssetBuilderSDK::ProcessJobResponse response;
response.m_resultCode = AssetBuilderSDK::ProcessJobResult_Success;
return response;
}
void OnShutdown()
{
++m_onShutdownCount;
}
void OnCancel()
{
++m_onCancelCount;
}
};
template <typename App, typename EntityType>
AZ::Uuid RegisterAssetBuilder(App* app, EntityType* systemEntity)
{
using namespace PythonAssetBuilder;
using namespace AssetBuilderSDK;
app->RegisterComponentDescriptor(PythonAssetBuilderSystemComponent::CreateDescriptor());
systemEntity->template CreateComponent<PythonAssetBuilderSystemComponent>();
systemEntity->Init();
systemEntity->Activate();
AssetBuilderPattern buildPattern;
buildPattern.m_pattern = "*.mock";
buildPattern.m_type = AssetBuilderPattern::Wildcard;
AssetBuilderDesc builderDesc;
builderDesc.m_busId = AZ::Uuid::CreateRandom();
builderDesc.m_name = "Mock Builder";
builderDesc.m_patterns.push_back(buildPattern);
builderDesc.m_version = 0;
AZ::Outcome<bool, AZStd::string> result;
PythonAssetBuilderRequestBus::BroadcastResult(result, &PythonAssetBuilderRequestBus::Events::RegisterAssetBuilder, builderDesc);
EXPECT_TRUE(result.IsSuccess());
return builderDesc.m_busId;
}
}
@@ -0,0 +1,131 @@
"""
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"""
#
# Simple example asset builder that processes *.foo files
#
import azlmbr.math
import azlmbr.asset.builder
import os, shutil
# the UUID must be unique amongst all the asset builders in Python or otherwise
busIdString = '{E4DB381B-61A0-4729-ACD9-4C8BDD2D2282}'
busId = azlmbr.math.Uuid_CreateString(busIdString, 0)
assetTypeScript = azlmbr.math.Uuid_CreateString('{82557326-4AE3-416C-95D6-C70635AB7588}', 0)
handler = None
jobKeyPrefix = 'Foo Job Key'
targetAssetFolder = 'foo_scripts'
# creates a single job to compile for a 'pc' platform
def on_create_jobs(args):
request = args[0] # azlmbr.asset.builder.CreateJobsRequest
response = azlmbr.asset.builder.CreateJobsResponse()
# note: if the asset builder is going to handle more than one file pattern it might need to check out
# the request.sourceFile to figure out what jobs need to be created
jobDescriptorList = []
for platformInfo in request.enabledPlatforms:
# for each enabled platform like 'pc' or 'ios'
platformId = platformInfo.identifier
# set up unique job key
jobKey = '{} {}'.format(jobKeyPrefix, platformId)
# create job descriptor
jobDesc = azlmbr.asset.builder.JobDescriptor()
jobDesc.jobKey = jobKey
jobDesc.set_platform_identifier(platformId)
jobDescriptorList.append(jobDesc)
print ('created a job for {} with key {}'.format(platformId, jobKey))
response.createJobOutputs = jobDescriptorList
response.result = azlmbr.asset.builder.CreateJobsResponse_ResultSuccess
return response
def get_target_name(sourceFullpath):
lua_file = os.path.basename(sourceFullpath)
lua_file = os.path.splitext(lua_file)[0]
lua_file = lua_file + '.lua'
return lua_file
def copy_foo_file(srcFile, dstFile):
try:
dir_name = os.path.dirname(dstFile)
if (os.path.exists(dir_name) is False):
os.makedirs(dir_name)
shutil.copyfile(srcFile, dstFile)
return True
except:
return False
# using the incoming 'request' find the type of job via 'jobKey' to determine what to do
def on_process_job(args):
request = args[0] # azlmbr.asset.builder.ProcessJobRequest
response = azlmbr.asset.builder.ProcessJobResponse()
# note: if possible to loop through incoming data a 'yeild' can be used to cooperatively
# thread the processing of the assets so that shutdown and cancel can be handled
if (request.jobDescription.jobKey.startswith(jobKeyPrefix)):
targetFile = os.path.join(targetAssetFolder, get_target_name(request.fullPath))
dstFile = os.path.join(request.tempDirPath, targetFile)
if (copy_foo_file(request.fullPath, dstFile)):
response.outputProducts = [azlmbr.asset.builder.JobProduct(dstFile, assetTypeScript, 0)]
response.resultCode = azlmbr.asset.builder.ProcessJobResponse_Success
response.dependenciesHandled = True
return response
def on_shutdown(args):
# note: user should attempt to close down any processing job if any running
global handler
if (handler is not None):
handler.disconnect()
handler = None
def on_cancel_job(args):
# note: user should attempt to close down any processing job if any running
print('>>> FOO asset builder - on_cancel_job <<<')
# register asset builder for source assets
def register_asset_builder():
assetPattern = azlmbr.asset.builder.AssetBuilderPattern()
assetPattern.pattern = '*.foo'
assetPattern.type = azlmbr.asset.builder.AssetBuilderPattern_Wildcard
builderDescriptor = azlmbr.asset.builder.AssetBuilderDesc()
builderDescriptor.name = "Foo Asset Builder"
builderDescriptor.patterns = [assetPattern]
builderDescriptor.busId = busId
builderDescriptor.version = 0
outcome = azlmbr.asset.builder.PythonAssetBuilderRequestBus(azlmbr.bus.Broadcast, 'RegisterAssetBuilder', builderDescriptor)
if outcome.IsSuccess():
# created the asset builder handler to hook into the notification bus
jobHandler = azlmbr.asset.builder.PythonBuilderNotificationBusHandler()
jobHandler.connect(busId)
jobHandler.add_callback('OnCreateJobsRequest', on_create_jobs)
jobHandler.add_callback('OnProcessJobRequest', on_process_job)
jobHandler.add_callback('OnShutdown', on_shutdown)
jobHandler.add_callback('OnCancel', on_cancel_job)
return jobHandler
# note: the handler has to be retained since Python retains the object ref count
# on_shutdown will clear the 'handler' to disconnect from the notification bus
handler = register_asset_builder()