Add extra comments

Signed-off-by: John <jonawals@amazon.com>
monroegm-disable-blank-issue-2
John 5 years ago
parent 478ffeeac6
commit 1cf1301a07

@ -54,9 +54,6 @@ if(PAL_TRAIT_PYTHONCOVERAGE_SUPPORTED)
Gem::PythonCoverage.Editor.Static 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.Tools NAMESPACE Gem TARGETS Gem::PythonCoverage.Editor)
ly_create_alias(NAME PythonCoverage.Builders NAMESPACE Gem TARGETS Gem::PythonCoverage.Editor) ly_create_alias(NAME PythonCoverage.Builders NAMESPACE Gem TARGETS Gem::PythonCoverage.Editor)
endif() endif()

@ -10,17 +10,15 @@
* *
*/ */
#include <AzCore/IO/Path/Path.h>
#include <AzCore/JSON/document.h>
#include <AzCore/Module/ModuleManagerBus.h> #include <AzCore/Module/ModuleManagerBus.h>
#include <AzCore/Module/Module.h> #include <AzCore/Module/Module.h>
#include <AzCore/Module/DynamicModuleHandle.h> #include <AzCore/Module/DynamicModuleHandle.h>
#include <AzCore/Serialization/SerializeContext.h> #include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/IO/Path/Path.h>
#include <AzCore/JSON/document.h>
#include <PythonCoverageEditorSystemComponent.h> #include <PythonCoverageEditorSystemComponent.h>
#pragma optimize("", off)
namespace PythonCoverage namespace PythonCoverage
{ {
constexpr char* const Caller = "PythonCoverageEditorSystemComponent"; constexpr char* const Caller = "PythonCoverageEditorSystemComponent";
@ -41,6 +39,7 @@ namespace PythonCoverage
// Attempt to discover the output directory for the test coverage files // Attempt to discover the output directory for the test coverage files
ParseCoverageOutputDirectory(); ParseCoverageOutputDirectory();
// If no output directory discovered, coverage gathering will be disabled
if (m_coverageState == CoverageState::Disabled) if (m_coverageState == CoverageState::Disabled)
{ {
return; return;
@ -77,11 +76,12 @@ namespace PythonCoverage
void PythonCoverageEditorSystemComponent::ParseCoverageOutputDirectory() void PythonCoverageEditorSystemComponent::ParseCoverageOutputDirectory()
{ {
m_coverageState = CoverageState::Disabled; 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; const AZStd::string configFilePath = LY_TEST_IMPACT_DEFAULT_CONFIG_FILE;
if (configFilePath.empty()) 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."); AZ_Warning(Caller, false, "No test impact analysis framework config found.");
return; return;
} }
@ -89,7 +89,7 @@ namespace PythonCoverage
const auto fileSize = AZ::IO::SystemFile::Length(configFilePath.c_str()); const auto fileSize = AZ::IO::SystemFile::Length(configFilePath.c_str());
if(!fileSize) 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; return;
} }
@ -97,7 +97,7 @@ namespace PythonCoverage
buffer[fileSize] = '\0'; buffer[fileSize] = '\0';
if (!AZ::IO::SystemFile::Read(configFilePath.c_str(), buffer.data())) 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; return;
} }
@ -110,15 +110,23 @@ namespace PythonCoverage
} }
const auto& tempConfig = configurationFile["workspace"]["temp"]; const auto& tempConfig = configurationFile["workspace"]["temp"];
// Temo directory root path is absolute
const AZ::IO::Path tempWorkspaceRootDir = tempConfig["root"].GetString(); 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(); const AZ::IO::Path artifactRelativeDir = tempConfig["relative_paths"]["artifact_dir"].GetString();
m_coverageDir = tempWorkspaceRootDir / artifactRelativeDir; m_coverageDir = tempWorkspaceRootDir / artifactRelativeDir;
// Everything is good to go, await the first python test case
m_coverageState = CoverageState::Idle; m_coverageState = CoverageState::Idle;
} }
void PythonCoverageEditorSystemComponent::WriteCoverageFile() void PythonCoverageEditorSystemComponent::WriteCoverageFile()
{ {
AZStd::string contents; AZStd::string contents;
// Compile the coverage for all test cases in this script
for (const auto& [testCase, entityComponents] : m_entityComponentMap) for (const auto& [testCase, entityComponents] : m_entityComponentMap)
{ {
const auto coveringModules = GetParentComponentModulesForAllActivatedEntities(entityComponents); const auto coveringModules = GetParentComponentModulesForAllActivatedEntities(entityComponents);
@ -140,17 +148,13 @@ namespace PythonCoverage
m_coverageFile.c_str(), 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::IO::SystemFile::SF_OPEN_CREATE | AZ::IO::SystemFile::SF_OPEN_CREATE_PATH | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY))
{ {
AZ_Error( AZ_Error(Caller, false, "Couldn't open file '%s' for writing", m_coverageFile.c_str());
Caller, false,
"Couldn't open file %s for writing", m_coverageFile.c_str());
return; return;
} }
if (!file.Write(bytes.data(), bytes.size())) if (!file.Write(bytes.data(), bytes.size()))
{ {
AZ_Error( AZ_Error(Caller, false, "Couldn't write contents for file '%s'", m_coverageFile.c_str());
Caller, false,
"Couldn't write contents for file %s", m_coverageFile.c_str());
return; return;
} }
} }

@ -39,11 +39,11 @@ namespace PythonCoverage
PythonCoverageEditorSystemComponent() = default; PythonCoverageEditorSystemComponent() = default;
private: private:
// AZ::Component // AZ::Component overrides...
void Activate() override; void Activate() override;
void Deactivate() override; void Deactivate() override;
// AZ::EntitySystemBus ... // AZ::EntitySystemBus overrides...
void OnEntityActivated(const AZ::EntityId& entityId) override; void OnEntityActivated(const AZ::EntityId& entityId) override;
// AZ::EditorPythonScriptNotificationsBus ... // AZ::EditorPythonScriptNotificationsBus ...
@ -66,7 +66,7 @@ namespace PythonCoverage
AZStd::unordered_set<AZStd::string> GetParentComponentModulesForAllActivatedEntities( AZStd::unordered_set<AZStd::string> GetParentComponentModulesForAllActivatedEntities(
const AZStd::unordered_map<AZ::Uuid, AZ::ComponentDescriptor*>& entityComponents) const; const AZStd::unordered_map<AZ::Uuid, AZ::ComponentDescriptor*>& entityComponents) const;
//! //! Writes the current coverage data snapshot to disk.
void WriteCoverageFile(); void WriteCoverageFile();
enum class CoverageState : AZ::u8 enum class CoverageState : AZ::u8

Loading…
Cancel
Save