diff --git a/AutomatedTesting/Gem/PythonCoverage/Code/CMakeLists.txt b/AutomatedTesting/Gem/PythonCoverage/Code/CMakeLists.txt index 570150758d..65b6d7509f 100644 --- a/AutomatedTesting/Gem/PythonCoverage/Code/CMakeLists.txt +++ b/AutomatedTesting/Gem/PythonCoverage/Code/CMakeLists.txt @@ -54,9 +54,6 @@ if(PAL_TRAIT_PYTHONCOVERAGE_SUPPORTED) Gem::PythonCoverage.Editor.Static ) - # By default, we will specify that the above target PythonCoverage would be used by - # Tool and Builder type targets when this gem is enabled. If you don't want it - # active in Tools or Builders by default, delete one of both of the following lines: ly_create_alias(NAME PythonCoverage.Tools NAMESPACE Gem TARGETS Gem::PythonCoverage.Editor) ly_create_alias(NAME PythonCoverage.Builders NAMESPACE Gem TARGETS Gem::PythonCoverage.Editor) endif() diff --git a/AutomatedTesting/Gem/PythonCoverage/Code/Source/PythonCoverageEditorSystemComponent.cpp b/AutomatedTesting/Gem/PythonCoverage/Code/Source/PythonCoverageEditorSystemComponent.cpp index 674e8684a5..95a084570c 100644 --- a/AutomatedTesting/Gem/PythonCoverage/Code/Source/PythonCoverageEditorSystemComponent.cpp +++ b/AutomatedTesting/Gem/PythonCoverage/Code/Source/PythonCoverageEditorSystemComponent.cpp @@ -10,17 +10,15 @@ * */ +#include +#include #include #include #include #include -#include -#include #include -#pragma optimize("", off) - namespace PythonCoverage { constexpr char* const Caller = "PythonCoverageEditorSystemComponent"; @@ -41,6 +39,7 @@ namespace PythonCoverage // Attempt to discover the output directory for the test coverage files ParseCoverageOutputDirectory(); + // If no output directory discovered, coverage gathering will be disabled if (m_coverageState == CoverageState::Disabled) { return; @@ -77,11 +76,12 @@ namespace PythonCoverage void PythonCoverageEditorSystemComponent::ParseCoverageOutputDirectory() { m_coverageState = CoverageState::Disabled; + + // Config file path will be empty if test impact analysis framework is disabled at the build config level const AZStd::string configFilePath = LY_TEST_IMPACT_DEFAULT_CONFIG_FILE; if (configFilePath.empty()) { - // Config file path will be empty if test impact analysis framework is disabled AZ_Warning(Caller, false, "No test impact analysis framework config found."); return; } @@ -89,7 +89,7 @@ namespace PythonCoverage const auto fileSize = AZ::IO::SystemFile::Length(configFilePath.c_str()); if(!fileSize) { - AZ_Error(Caller, false, "File %s does not exist", configFilePath.c_str()); + AZ_Error(Caller, false, "File '%s' does not exist", configFilePath.c_str()); return; } @@ -97,7 +97,7 @@ namespace PythonCoverage buffer[fileSize] = '\0'; if (!AZ::IO::SystemFile::Read(configFilePath.c_str(), buffer.data())) { - AZ_Error(Caller, false, "Could not read contents of file %s", configFilePath.c_str()); + AZ_Error(Caller, false, "Could not read contents of file '%s'", configFilePath.c_str()); return; } @@ -110,15 +110,23 @@ namespace PythonCoverage } const auto& tempConfig = configurationFile["workspace"]["temp"]; + + // Temo directory root path is absolute const AZ::IO::Path tempWorkspaceRootDir = tempConfig["root"].GetString(); + + // Artifact directory is relative to temp directory root const AZ::IO::Path artifactRelativeDir = tempConfig["relative_paths"]["artifact_dir"].GetString(); m_coverageDir = tempWorkspaceRootDir / artifactRelativeDir; + + // Everything is good to go, await the first python test case m_coverageState = CoverageState::Idle; } void PythonCoverageEditorSystemComponent::WriteCoverageFile() { AZStd::string contents; + + // Compile the coverage for all test cases in this script for (const auto& [testCase, entityComponents] : m_entityComponentMap) { const auto coveringModules = GetParentComponentModulesForAllActivatedEntities(entityComponents); @@ -140,17 +148,13 @@ namespace PythonCoverage m_coverageFile.c_str(), AZ::IO::SystemFile::SF_OPEN_CREATE | AZ::IO::SystemFile::SF_OPEN_CREATE_PATH | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY)) { - AZ_Error( - Caller, false, - "Couldn't open file %s for writing", m_coverageFile.c_str()); + AZ_Error(Caller, false, "Couldn't open file '%s' for writing", m_coverageFile.c_str()); return; } if (!file.Write(bytes.data(), bytes.size())) { - AZ_Error( - Caller, false, - "Couldn't write contents for file %s", m_coverageFile.c_str()); + AZ_Error(Caller, false, "Couldn't write contents for file '%s'", m_coverageFile.c_str()); return; } } diff --git a/AutomatedTesting/Gem/PythonCoverage/Code/Source/PythonCoverageEditorSystemComponent.h b/AutomatedTesting/Gem/PythonCoverage/Code/Source/PythonCoverageEditorSystemComponent.h index 0494cf1778..13101ff19c 100644 --- a/AutomatedTesting/Gem/PythonCoverage/Code/Source/PythonCoverageEditorSystemComponent.h +++ b/AutomatedTesting/Gem/PythonCoverage/Code/Source/PythonCoverageEditorSystemComponent.h @@ -39,11 +39,11 @@ namespace PythonCoverage PythonCoverageEditorSystemComponent() = default; private: - // AZ::Component + // AZ::Component overrides... void Activate() override; void Deactivate() override; - // AZ::EntitySystemBus ... + // AZ::EntitySystemBus overrides... void OnEntityActivated(const AZ::EntityId& entityId) override; // AZ::EditorPythonScriptNotificationsBus ... @@ -66,7 +66,7 @@ namespace PythonCoverage AZStd::unordered_set GetParentComponentModulesForAllActivatedEntities( const AZStd::unordered_map& entityComponents) const; - //! + //! Writes the current coverage data snapshot to disk. void WriteCoverageFile(); enum class CoverageState : AZ::u8