Remove PythonCoverage runtime component

Signed-off-by: John <jonawals@amazon.com>
This commit is contained in:
John
2021-06-22 14:49:08 +01:00
parent 0e0f266fdd
commit 478ffeeac6
48 changed files with 274 additions and 573 deletions
@@ -18,9 +18,7 @@ namespace PythonCoverage
AZ_CLASS_ALLOCATOR_IMPL(PythonCoverageEditorModule, AZ::SystemAllocator, 0)
PythonCoverageEditorModule::PythonCoverageEditorModule()
: PythonCoverageModule()
{
// push results of [MyComponent]::CreateDescriptor() into m_descriptors here
m_descriptors.insert(
m_descriptors.end(),
{
@@ -12,15 +12,17 @@
#pragma once
#include "PythonCoverageModule.h"
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/Module/Module.h>
namespace PythonCoverage
{
class PythonCoverageEditorModule : public PythonCoverageModule
class PythonCoverageEditorModule
: public AZ::Module
{
public:
AZ_CLASS_ALLOCATOR_DECL
AZ_RTTI(PythonCoverageEditorModule, "{32C0FFEA-09A7-460F-9257-5BDEF74FCD5B}", PythonCoverageModule);
AZ_RTTI(PythonCoverageEditorModule, "{32C0FFEA-09A7-460F-9257-5BDEF74FCD5B}");
PythonCoverageEditorModule();
~PythonCoverageEditorModule();
@@ -37,7 +37,15 @@ namespace PythonCoverage
{
AzToolsFramework::EditorPythonScriptNotificationsBus::Handler::BusConnect();
AZ::EntitySystemBus::Handler::BusConnect();
// Attempt to discover the output directory for the test coverage files
ParseCoverageOutputDirectory();
if (m_coverageState == CoverageState::Disabled)
{
return;
}
EnumerateAllModuleComponents();
}
@@ -49,16 +57,31 @@ namespace PythonCoverage
void PythonCoverageEditorSystemComponent::OnEntityActivated(const AZ::EntityId& entityId)
{
if (m_coverageState == CoverageState::Disabled)
{
return;
}
EnumerateComponentsForEntity(entityId);
WriteCoverageFile();
// There is currently no way to receive a graceful exit signal in order to properly handle the coverage end of life so
// instead we have to serialize the data on-the-fly with blocking disk writes on the main thread... if this adversely
// affects performance in a measurable way then this could potentially be put on a worker thread, although it remains to
// be seen whether the asynchronous nature of such a thread results in queued up coverage being lost due to the hard exit
if (m_coverageState == CoverageState::Gathering)
{
WriteCoverageFile();
}
}
void PythonCoverageEditorSystemComponent::ParseCoverageOutputDirectory()
{
m_coverageState = CoverageState::Disabled;
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;
}
@@ -86,53 +109,49 @@ namespace PythonCoverage
return;
}
const AZ::IO::Path tempWorkspaceRootDir = configurationFile["workspace"]["temp"]["root"].GetString();
const AZ::IO::Path artifactRelativeDir = configurationFile["workspace"]["temp"]["relative_paths"]["artifact_dir"].GetString();
const auto& tempConfig = configurationFile["workspace"]["temp"];
const AZ::IO::Path tempWorkspaceRootDir = tempConfig["root"].GetString();
const AZ::IO::Path artifactRelativeDir = tempConfig["relative_paths"]["artifact_dir"].GetString();
m_coverageDir = tempWorkspaceRootDir / artifactRelativeDir;
m_coverageState = CoverageState::Idle;
}
void PythonCoverageEditorSystemComponent::WriteCoverageFile()
{
// Yes, we're doing blocking file operations on the main thread... If this becomes an issue this can be offloaded
// to a worker thread
if (m_coverageState == CoverageState::Gathering)
AZStd::string contents;
for (const auto& [testCase, entityComponents] : m_entityComponentMap)
{
AZStd::string contents;
for (const auto& [testCase, entityComponents] : m_entityComponentMap)
const auto coveringModules = GetParentComponentModulesForAllActivatedEntities(entityComponents);
if (coveringModules.empty())
{
const auto coveringModules = GetParentComponentModulesForAllActivatedEntities(entityComponents);
if (coveringModules.empty())
{
return;
}
return;
}
contents = testCase + "\n";
for (const auto& coveringModule : coveringModules)
{
contents += AZStd::string::format(" %s\n", coveringModule.c_str());
}
}
AZ::IO::SystemFile file;
const AZStd::vector<char> bytes(contents.begin(), contents.end());
if (!file.Open(
m_coverageFile.c_str(),
AZ::IO::SystemFile::SF_OPEN_CREATE | AZ::IO::SystemFile::SF_OPEN_CREATE_PATH | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY))
contents = testCase + "\n";
for (const auto& coveringModule : coveringModules)
{
AZ_Error(
Caller, false,
"Couldn't open file %s for writing", m_coverageFile.c_str());
return;
contents += AZStd::string::format(" %s\n", coveringModule.c_str());
}
}
if (!file.Write(bytes.data(), bytes.size()))
{
AZ_Error(
Caller, false,
"Couldn't write contents for file %s", m_coverageFile.c_str());
return;
}
AZ::IO::SystemFile file;
const AZStd::vector<char> bytes(contents.begin(), contents.end());
if (!file.Open(
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());
return;
}
if (!file.Write(bytes.data(), bytes.size()))
{
AZ_Error(
Caller, false,
"Couldn't write contents for file %s", m_coverageFile.c_str());
return;
}
}
@@ -142,10 +161,9 @@ namespace PythonCoverage
&AZ::ModuleManagerRequestBus::Events::EnumerateModules,
[this](const AZ::ModuleData& moduleData)
{
const AZStd::string moduleName = moduleData.GetDebugName();
// We can only enumerate shared libs, static libs are invisible to us
if (moduleData.GetDynamicModuleHandle())
{
const auto fileName = moduleData.GetDynamicModuleHandle()->GetFilename();
for (const auto* moduleComponentDescriptor : moduleData.GetModule()->GetComponentDescriptors())
{
m_moduleComponents[moduleComponentDescriptor->GetUuid()] = moduleData.GetDebugName();
@@ -1,26 +0,0 @@
#include <PythonCoverageModule.h>
#pragma optimize("", off)
namespace PythonCoverage
{
PythonCoverageModule::PythonCoverageModule()
: AZ::Module()
{
// Push results of [MyComponent]::CreateDescriptor() into m_descriptors here.
m_descriptors.insert(
m_descriptors.end(),
{ PythonCoverageSystemComponent::CreateDescriptor() });
}
AZ::ComponentTypeList PythonCoverageModule::GetRequiredSystemComponents() const
{
return AZ::ComponentTypeList{
azrtti_typeid<PythonCoverageSystemComponent>(),
};
}
}// namespace PythonCoverage
#if !defined(PYTHON_COVERAGE_EDITOR)
AZ_DECLARE_MODULE_CLASS(Gem_PythonCoverage, PythonCoverage::PythonCoverageModule)
#endif // !defined(PYTHON_COVERAGE_EDITOR)
@@ -1,26 +0,0 @@
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/Module/Module.h>
#include <PythonCoverageSystemComponent.h>
#pragma once
#pragma optimize("", off)
namespace PythonCoverage
{
class PythonCoverageModule : public AZ::Module
{
public:
AZ_RTTI(PythonCoverageModule, "{dc706de0-22c4-4b05-9b99-438692afc082}", AZ::Module);
AZ_CLASS_ALLOCATOR(PythonCoverageModule, AZ::SystemAllocator, 0);
PythonCoverageModule();
/**
* Add required SystemComponents to the SystemEntity.
*/
AZ::ComponentTypeList GetRequiredSystemComponents() const override;
};
} // namespace PythonCoverage
@@ -1,70 +0,0 @@
#include <PythonCoverageSystemComponent.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Serialization/EditContextConstants.inl>
namespace PythonCoverage
{
void PythonCoverageSystemComponent::Reflect(AZ::ReflectContext* context)
{
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
serialize->Class<PythonCoverageSystemComponent, AZ::Component>()
->Version(0)
;
if (AZ::EditContext* ec = serialize->GetEditContext())
{
ec->Class<PythonCoverageSystemComponent>("PythonCoverage", "[Description of functionality provided by this System Component]")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System"))
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
;
}
}
}
void PythonCoverageSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("PythonCoverageService"));
}
void PythonCoverageSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC("PythonCoverageService"));
}
void PythonCoverageSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
AZ_UNUSED(required);
}
void PythonCoverageSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
{
AZ_UNUSED(dependent);
}
void PythonCoverageSystemComponent::Init()
{
}
void PythonCoverageSystemComponent::Activate()
{
PythonCoverageRequestBus::Handler::BusConnect();
AZ::TickBus::Handler::BusConnect();
}
void PythonCoverageSystemComponent::Deactivate()
{
AZ::TickBus::Handler::BusDisconnect();
PythonCoverageRequestBus::Handler::BusDisconnect();
}
void PythonCoverageSystemComponent::OnTick(float /*deltaTime*/, AZ::ScriptTimePoint /*time*/)
{
}
} // namespace PythonCoverage
@@ -1,44 +0,0 @@
#pragma once
#include <AzCore/Component/Component.h>
#include <AzCore/Component/TickBus.h>
#include <PythonCoverage/PythonCoverageBus.h>
namespace PythonCoverage
{
class PythonCoverageSystemComponent
: public AZ::Component
, protected PythonCoverageRequestBus::Handler
, public AZ::TickBus::Handler
{
public:
AZ_COMPONENT(PythonCoverageSystemComponent, "{b2f692ae-1047-4a6d-a4ed-27b1aac40ba5}");
static void Reflect(AZ::ReflectContext* context);
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
protected:
////////////////////////////////////////////////////////////////////////
// PythonCoverageRequestBus interface implementation
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// AZ::Component interface implementation
void Init() override;
void Activate() override;
void Deactivate() override;
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// AZTickBus interface implementation
void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
////////////////////////////////////////////////////////////////////////
};
} // namespace PythonCoverage