Browse Source

Removed the Python SerializeContextTools smoke test (#13453)

Registered a C++ SerializeContextTools test that validates the `--help`
argument.

Fixed the logic in ly_add_target to associate the `AZ_TEST_EXECUTABLE`
define with an executable target that depends on AzTests.

Signed-off-by: lumberyard-employee-dm <[email protected]>

Signed-off-by: lumberyard-employee-dm <[email protected]>
lumberyard-employee-dm 2 years ago
parent
commit
4b25534ccf

+ 0 - 3
AutomatedTesting/Gem/PythonTests/smoke/CMakeLists.txt

@@ -7,9 +7,6 @@
 
 if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS)
 
-    set(SMOKETEST_FILTER "SUITE_smoke and not SerializeContext")
-
-    list(APPEND additional_dependencies AZ::SerializeContextTools) # test_CLITool_SerializeContextTools depends on it
     set(SMOKETEST_FILTER "SUITE_smoke")
 
     ly_add_pytest(

+ 0 - 28
AutomatedTesting/Gem/PythonTests/smoke/test_CLITool_SerializeContextTools_Works.py

@@ -1,28 +0,0 @@
-"""
-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
-
-
-CLI tool - SerializeContextTools
-Launch SerializeContextTools and Verify the help message
-"""
-
-import os
-import pytest
-import subprocess
-
-import ly_test_tools
-
-
[email protected]
[email protected]_smoke
-class TestCLIToolSerializeContextToolsWorks(object):
-    def test_CLITool_SerializeContextTools_Works(self, build_directory):
-        file_path = os.path.join(build_directory, "SerializeContextTools")
-        # Launch SerializeContextTools
-        output = subprocess.run([file_path, "--help"], capture_output=True, timeout=10)
-        assert (
-            (len(output.stdout) > 0 or len(output.stderr) > 0) and output.returncode == 0
-        ), f"Error occurred while launching {file_path}: {output.stdout}"

+ 40 - 0
Code/Tools/SerializeContextTools/CMakeLists.txt

@@ -10,6 +10,21 @@ if (NOT PAL_TRAIT_BUILD_HOST_TOOLS)
     return()
 endif()
 
+ly_add_target(
+    NAME SerializeContextTools.Object OBJECT
+    NAMESPACE AZ
+    FILES_CMAKE
+        serializecontexttools_object_files.cmake
+    INCLUDE_DIRECTORIES
+        PUBLIC
+            .
+    BUILD_DEPENDENCIES
+        PRIVATE
+            AZ::AzCore
+            AZ::AzFramework
+            AZ::AzToolsFramework
+)
+
 ly_add_target(
     NAME SerializeContextTools EXECUTABLE
     NAMESPACE AZ
@@ -23,4 +38,29 @@ ly_add_target(
             AZ::AzCore
             AZ::AzFramework
             AZ::AzToolsFramework
+            $<TARGET_OBJECTS:SerializeContextTools.Object>
 )
+
+if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
+    ly_add_target(
+        NAME SerializeContextTools.Tests EXECUTABLE
+        NAMESPACE AZ
+        FILES_CMAKE
+            serializecontexttools_tests_files.cmake
+        INCLUDE_DIRECTORIES
+            PRIVATE
+                .
+        BUILD_DEPENDENCIES
+            PRIVATE
+                AZ::AzCore
+                AZ::AzFramework
+                AZ::AzToolsFramework
+                AZ::AzTest
+                $<TARGET_OBJECTS:SerializeContextTools.Object>
+    )
+
+    ly_add_googletest(
+        NAME AZ::SerializeContextTools.Tests
+        TEST_COMMAND $<TARGET_FILE:AZ::SerializeContextTools.Tests> AzRunUnitTests
+    )
+endif()

+ 203 - 0
Code/Tools/SerializeContextTools/Runner.cpp

@@ -0,0 +1,203 @@
+/*
+ * 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 <AzCore/Console/IConsole.h>
+#include <AzCore/Debug/Trace.h>
+#include <AzCore/IO/SystemFile.h>
+#include <AzCore/StringFunc/StringFunc.h>
+#include <AzCore/Settings/CommandLine.h>
+#include <Application.h>
+#include <Converter.h>
+#include <Dumper.h>
+#include <SliceConverter.h>
+
+namespace SerializeContextTools
+{
+    void PrintHelp()
+    {
+        AZ_Printf("Help", "Serialize Context Tool\n");
+        AZ_Printf("Help", "  <action> [-config] [misc options] <action arguments>*\n");
+        AZ_Printf("Help", "  [opt] -config=<path>: optional path to application's config file. Default is 'config/editor.xml'.\n");
+        AZ_Printf("Help", "  [opt] -specializations=<prefix>: <comma or semicolon>-separated list of optional Registry project\n");
+        AZ_Printf("Help", "         specializations, such as 'editor' or 'game' or 'editor;test'.  Default is none. \n");
+        AZ_Printf("Help", "\n");
+        AZ_Printf("Help", "  'help': Print this help\n");
+        AZ_Printf("Help", "    example: 'help'\n");
+        AZ_Printf("Help", "\n");
+        AZ_Printf("Help", "  'dumpfiles': Dump the content to a .dump.txt file next to the original file.\n");
+        AZ_Printf("Help", "    [arg] -files=<path>: ;-separated list of files to verify. Supports wildcards.\n");
+        AZ_Printf("Help", "    [opt] -output=<path>: Path to the folder to write to instead of next to the original file.\n");
+        AZ_Printf("Help", "    example: 'dumpfiles -files=folder/*.ext;a.ext;folder/another/z.ext'\n");
+        AZ_Printf("Help", "\n");
+        AZ_Printf("Help", "  'dumpsc': Dump the content of the Serialize and Edit Context to a JSON file.\n");
+        AZ_Printf("Help", "    [opt] -output=<path>: Path to the folder to write to instead of next to the original file.\n");
+        AZ_Printf("Help", "    example: 'dumpsc -output=../TargetFolder/SerializeContext.json'\n");
+        AZ_Printf("Help", "\n");
+        AZ_Printf("Help", "  'dumptypes': Dump the list of reflected types to stdout or a file.\n");
+        AZ_Printf("Help", "    [opt] --sort=<WORD> : Sorts the reflected type by <WORD> where word can be one of the following values.\n");
+        AZ_Printf("Help", R"(          "name", "typeid", "none")" "\n")
+        AZ_Printf("Help", "          sorts by name if not specified .\n");
+        AZ_Printf("Help", "    [opt] --output-file=<filepath>: Path to the file to output reflected types.\n");
+        AZ_Printf("Help", "          If not specfied, output is written to stdout.\n");
+        AZ_Printf("Help", R"(    example: 'dumptypes')" "\n");
+        AZ_Printf("Help", R"(    example: 'dumptypes --sort=typeid)" "\n");
+        AZ_Printf("Help", R"(    example: 'dumptypes --output-file=reflectedtypes.txt)" "\n");
+        AZ_Printf("Help", "\n");
+        AZ_Printf("Help", "  'convert': Converts a file with an ObjectStream to the new JSON formats.\n");
+        AZ_Printf("Help", "    [arg] -files=<path>: <comma or semicolon>-separated list of files to verify. Supports wildcards.\n");
+        AZ_Printf("Help", "    [arg] -ext=<string>: Extension to use for the new file.\n");
+        AZ_Printf("Help", "    [opt] -dryrun: Processes as normal, but doesn't write files.\n");
+        AZ_Printf("Help", "    [opt] -skipverify: After conversion the result will not be compared to the original.\n");
+        AZ_Printf("Help", "    [opt] -keepdefaults: Fields are written if a default value was found.\n");
+        AZ_Printf("Help", "    [opt] -json-prefix=<prefix>: JSON pointer path prefix to anchor the JSON output underneath.\n");
+        AZ_Printf("Help", "           On Windows the <prefix> should be in quotes, as \"/\" is treated as command option prefix\n");
+        AZ_Printf("Help", "    [opt] -json-prefix=prefix: Json pointer path prefix to use as a \"root\" for settings.\n");
+        AZ_Printf("Help", "    [opt] -verbose: Report additional details during the conversion process.\n");
+        AZ_Printf("Help", "    example: 'convert -file=*.slice;*.uislice -ext=slice2'\n");
+        AZ_Printf("Help", "\n");
+        AZ_Printf("Help", R"(  'convert-ini': Converts windows-style INI file to a json format file.)" "\n");
+        AZ_Printf("Help", R"(                 The converted file is suitable for being loaded into the Settings Registry.)" "\n");
+        AZ_Printf("Help", R"(                 Can be used to convert .cfg/.ini files.)" "\n");
+        AZ_Printf("Help", R"(    [arg] -files=<path...>: <comma or semicolon>-separated list of files to verify. Supports wildcards.)" "\n");
+        AZ_Printf("Help", R"(    [opt] -ext=<string>: Extension to use for the new files. default=setreg)" "\n");
+        AZ_Printf("Help", R"(    [opt] -dryrun: Processes as normal, but doesn't write files.)" "\n");
+        AZ_Printf("Help", R"(    [opt] -json-prefix=<prefix>: JSON pointer path prefix to anchor the JSON output underneath.)" "\n");
+        AZ_Printf("Help", R"(           On Windows the <prefix> should be in quotes, as \"/\" is treated as command option prefix)" "\n");
+        AZ_Printf("Help", R"(    [opt] -verbose: Report additional details during the conversion process.)" "\n");
+        AZ_Printf("Help", R"(    example: 'convert-ini --files=AssetProcessorPlatformConfig.ini;bootstrap.cfg --ext=setreg)" "\n");
+        AZ_Printf("Help", "  'convert-slice': Converts ObjectStream-based slice files or legacy levels to a JSON-based prefab.\n");
+        AZ_Printf("Help", "    [arg] -files=<path>: <comma or semicolon>-separated list of files to convert. Supports wildcards.\n");
+        AZ_Printf("Help", "    [opt] -dryrun: Processes as normal, but doesn't write files.\n");
+        AZ_Printf("Help", "    [opt] -keepdefaults: Fields are written if a default value was found.\n");
+        AZ_Printf("Help", "    [opt] -verbose: Report additional details during the conversion process.\n");
+        AZ_Printf("Help", "    example: 'convert-slice -files=*.slice -specializations=editor\n");
+        AZ_Printf("Help", "    example: 'convert-slice -files=Levels/TestLevel/TestLevel.ly -specializations=editor\n");
+        AZ_Printf("Help", "\n");
+        AZ_Printf("Help", "  'createtype': Create a default constructed object using Json Serialization and output the contents.\n");
+        AZ_Printf("Help", "    [arg] --type-name=<string>: Name of type to construct and output.\n");
+        AZ_Printf("Help", "          The type must be registered with the Json Registration or Serialize Context.\n");
+        AZ_Printf("Help", "          Cannot be specified with the -type-id parameter.\n");
+        AZ_Printf("Help", "    [arg] --type-id=<uuid>: Uuid of type to construct and output.\n");
+        AZ_Printf("Help", "          The type must be registered with the Json Registration or Serialize Context.\n");
+        AZ_Printf("Help", "          Cannot be specified with the -type-name parameter.\n");
+        AZ_Printf("Help", "    [opt] --output-file=<filepath>: Path to the file to output constructed object.\n");
+        AZ_Printf("Help", "          If not supplied, output is written to stdout.\n");
+        AZ_Printf("Help", R"(    [opt] --json-prefix=<prefix>: JSON pointer path prefix to anchor the JSON output underneath.)" "\n");
+        AZ_Printf("Help", R"(    example: 'createtype --type-name="AZ::Entity"')" "\n");
+        AZ_Printf("Help", R"(    example: 'createtype --type-id="{75651658-8663-478D-9090-2432DFCAFA44}"')" "\n");
+        AZ_Printf("Help", R"(    example: 'createtype --type-name="AZ::Entity" --json-prefix="/My/Anchor"')" "\n");
+        AZ_Printf("Help", R"(    example: 'createtype --type-name="AZ::Entity" --output-file=object.json)" "\n");
+        AZ_Printf("Help", "\n");
+        AZ_Printf("Help", "  Miscellaneous Options:\n");
+        AZ_Printf("Help", "  This options can be used with any of the above actions:\n");
+        AZ_Printf("Help", "    [opt] --regset <setreg_key>=<setreg_value>: Set setreg_value at key setreg_key within the settings registry.\n");
+        AZ_Printf("Help", "    [opt] --project-path <project_path>: Sets the path to the active project. Used to load gems associated with project\n");
+    }
+
+    int LaunchSerializeContextTools(int argc, char** argv)
+    {
+        using namespace AZ::SerializeContextTools;
+
+        const AZ::Debug::Trace tracer;
+        constexpr int StdoutDescriptor = 1;
+        AZ::IO::FileDescriptorCapturer stdoutCapturer(StdoutDescriptor);
+
+        // Send stdout output to stderr if the executed command returned a failure
+        bool suppressStderr = false;
+        auto SendStdoutToError = [&suppressStderr](AZStd::span<AZStd::byte const> outputBytes)
+        {
+            if (!suppressStderr)
+            {
+                constexpr int StderrDescriptor = 2;
+                AZ::IO::PosixInternal::Write(StderrDescriptor, outputBytes.data(), aznumeric_cast<int>(outputBytes.size()));
+            }
+        };
+
+        stdoutCapturer.Start();
+        Application application(argc, argv, &stdoutCapturer);
+        AZ::ComponentApplication::StartupParameters startupParameters;
+        application.Start({}, startupParameters);
+
+        bool result = false;
+        const AZ::CommandLine* commandLine = application.GetAzCommandLine();
+        bool commandExecuted = false;
+        if (commandLine->GetNumMiscValues() >= 1)
+        {
+            // Set the command executed boolean to true
+            commandExecuted = true;
+            AZStd::string_view action = commandLine->GetMiscValue(0);
+            if (AZ::StringFunc::Equal("dumpfiles", action))
+            {
+                result = Dumper::DumpFiles(application);
+            }
+            else if (AZ::StringFunc::Equal("dumpsc", action))
+            {
+                result = Dumper::DumpSerializeContext(application);
+            }
+            else if (AZ::StringFunc::Equal("dumptypes", action))
+            {
+                result = Dumper::DumpTypes(application);
+            }
+            else if (AZ::StringFunc::Equal("convert", action))
+            {
+                result = Converter::ConvertObjectStreamFiles(application);
+            }
+            else if (AZ::StringFunc::Equal("convert-ini", action))
+            {
+                result = Converter::ConvertConfigFile(application);
+            }
+            else if (AZ::StringFunc::Equal("convert-slice", action))
+            {
+                SliceConverter sliceConverter;
+                result = sliceConverter.ConvertSliceFiles(application);
+            }
+            else if (AZ::StringFunc::Equal("createtype", action))
+            {
+                result = Dumper::CreateType(application);
+            }
+            else
+            {
+                commandExecuted = false;
+            }
+        }
+
+        // If a command was executed, display the help options
+        if (!commandExecuted)
+        {
+            // Stop capture of stdout to allow the help command to output to stdout
+            // stderr messages are suppressed in this case
+            fflush(stdout);
+            suppressStderr = true;
+            stdoutCapturer.Stop(SendStdoutToError);
+            PrintHelp();
+            result = true;
+            // Flush stdout stream before restarting the capture to make sure
+            // all the help text is output
+            fflush(stdout);
+            stdoutCapturer.Start();
+        }
+
+        if (!result)
+        {
+            AZ_Printf("SerializeContextTools", "Processing didn't complete fully as problems were encountered.\n");
+        }
+
+        application.Destroy();
+
+        // Write out any stdout to stderr at this point
+
+        // Because the FILE* stream is buffered, make sure to flush
+        // it before stopping the capture of stdout.
+        fflush(stdout);
+
+        suppressStderr = result;
+        stdoutCapturer.Stop(SendStdoutToError);
+
+        return result ? 0 : -1;
+    }
+}

+ 18 - 0
Code/Tools/SerializeContextTools/Runner.h

@@ -0,0 +1,18 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+namespace SerializeContextTools
+{
+    //! Outputs the SerializeContextTools help usage
+    void PrintHelp();
+
+    //! Runs the SerializeContext application hook with the command line parameters.
+    int LaunchSerializeContextTools(int argc, char** argv);
+}

+ 29 - 0
Code/Tools/SerializeContextTools/Tests/test_main.cpp

@@ -0,0 +1,29 @@
+/*
+ * 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 <AzCore/std/string/fixed_string.h>
+#include <AzCore/std/containers/fixed_vector.h>
+#include <AzTest/AzTest.h>
+#include <Runner.h>
+
+AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV)
+
+
+namespace UnitTest
+{
+    using SerializeContextToolsFixture = ::testing::Test;
+
+    TEST_F(SerializeContextToolsFixture, SerializeContextTools_HelpOption_Works)
+    {
+        AZStd::fixed_string<32> appName{ "SerializeContextTools" };
+        AZStd::fixed_string<32> helpArg{ "--help" };
+        AZStd::fixed_vector<char*, 2> commandArgs{ appName.data(), helpArg.data() };
+        EXPECT_EQ(0, SerializeContextTools::LaunchSerializeContextTools(int(commandArgs.size()),
+            commandArgs.data()));
+    }
+}

+ 2 - 189
Code/Tools/SerializeContextTools/main.cpp

@@ -6,196 +6,9 @@
  *
  */
 
-#include <AzCore/Console/IConsole.h>
-#include <AzCore/Debug/Trace.h>
-#include <AzCore/IO/SystemFile.h>
-#include <AzCore/StringFunc/StringFunc.h>
-#include <AzCore/Settings/CommandLine.h>
-#include <Application.h>
-#include <Converter.h>
-#include <Dumper.h>
-#include <SliceConverter.h>
-
-
-void PrintHelp()
-{
-    AZ_Printf("Help", "Serialize Context Tool\n");
-    AZ_Printf("Help", "  <action> [-config] [misc options] <action arguments>*\n");
-    AZ_Printf("Help", "  [opt] -config=<path>: optional path to application's config file. Default is 'config/editor.xml'.\n");
-    AZ_Printf("Help", "  [opt] -specializations=<prefix>: <comma or semicolon>-separated list of optional Registry project\n");
-    AZ_Printf("Help", "         specializations, such as 'editor' or 'game' or 'editor;test'.  Default is none. \n");
-    AZ_Printf("Help", "\n");
-    AZ_Printf("Help", "  'help': Print this help\n");
-    AZ_Printf("Help", "    example: 'help'\n");
-    AZ_Printf("Help", "\n");
-    AZ_Printf("Help", "  'dumpfiles': Dump the content to a .dump.txt file next to the original file.\n");
-    AZ_Printf("Help", "    [arg] -files=<path>: ;-separated list of files to verify. Supports wildcards.\n");
-    AZ_Printf("Help", "    [opt] -output=<path>: Path to the folder to write to instead of next to the original file.\n");
-    AZ_Printf("Help", "    example: 'dumpfiles -files=folder/*.ext;a.ext;folder/another/z.ext'\n");
-    AZ_Printf("Help", "\n");
-    AZ_Printf("Help", "  'dumpsc': Dump the content of the Serialize and Edit Context to a JSON file.\n");
-    AZ_Printf("Help", "    [opt] -output=<path>: Path to the folder to write to instead of next to the original file.\n");
-    AZ_Printf("Help", "    example: 'dumpsc -output=../TargetFolder/SerializeContext.json'\n");
-    AZ_Printf("Help", "\n");
-    AZ_Printf("Help", "  'dumptypes': Dump the list of reflected types to stdout or a file.\n");
-    AZ_Printf("Help", "    [opt] --sort=<WORD> : Sorts the reflected type by <WORD> where word can be one of the following values.\n");
-    AZ_Printf("Help", R"(          "name", "typeid", "none")" "\n")
-    AZ_Printf("Help", "          sorts by name if not specified .\n");
-    AZ_Printf("Help", "    [opt] --output-file=<filepath>: Path to the file to output reflected types.\n");
-    AZ_Printf("Help", "          If not specfied, output is written to stdout.\n");
-    AZ_Printf("Help", R"(    example: 'dumptypes')" "\n");
-    AZ_Printf("Help", R"(    example: 'dumptypes --sort=typeid)" "\n");
-    AZ_Printf("Help", R"(    example: 'dumptypes --output-file=reflectedtypes.txt)" "\n");
-    AZ_Printf("Help", "\n");
-    AZ_Printf("Help", "  'convert': Converts a file with an ObjectStream to the new JSON formats.\n");
-    AZ_Printf("Help", "    [arg] -files=<path>: <comma or semicolon>-separated list of files to verify. Supports wildcards.\n");
-    AZ_Printf("Help", "    [arg] -ext=<string>: Extension to use for the new file.\n");
-    AZ_Printf("Help", "    [opt] -dryrun: Processes as normal, but doesn't write files.\n");
-    AZ_Printf("Help", "    [opt] -skipverify: After conversion the result will not be compared to the original.\n");
-    AZ_Printf("Help", "    [opt] -keepdefaults: Fields are written if a default value was found.\n");
-    AZ_Printf("Help", "    [opt] -json-prefix=<prefix>: JSON pointer path prefix to anchor the JSON output underneath.\n");
-    AZ_Printf("Help", "           On Windows the <prefix> should be in quotes, as \"/\" is treated as command option prefix\n");
-    AZ_Printf("Help", "    [opt] -json-prefix=prefix: Json pointer path prefix to use as a \"root\" for settings.\n");
-    AZ_Printf("Help", "    [opt] -verbose: Report additional details during the conversion process.\n");
-    AZ_Printf("Help", "    example: 'convert -file=*.slice;*.uislice -ext=slice2'\n");
-    AZ_Printf("Help", "\n");
-    AZ_Printf("Help", R"(  'convert-ini': Converts windows-style INI file to a json format file.)" "\n");
-    AZ_Printf("Help", R"(                 The converted file is suitable for being loaded into the Settings Registry.)" "\n");
-    AZ_Printf("Help", R"(                 Can be used to convert .cfg/.ini files.)" "\n");
-    AZ_Printf("Help", R"(    [arg] -files=<path...>: <comma or semicolon>-separated list of files to verify. Supports wildcards.)" "\n");
-    AZ_Printf("Help", R"(    [opt] -ext=<string>: Extension to use for the new files. default=setreg)" "\n");
-    AZ_Printf("Help", R"(    [opt] -dryrun: Processes as normal, but doesn't write files.)" "\n");
-    AZ_Printf("Help", R"(    [opt] -json-prefix=<prefix>: JSON pointer path prefix to anchor the JSON output underneath.)" "\n");
-    AZ_Printf("Help", R"(           On Windows the <prefix> should be in quotes, as \"/\" is treated as command option prefix)" "\n");
-    AZ_Printf("Help", R"(    [opt] -verbose: Report additional details during the conversion process.)" "\n");
-    AZ_Printf("Help", R"(    example: 'convert-ini --files=AssetProcessorPlatformConfig.ini;bootstrap.cfg --ext=setreg)" "\n");
-    AZ_Printf("Help", "  'convert-slice': Converts ObjectStream-based slice files or legacy levels to a JSON-based prefab.\n");
-    AZ_Printf("Help", "    [arg] -files=<path>: <comma or semicolon>-separated list of files to convert. Supports wildcards.\n");
-    AZ_Printf("Help", "    [opt] -dryrun: Processes as normal, but doesn't write files.\n");
-    AZ_Printf("Help", "    [opt] -keepdefaults: Fields are written if a default value was found.\n");
-    AZ_Printf("Help", "    [opt] -verbose: Report additional details during the conversion process.\n");
-    AZ_Printf("Help", "    example: 'convert-slice -files=*.slice -specializations=editor\n");
-    AZ_Printf("Help", "    example: 'convert-slice -files=Levels/TestLevel/TestLevel.ly -specializations=editor\n");
-    AZ_Printf("Help", "\n");
-    AZ_Printf("Help", "  'createtype': Create a default constructed object using Json Serialization and output the contents.\n");
-    AZ_Printf("Help", "    [arg] --type-name=<string>: Name of type to construct and output.\n");
-    AZ_Printf("Help", "          The type must be registered with the Json Registration or Serialize Context.\n");
-    AZ_Printf("Help", "          Cannot be specified with the -type-id parameter.\n");
-    AZ_Printf("Help", "    [arg] --type-id=<uuid>: Uuid of type to construct and output.\n");
-    AZ_Printf("Help", "          The type must be registered with the Json Registration or Serialize Context.\n");
-    AZ_Printf("Help", "          Cannot be specified with the -type-name parameter.\n");
-    AZ_Printf("Help", "    [opt] --output-file=<filepath>: Path to the file to output constructed object.\n");
-    AZ_Printf("Help", "          If not supplied, output is written to stdout.\n");
-    AZ_Printf("Help", R"(    [opt] --json-prefix=<prefix>: JSON pointer path prefix to anchor the JSON output underneath.)" "\n");
-    AZ_Printf("Help", R"(    example: 'createtype --type-name="AZ::Entity"')" "\n");
-    AZ_Printf("Help", R"(    example: 'createtype --type-id="{75651658-8663-478D-9090-2432DFCAFA44}"')" "\n");
-    AZ_Printf("Help", R"(    example: 'createtype --type-name="AZ::Entity" --json-prefix="/My/Anchor"')" "\n");
-    AZ_Printf("Help", R"(    example: 'createtype --type-name="AZ::Entity" --output-file=object.json)" "\n");
-    AZ_Printf("Help", "\n");
-    AZ_Printf("Help", "  Miscellaneous Options:\n");
-    AZ_Printf("Help", "  This options can be used with any of the above actions:\n");
-    AZ_Printf("Help", "    [opt] --regset <setreg_key>=<setreg_value>: Set setreg_value at key setreg_key within the settings registry.\n");
-    AZ_Printf("Help", "    [opt] --project-path <project_path>: Sets the path to the active project. Used to load gems associated with project\n");
-}
+#include <Runner.h>
 
 int main(int argc, char** argv)
 {
-    using namespace AZ::SerializeContextTools;
-
-    const AZ::Debug::Trace tracer;
-    constexpr int StdoutDescriptor = 1;
-    AZ::IO::FileDescriptorCapturer stdoutCapturer(StdoutDescriptor);
-
-    // Send stdout output to stderr if the executed command returned a failure
-    bool suppressStderr = false;
-    auto SendStdoutToError = [&suppressStderr](AZStd::span<AZStd::byte const> outputBytes)
-    {
-        if (!suppressStderr)
-        {
-            constexpr int StderrDescriptor = 2;
-            AZ::IO::PosixInternal::Write(StderrDescriptor, outputBytes.data(), aznumeric_cast<int>(outputBytes.size()));
-        }
-    };
-
-    stdoutCapturer.Start();
-    Application application(argc, argv, &stdoutCapturer);
-    AZ::ComponentApplication::StartupParameters startupParameters;
-    application.Start({}, startupParameters);
-
-    bool result = false;
-    const AZ::CommandLine* commandLine = application.GetAzCommandLine();
-    bool commandExecuted = false;
-    if (commandLine->GetNumMiscValues() >= 1)
-    {
-        // Set the command executed boolean to true
-        commandExecuted = true;
-        AZStd::string_view action = commandLine->GetMiscValue(0);
-        if (AZ::StringFunc::Equal("dumpfiles", action))
-        {
-            result = Dumper::DumpFiles(application);
-        }
-        else if (AZ::StringFunc::Equal("dumpsc", action))
-        {
-            result = Dumper::DumpSerializeContext(application);
-        }
-        else if (AZ::StringFunc::Equal("dumptypes", action))
-        {
-            result = Dumper::DumpTypes(application);
-        }
-        else if (AZ::StringFunc::Equal("convert", action))
-        {
-            result = Converter::ConvertObjectStreamFiles(application);
-        }
-        else if (AZ::StringFunc::Equal("convert-ini", action))
-        {
-            result = Converter::ConvertConfigFile(application);
-        }
-        else if (AZ::StringFunc::Equal("convert-slice", action))
-        {
-            SliceConverter sliceConverter;
-            result = sliceConverter.ConvertSliceFiles(application);
-        }
-        else if (AZ::StringFunc::Equal("createtype", action))
-        {
-            result = Dumper::CreateType(application);
-        }
-        else
-        {
-            commandExecuted = false;
-        }
-    }
-
-    // If a command was executed, display the help options
-    if (!commandExecuted)
-    {
-        // Stop capture of stdout to allow the help command to output to stdout
-        // stderr messages are suppressed in this case
-        fflush(stdout);
-        suppressStderr = true;
-        stdoutCapturer.Stop(SendStdoutToError);
-        PrintHelp();
-        result = true;
-        // Flush stdout stream before restarting the capture to make sure
-        // all the help text is output
-        fflush(stdout);
-        stdoutCapturer.Start();
-    }
-
-    if (!result)
-    {
-        AZ_Printf("SerializeContextTools", "Processing didn't complete fully as problems were encountered.\n");
-    }
-
-    application.Destroy();
-
-    // Write out any stdout to stderr at this point
-
-    // Because the FILE* stream is buffered, make sure to flush
-    // it before stopping the capture of stdout.
-    fflush(stdout);
-
-    suppressStderr = result;
-    stdoutCapturer.Stop(SendStdoutToError);
-
-    return result ? 0 : -1;
+    return SerializeContextTools::LaunchSerializeContextTools(argc, argv);
 }

+ 0 - 11
Code/Tools/SerializeContextTools/serializecontexttools_files.cmake

@@ -7,16 +7,5 @@
 #
 
 set(FILES
-    Application.h
-    Application.cpp
-    Converter.h
-    Converter.cpp
-    Dumper.h
-    Dumper.cpp
     main.cpp
-    SliceConverterEditorEntityContextComponent.h
-    SliceConverter.h
-    SliceConverter.cpp
-    Utilities.h
-    Utilities.cpp
 )

+ 23 - 0
Code/Tools/SerializeContextTools/serializecontexttools_object_files.cmake

@@ -0,0 +1,23 @@
+#
+# 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
+#
+#
+
+set(FILES
+    Application.h
+    Application.cpp
+    Converter.h
+    Converter.cpp
+    Dumper.h
+    Dumper.cpp
+    SliceConverterEditorEntityContextComponent.h
+    SliceConverter.h
+    SliceConverter.cpp
+    Runner.h
+    Runner.cpp
+    Utilities.h
+    Utilities.cpp
+)

+ 11 - 0
Code/Tools/SerializeContextTools/serializecontexttools_tests_files.cmake

@@ -0,0 +1,11 @@
+#
+# 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
+#
+#
+
+set(FILES
+    Tests/test_main.cpp
+)

+ 1 - 1
cmake/LYWrappers.cmake

@@ -277,7 +277,7 @@ function(ly_add_target)
     # For any target that depends on AzTest and is built as an executable, an additional 'AZ_TEST_EXECUTABLE' define will
     # enable the 'AZ_UNIT_TEST_HOOK' macro to also implement main() so that running the executable directly will run
     # the AZ_UNIT_TEST_HOOK function
-    if (${PAL_TRAIT_TEST_TARGET_TYPE} STREQUAL "EXECUTABLE" AND "AZ::AzTest" IN_LIST ly_add_target_BUILD_DEPENDENCIES)
+    if (${linking_options} STREQUAL "EXECUTABLE" AND "AZ::AzTest" IN_LIST ly_add_target_BUILD_DEPENDENCIES)
         target_compile_definitions(${ly_add_target_NAME}
             PRIVATE
                 AZ_TEST_EXECUTABLE