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,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.
#
if(NOT PAL_TRAIT_BUILD_HOST_TOOLS)
return()
endif()
ly_add_target(
NAME PythonBindingsExample.Static STATIC
NAMESPACE AZ
FILES_CMAKE
pythonbindingsexample_files.cmake
PLATFORM_INCLUDE_FILES
source/Platform/Common/${PAL_TRAIT_COMPILER_ID}/pythonbindingsexample_${PAL_TRAIT_COMPILER_ID_LOWERCASE}.cmake
INCLUDE_DIRECTORIES
PRIVATE
.
BUILD_DEPENDENCIES
PRIVATE
AZ::AzCore
AZ::AzFramework
AZ::AzToolsFramework
)
ly_add_target(
NAME PythonBindingsExample EXECUTABLE
NAMESPACE AZ
FILES_CMAKE
pythonbindingsexample_app_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
.
BUILD_DEPENDENCIES
PRIVATE
AZ::AzCore
AZ::AzFramework
AZ::AzToolsFramework
PythonBindingsExample.Static
)
# The PythonBindingsExample application isn't really an LY_PROJECT,
# It's target name is being used to tag the tool_dependencies
# This allows both the PythonBindingsExample and PythonBindingsExample.Tests applications
# to load the generated cmake_dependencies.PythonBindingsExample.PythonBindingsExample.setreg file
# which contains the list of gem dependencies
ly_add_target_dependencies(
TARGETS
PythonBindingsExample
DEPENDENCIES_FILES
tool_dependencies.cmake
)
# Adds the PythonBindingsExample as a C preprocessor define so that it can be used as a Settings Registry
# specialization in order to look up the generated .setreg which contains the dependencies
# specified for the target
if(TARGET PythonBindingsExample)
set_source_files_properties(
source/main.cpp
PROPERTIES
COMPILE_DEFINITIONS
LY_CMAKE_TARGET="PythonBindingsExample"
)
else()
message(FATAL_ERROR "Cannot set LY_CMAKE_TARGET define to PythonBindingsExample as the target doesn't exist anymore."
" Perhaps it has been renamed")
endif()
if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
ly_add_target(
NAME PythonBindingsExample.Tests EXECUTABLE
NAMESPACE AZ
FILES_CMAKE
pythonbindingsexample_tests_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
.
BUILD_DEPENDENCIES
PRIVATE
AZ::AzCore
AZ::AzFramework
AZ::AzTest
AZ::AzToolsFramework
PythonBindingsExample.Static
)
ly_add_target_dependencies(
TARGETS
PythonBindingsExample.Tests
DEPENDENCIES_FILES
tool_dependencies.cmake
)
if(TARGET PythonBindingsExample)
set_source_files_properties(
tests/ApplicationTests.cpp
PROPERTIES
COMPILE_DEFINITIONS
# The PythonBindingsExample target is being defined here to allow the PythonBindingsExample.Tests executable
# to load the specializations which contains the "PythonBindingsExample" value'
LY_CMAKE_TARGET="PythonBindingsExample"
)
else()
message(FATAL_ERROR "Cannot set LY_CMAKE_TARGET define to PythonBindingsExample as the target doesn't exist anymore."
" Perhaps it has been renamed")
endif()
ly_add_googletest(
NAME AZ::PythonBindingsExample.Tests
TEST_COMMAND $<TARGET_FILE:AZ::PythonBindingsExample.Tests>
)
endif()
@@ -0,0 +1,14 @@
#
# 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.
#
set(FILES
source/main.cpp
)
@@ -0,0 +1,18 @@
#
# 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.
#
set(FILES
source/Application.h
source/Application.cpp
source/ApplicationParameters.h
source/ApplicationParameters.cpp
tool_dependencies.cmake
)
@@ -0,0 +1,15 @@
#
# 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.
#
set(FILES
tests/ApplicationTests.cpp
tests/TestMain.cpp
)
@@ -0,0 +1,278 @@
/*
* 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 <source/Application.h>
#include <source/ApplicationParameters.h>
#include <AzCore/IO/FileIO.h>
#include <AzCore/StringFunc/StringFunc.h>
#include <AzFramework/CommandLine/CommandRegistrationBus.h>
#include <AzToolsFramework/API/EditorPythonRunnerRequestsBus.h>
#include <AzToolsFramework/Asset/AssetUtils.h>
#include <iostream>
#include <string>
namespace PythonBindingsExample
{
//////////////////////////////////////////////////////////////////////////
// Application
Application::Application(int* argc, char*** argv)
: AzToolsFramework::ToolsApplication(argc, argv)
{
}
Application::~Application()
{
TearDown();
}
void Application::SetUp()
{
AZ::Debug::TraceMessageBus::Handler::BusConnect();
AzToolsFramework::EditorPythonConsoleNotificationBus::Handler::BusConnect();
// prepare the Python binding gem(s)
CalculateExecutablePath();
Start(Descriptor());
AZ::SerializeContext* context;
EBUS_EVENT_RESULT(context, AZ::ComponentApplicationBus, GetSerializeContext);
AZ_Assert(context, "Application did not start; detected no serialize context");
AZ_TracePrintf("Python Bindings", "Init() \n");
}
void Application::TearDown()
{
StopPythonVM();
m_showVerboseOutput = false;
AzToolsFramework::EditorPythonConsoleNotificationBus::Handler::BusDisconnect();
AZ::Debug::TraceMessageBus::Handler::BusDisconnect();
Stop();
}
void Application::StartPythonVM()
{
auto&& editorPythonEventsInterface = AZ::Interface<AzToolsFramework::EditorPythonEventsInterface>::Get();
if (editorPythonEventsInterface)
{
// already started?
if (m_startedPython == false)
{
m_startedPython = editorPythonEventsInterface->StartPython();
AZ_Error("python_app", m_startedPython, "Python VM did not start.");
}
}
}
void Application::StopPythonVM()
{
auto&& editorPythonEventsInterface = AZ::Interface<AzToolsFramework::EditorPythonEventsInterface>::Get();
if (editorPythonEventsInterface && m_startedPython)
{
editorPythonEventsInterface->StopPython();
m_startedPython = false;
}
else if (m_showVerboseOutput)
{
AZ_Warning("python_app", false, "Python interface could not be stopped.");
}
}
bool Application::Run()
{
ApplicationParameters params;
if (params.Parse(GetCommandLine()))
{
return RunWithParameters(params);
}
return false;
}
bool Application::RunWithParameters(const ApplicationParameters& params)
{
using namespace AzFramework;
using namespace AzToolsFramework;
m_showVerboseOutput = params.m_verbose;
auto&& editorPythonEventsInterface = AZ::Interface<EditorPythonEventsInterface>::Get();
if (editorPythonEventsInterface)
{
try
{
StartPythonVM();
if (!m_startedPython)
{
AZ_Error("python_app", false, "Python VM did not start.");
return false;
}
if (params.m_pythonStatement.empty() == false)
{
EditorPythonRunnerRequestBus::Broadcast(
&EditorPythonRunnerRequestBus::Events::ExecuteByString,
params.m_pythonStatement,
params.m_verbose);
}
if (params.m_pythonFilename.empty() == false)
{
if (m_pythonExceptionCount == 0)
{
RunFileWithArgs(params);
}
else
{
AZ_Warning("python_app", false, "Did not execute script file since statement threw exceptions.");
}
}
const bool errorFree = (m_pythonExceptionCount == 0) && (m_pythonErrorCount == 0);
if (errorFree && params.m_interactiveMode)
{
AZSTD_PRINTF("Interactive mode enabled \n");
std::string statement;
bool executeStatement = false;
do
{
AZSTD_PRINTF("> ");
std::getline(std::cin, statement);
executeStatement = (statement.empty() == false);
if (executeStatement)
{
EditorPythonRunnerRequestBus::Broadcast(
&EditorPythonRunnerRequestBus::Events::ExecuteByString,
statement.c_str(),
params.m_verbose);
}
}
while (executeStatement);
}
if (errorFree == false)
{
AZ_Warning("python_app", false, "Encountered %d exceptions and %d errors", m_pythonExceptionCount, m_pythonErrorCount);
}
return errorFree;
}
catch (const std::exception& e)
{
OnExceptionMessage(e.what());
}
}
else
{
AZ_Error("python_app", false, "Python interface missing. "
"This likely means that the project has not enabled the EditorPythonBindings gem.");
}
return false;
}
bool Application::RunFileWithArgs(const ApplicationParameters& params)
{
using namespace AzFramework;
using namespace AzToolsFramework;
AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance();
if (fileIO->Exists(params.m_pythonFilename.c_str()) == false)
{
AZ_Error("python_app", false, "Python file (%s) is missing.", params.m_pythonFilename.c_str());
return false;
}
AZStd::vector<AZStd::string_view> pythonArgs;
pythonArgs.reserve(params.m_pythonArgs.size());
for(auto&& arg : params.m_pythonArgs)
{
pythonArgs.push_back(arg);
}
AZStd::transform(params.m_pythonArgs.begin(), params.m_pythonArgs.end(), pythonArgs.begin(), [](auto&& arg)
{
return arg.c_str();
});
EditorPythonRunnerRequestBus::Broadcast(
&EditorPythonRunnerRequestBus::Events::ExecuteByFilenameWithArgs,
params.m_pythonFilename,
pythonArgs);
return m_pythonExceptionCount == 0;
}
bool Application::OnPreError(const char* window, const char* fileName, int line, [[maybe_unused]] const char* func, const char* message)
{
printf("\n");
printf("[ERROR] - %s:\n", window);
if (m_showVerboseOutput)
{
printf("(%s - Line %i)\n", fileName, line);
}
printf("%s \n", message);
return true;
}
bool Application::OnPreWarning(const char* window, const char* fileName, int line, [[maybe_unused]] const char* func, const char* message)
{
// remove the warnings about the command line options from AZ::Console
if (AZ::StringFunc::Equal(window, "Az Console"))
{
return true;
}
printf("\n");
printf("[WARN] - %s:\n", window);
if (m_showVerboseOutput)
{
printf("(%s - Line %i)\n", fileName, line);
}
printf("%s \n", message);
return true;
}
bool Application::OnPrintf([[maybe_unused]] const char* window, const char* message)
{
if (m_showVerboseOutput)
{
printf("%s\n", message);
return true;
}
return !m_showVerboseOutput;
}
void Application::OnTraceMessage(AZStd::string_view message)
{
if (m_showVerboseOutput)
{
printf("(python) %.*s \n", aznumeric_cast<int>(message.size()), message.data());
}
}
void Application::OnErrorMessage(AZStd::string_view message)
{
++m_pythonErrorCount;
printf("(python) [ERROR] %.*s \n", aznumeric_cast<int>(message.size()), message.data());
}
void Application::OnExceptionMessage(AZStd::string_view message)
{
++m_pythonExceptionCount;
printf("(python) [EXCEPTION] %.*s \n", aznumeric_cast<int>(message.size()), message.data());
}
}
@@ -0,0 +1,60 @@
/*
* 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 <AzCore/Debug/TraceMessageBus.h>
#include <AzToolsFramework/Application/ToolsApplication.h>
#include <AzToolsFramework/API/EditorPythonConsoleBus.h>
namespace PythonBindingsExample
{
struct ApplicationParameters;
class Application
: public AzToolsFramework::ToolsApplication
, protected AZ::Debug::TraceMessageBus::Handler
, protected AzToolsFramework::EditorPythonConsoleNotificationBus::Handler
{
public:
Application(int* argc, char*** argv);
~Application();
void SetUp();
bool Run();
void TearDown();
bool RunWithParameters(const ApplicationParameters& params);
protected:
////////////////////////////////////////////////////////////////////////////////////////////
// TraceMessageBus
bool OnPreError(const char* window, const char* fileName, int line, const char* func, const char* message) override;
bool OnPreWarning(const char* window, const char* fileName, int line, const char* func, const char* message) override;
bool OnPrintf(const char* window, const char* message) override;
////////////////////////////////////////////////////////////////////////////////////////////
// AzToolsFramework::EditorPythonConsoleNotifications
void OnTraceMessage(AZStd::string_view message) override;
void OnErrorMessage(AZStd::string_view message) override;
void OnExceptionMessage(AZStd::string_view message) override;
bool RunFileWithArgs(const ApplicationParameters& params);
void StartPythonVM();
void StopPythonVM();
protected:
bool m_showVerboseOutput = false;
bool m_startedPython = false;
int m_pythonExceptionCount = 0;
int m_pythonErrorCount = 0;
};
}
@@ -0,0 +1,76 @@
/*
* 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 <source/ApplicationParameters.h>
#include <AzCore/Settings/CommandLine.h>
#include <AzToolsFramework/Application/ToolsApplication.h>
namespace PythonBindingsExample
{
void ApplicationParameters::ShowHelp()
{
constexpr const char* helpText =
R"(PythonBindingsExample - An example of how to bind the Behavior Context in a simple Tools Application
PythonBindingsExample.exe --file path/to/file.py --arg one --arg two
--help Prints the help text
--verbose (v) Uses verbose output
--file (f) Execute this Python script file
--arg (a) Any number of args sent to the Python script
--interactive (i) Run in interactive mode after file and/or statement (note: enable --verbose to get Python output)
--statement (s) Run Python string statement)";
puts(helpText);
}
bool ApplicationParameters::Parse(const AzFramework::CommandLine* commandLine)
{
if (commandLine->GetSwitchList().empty())
{
ShowHelp();
return false;
}
auto&& switchList = commandLine->GetSwitchList();
for (auto&& switchItem : switchList)
{
if (switchItem.first == "help")
{
ShowHelp();
return false;
}
else if (switchItem.first.starts_with('v'))
{
m_verbose = true;
}
else if (switchItem.first.starts_with('f'))
{
m_pythonFilename = switchItem.second[0];
}
else if (switchItem.first.starts_with('a'))
{
m_pythonArgs.push_back(switchItem.second[0]);
}
else if (switchItem.first.starts_with('s'))
{
m_pythonStatement = switchItem.second[0];
}
else if (switchItem.first.starts_with('i'))
{
m_interactiveMode = true;
}
else
{
AZ_Warning("python_app", false, "Unknown switch %s \n", switchItem.first.c_str());
}
}
return true;
}
}
@@ -0,0 +1,39 @@
/*
* 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 <AzCore/std/containers/vector.h>
#include <AzCore/std/string/string.h>
namespace AZ
{
class CommandLine;
}
namespace PythonBindingsExample
{
struct ApplicationParameters final
{
bool Parse(const AZ::CommandLine* commandLine);
// the arguments
using StringList = AZStd::vector<AZStd::string>;
bool m_verbose = false;
AZStd::string m_pythonFilename;
StringList m_pythonArgs;
AZStd::string m_pythonStatement;
bool m_interactiveMode = false;
protected:
void ShowHelp();
};
}
@@ -0,0 +1,15 @@
#
# 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.
#
set(LY_COMPILE_OPTIONS
PRIVATE
-fexceptions
)
@@ -0,0 +1,15 @@
#
# 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.
#
set(LY_COMPILE_OPTIONS
PUBLIC
/EHsc
)
@@ -0,0 +1,43 @@
/*
* 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 <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <source/Application.h>
namespace PythonBindingsExample
{
//! This function returns the build system target name
AZStd::string_view GetBuildTargetName()
{
#if !defined (LY_CMAKE_TARGET)
#error "LY_CMAKE_TARGET must be defined in order to add this source file to a CMake executable target"
#endif
return AZStd::string_view{ LY_CMAKE_TARGET };
}
}
int main(int argc, char* argv[])
{
AZ::AllocatorInstance<AZ::SystemAllocator>::Create();
int runSuccess = 0;
{
PythonBindingsExample::Application application(&argc, &argv);
// The AZ::ComponentApplication constructor creates the settings registry
// so the CMake target name can be added at this point
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddBuildSystemTargetSpecialization(
*AZ::SettingsRegistry::Get(), PythonBindingsExample::GetBuildTargetName());
application.SetUp();
runSuccess = application.Run() ? 0 : 1;
}
AZ::AllocatorInstance<AZ::SystemAllocator>::Destroy();
return runSuccess;
}
@@ -0,0 +1,98 @@
/*
* 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 <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <source/Application.h>
#include <source/ApplicationParameters.h>
namespace PythonBindingsExample
{
//! This function returns the build system target name
AZStd::string_view GetBuildTargetName()
{
#if !defined (LY_CMAKE_TARGET)
#error "LY_CMAKE_TARGET must be defined in order to add this source file to a CMake executable target"
#endif
return AZStd::string_view{ LY_CMAKE_TARGET };
}
class PythonBindingsExampleTest
: public ::testing::Test
, public ::UnitTest::AllocatorsBase
{
public:
static void SetUpTestCase()
{
if (!AZ::AllocatorInstance<AZ::SystemAllocator>::IsReady())
{
AZ::AllocatorInstance<AZ::SystemAllocator>::Create();
}
s_application = AZStd::make_unique<PythonBindingsExample::Application>(nullptr, nullptr);
// The AZ::ComponentApplication constructor creates the settings registry
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddBuildSystemTargetSpecialization(
*AZ::SettingsRegistry::Get(), GetBuildTargetName());
s_application->SetUp();
}
static void TearDownTestCase()
{
s_application->TearDown();
s_application.reset();
if (AZ::AllocatorInstance<AZ::SystemAllocator>::IsReady())
{
AZ::AllocatorInstance<AZ::SystemAllocator>::Destroy();
}
}
static AZStd::unique_ptr<PythonBindingsExample::Application> s_application;
};
AZStd::unique_ptr<PythonBindingsExample::Application> PythonBindingsExampleTest::s_application;
TEST_F(PythonBindingsExampleTest, Application_Run_Fails)
{
EXPECT_FALSE(s_application->Run());
}
TEST_F(PythonBindingsExampleTest, Application_RunWithParameters_Works)
{
ApplicationParameters params;
EXPECT_TRUE(s_application->RunWithParameters(params));
}
TEST_F(PythonBindingsExampleTest, Application_ImportSys_Works)
{
ApplicationParameters params;
params.m_pythonStatement = "import sys";
EXPECT_TRUE(s_application->RunWithParameters(params));
}
TEST_F(PythonBindingsExampleTest, Application_ImportAzLmbr_Works)
{
ApplicationParameters params;
params.m_pythonStatement = "import azlmbr";
EXPECT_TRUE(s_application->RunWithParameters(params));
}
TEST_F(PythonBindingsExampleTest, Application_ImportAzLmbrPaths_Works)
{
ApplicationParameters params;
params.m_pythonStatement = "import azlmbr.paths; print (azlmbr.paths.engroot); print (azlmbr.paths.devroot)";
EXPECT_TRUE(s_application->RunWithParameters(params));
}
}
@@ -0,0 +1,44 @@
/*
* 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 <AzFramework/Platform/PlatformDefaults.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzTest/AzTest.h>
#include <AzTest/Utils.h>
#include <AzTest/AzTest.h>
DECLARE_AZ_UNIT_TEST_MAIN();
int runDefaultRunner(int argc, char* argv[])
{
INVOKE_AZ_UNIT_TEST_MAIN(nullptr);
return 0;
}
int main(int argc, char* argv[])
{
// ran with no parameters?
if (argc == 1)
{
constexpr int defaultArgc = 2;
char unittest_arg[] = "--unittests"; // Conversion from string literal to char* is not allowed per ISO C++11
char* defaultArgv[defaultArgc] =
{
argv[0],
unittest_arg
};
return runDefaultRunner(defaultArgc, defaultArgv);
}
INVOKE_AZ_UNIT_TEST_MAIN(nullptr);
return 0;
}
@@ -0,0 +1,62 @@
@echo off
REM
REM All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
REM its licensors.
REM
REM For complete copyright and license terms please see the LICENSE at the root of this
REM distribution (the "License"). All use of this software is governed by the License,
REM or, if provided, by the license below or the license accompanying this file. Do not
REM remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM
PUSHD "%~dp0"
SET CWD="%~dp0"
SET EXEPATH141="../../../../Bin64vc141/PythonBindingsExample.exe"
SET EXEPATH142="../../../../Bin64vc142/PythonBindingsExample.exe"
SET EXEPATH=""
IF EXIST %EXEPATH141% (
SET EXEPATH=%EXEPATH141%
) ELSE (
IF EXIST %EXEPATH142% (
SET EXEPATH=%EXEPATH142%
) ELSE (
ECHO PythonBindingsExample.exe not found.
)
)
IF /I %EXEPATH% EQU "" (
ECHO [FAILED] Could not run tests since a build of PythonBindingsExample.exe is missing
GOTO exit_app
)
ECHO Testing basics of tool Python bindings in %CWD%
%EXEPATH% --file test_hello_tool.py
IF %ERRORLEVEL% EQU 0 (
ECHO [WORKED] test_hello_tool.py
) ELSE (
ECHO [FAILED] test_hello_tool.py with %ERRORLEVEL%
GOTO exit_app
)
%EXEPATH% --file test_framework.py --arg entity
IF %ERRORLEVEL% EQU 0 (
ECHO [WORKED] test_framework.py --arg entity
) ELSE (
ECHO [FAILED] test_framework.py --arg entity with %ERRORLEVEL%
GOTO exit_app
)
%EXEPATH% --file test_framework.py --arg math
IF %ERRORLEVEL% EQU 0 (
ECHO [WORKED] test_framework.py --arg math
) ELSE (
ECHO [FAILED] test_framework.py --arg math with %ERRORLEVEL%
GOTO exit_app
)
:exit_app
POPD
@@ -0,0 +1,50 @@
"""
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.
"""
print ('Testing framework Python bindings')
import azlmbr.entity as entity
import azlmbr.framework as framework
import azlmbr.math as math
def test_entity_api():
entityId = entity.EntityId()
if (entityId.IsValid is None):
print('entityId.IsValid is None')
framework.Terminate(1)
if (entityId.IsValid() is True):
print('entityId.IsValid() is True')
framework.Terminate(2)
def test_math_api():
if (math.Math_IsEven(3)):
framework.Terminate(1)
if (math.Math_IsClose(1.0,2.0)):
framework.Terminate(2)
if (math.Math_IsClose(2.0, math.Math_Sqrt(4.0)) is False):
framework.Terminate(3)
def main():
import sys
print("Starting framework test")
if (sys.argv[1] == 'entity'):
test_entity_api()
elif (sys.argv[1] == 'math'):
test_math_api()
else:
print('Unknown arg {}'.format(sys.argv[0]))
framework.Terminate(4)
if __name__ == "__main__":
main()
@@ -0,0 +1,12 @@
"""
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.
"""
import azlmbr
print ('Able to load azlmbr module.')
@@ -0,0 +1,14 @@
#
# 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.
#
set(GEM_DEPENDENCIES
Gem::EditorPythonBindings.Editor
)