General refactor of runtime classes.

This commit is contained in:
jonawals
2021-05-21 09:00:57 +01:00
parent 226ccce52d
commit d732b7d0ce
26 changed files with 320 additions and 175 deletions
@@ -25,7 +25,7 @@ namespace TestImpact
{
for (const auto& source : target->GetSources().m_staticSources)
{
if (auto mapping = m_sourceDependencyMap.find(source);
if (auto mapping = m_sourceDependencyMap.find(source.String());
mapping != m_sourceDependencyMap.end())
{
// This is an existing entry in the dependency map so update the parent build targets with this target
@@ -43,7 +43,7 @@ namespace TestImpact
{
for (const auto& output : autogen.m_outputs)
{
m_autogenInputToOutputMap[autogen.m_input].push_back(output);
m_autogenInputToOutputMap[autogen.m_input.String()].push_back(output.String());
}
}
};
@@ -138,11 +138,11 @@ namespace TestImpact
{
// Autogen input files are not compiled sources and thus supplying coverage data for them makes no sense
AZ_TestImpact_Eval(
m_autogenInputToOutputMap.find(sourceCoverage.GetPath()) == m_autogenInputToOutputMap.end(),
m_autogenInputToOutputMap.find(sourceCoverage.GetPath().c_str()) == m_autogenInputToOutputMap.end(),
DependencyException, AZStd::string::format("Couldn't replace source coverage for %s, source file is an autogen input file",
sourceCoverage.GetPath().c_str()).c_str());
auto [it, inserted] = m_sourceDependencyMap.insert(sourceCoverage.GetPath());
auto [it, inserted] = m_sourceDependencyMap.insert(sourceCoverage.GetPath().String());
auto& [key, sourceDependency] = *it;
// Clear any existing coverage for the delta
@@ -178,22 +178,26 @@ namespace TestImpact
}
}
void DynamicDependencyMap::ClearSourceCoverage(const AZStd::vector<AZStd::string>& paths)
void DynamicDependencyMap::ClearSourceCoverage(const AZStd::vector<RepoPath>& paths)
{
for (const auto& path : paths)
{
if (const auto outputSources = m_autogenInputToOutputMap.find(path);
if (const auto outputSources = m_autogenInputToOutputMap.find(path.String());
outputSources != m_autogenInputToOutputMap.end())
{
// Clearing the coverage data of an autogen input source instead clears the coverage data of its output sources
for (const auto& outputSource : outputSources->second)
{
ReplaceSourceCoverage(SourceCoveringTestsList({ SourceCoveringTests(outputSource) }));
AZStd::vector<SourceCoveringTests> coverage;
coverage.emplace_back(RepoPath(outputSource));
ReplaceSourceCoverage(SourceCoveringTestsList(AZStd::move(coverage)));
}
}
else
{
ReplaceSourceCoverage(SourceCoveringTestsList({ SourceCoveringTests(path, { }) }));
AZStd::vector<SourceCoveringTests> coverage;
coverage.emplace_back(RepoPath(path));
ReplaceSourceCoverage(SourceCoveringTestsList(AZStd::move(coverage)));
}
}
}
@@ -221,7 +225,7 @@ namespace TestImpact
return coveringTestTargets;
}
AZStd::optional<SourceDependency> DynamicDependencyMap::GetSourceDependency(const AZStd::string& path) const
AZStd::optional<SourceDependency> DynamicDependencyMap::GetSourceDependency(const RepoPath& path) const
{
AZStd::unordered_set<ParentTarget> parentTargets;
AZStd::unordered_set<const TestTarget*> coveringTestTargets;
@@ -243,7 +247,7 @@ namespace TestImpact
}
};
if (const auto outputSources = m_autogenInputToOutputMap.find(path); outputSources != m_autogenInputToOutputMap.end())
if (const auto outputSources = m_autogenInputToOutputMap.find(path.String()); outputSources != m_autogenInputToOutputMap.end())
{
// Consolidate the parentage and coverage of each of the autogen input file's generated output files
for (const auto& outputSource : outputSources->second)
@@ -253,7 +257,7 @@ namespace TestImpact
}
else
{
getSourceDependency(path);
getSourceDependency(path.String());
}
if (!parentTargets.empty() || !coveringTestTargets.empty())
@@ -264,7 +268,7 @@ namespace TestImpact
return AZStd::nullopt;
}
SourceDependency DynamicDependencyMap::GetSourceDependencyOrThrow(const AZStd::string& path) const
SourceDependency DynamicDependencyMap::GetSourceDependencyOrThrow(const RepoPath& path) const
{
auto sourceDependency = GetSourceDependency(path);
AZ_TestImpact_Eval(sourceDependency.has_value(), DependencyException, AZStd::string::format("Couldn't find source %s", path.c_str()).c_str());
@@ -282,7 +286,7 @@ namespace TestImpact
souceCoveringTests.push_back(testTarget->GetName());
}
coverage.push_back(SourceCoveringTests(path, AZStd::move(souceCoveringTests)));
coverage.push_back(SourceCoveringTests(RepoPath(path), AZStd::move(souceCoveringTests)));
}
return SourceCoveringTestsList(AZStd::move(coverage));
@@ -310,7 +314,7 @@ namespace TestImpact
// Keep track of the coverage to delete as a post step rather than deleting it in situ so that erroneous change lists
// do not corrupt the dynamic dependency map
AZStd::vector<AZStd::string> coverageToDelete;
AZStd::vector<RepoPath> coverageToDelete;
// Create operations
for (const auto& createdFile : changeList.m_createdFiles)
@@ -12,7 +12,8 @@
#pragma once
#include <Artifact/Dynamic/TestImpactChangeList.h>
#include <TestImpactFramework/TestImpactChangeList.h>
#include <Artifact/Static/TestImpactProductionTargetDescriptor.h>
#include <Artifact/Static/TestImpactTestTargetDescriptor.h>
#include <Dependency/TestImpactSourceCoveringTestsList.h>
@@ -74,10 +75,10 @@ namespace TestImpact
//! Gets the source dependency for the specified source file.
//! @note Autogen input source dependencies are the consolidated source dependencies of all of their generated output sources.
//! @returns If found, the source dependency information for the specified source file, otherwise empty.
AZStd::optional<SourceDependency> GetSourceDependency(const AZStd::string& path) const;
AZStd::optional<SourceDependency> GetSourceDependency(const RepoPath& path) const;
//! Gets the source dependency for the specified source file or throw DependencyException.
SourceDependency GetSourceDependencyOrThrow(const AZStd::string& path) const;
SourceDependency GetSourceDependencyOrThrow(const RepoPath& path) const;
//! Replaces the source coverage of the specified sources with the specified source coverage.
//! @note The covering targets for the parent test target(s) will not be pruned if those covering targets are removed.
@@ -99,7 +100,7 @@ namespace TestImpact
private:
//! Clears the source coverage of the specified sources.
//! @note The covering targets for the parent test target(s) will not be pruned if those covering targets are removed.
void ClearSourceCoverage(const AZStd::vector<AZStd::string>& paths);
void ClearSourceCoverage(const AZStd::vector<RepoPath>& paths);
//! The sorted list of unique production targets in the repository.
ProductionTargetList m_productionTargets;
@@ -16,18 +16,36 @@
namespace TestImpact
{
SourceCoveringTests::SourceCoveringTests(const AZStd::string& path)
AZStd::vector<AZStd::string> ExtractTargetsFromSet(AZStd::unordered_set<AZStd::string>&& coveringTestTargets)
{
AZStd::vector<AZStd::string> testTargets;
testTargets.reserve(coveringTestTargets.size());
for (auto it = coveringTestTargets.begin(); it != coveringTestTargets.end(); )
{
testTargets.push_back(std::move(coveringTestTargets.extract(it++).value()));
}
return testTargets;
}
SourceCoveringTests::SourceCoveringTests(const RepoPath& path)
: m_path(path)
{
}
SourceCoveringTests::SourceCoveringTests(const AZStd::string& path, AZStd::vector<AZStd::string>&& coveringTestTargets)
SourceCoveringTests::SourceCoveringTests(const RepoPath& path, AZStd::vector<AZStd::string>&& coveringTestTargets)
: m_path(path)
, m_coveringTestTargets(AZStd::move(coveringTestTargets))
{
}
const AZStd::string& SourceCoveringTests::GetPath() const
SourceCoveringTests::SourceCoveringTests(const RepoPath& path, AZStd::unordered_set<AZStd::string>&& coveringTestTargets)
: m_path(path)
, m_coveringTestTargets(ExtractTargetsFromSet(AZStd::move(coveringTestTargets)))
{
}
const RepoPath& SourceCoveringTests::GetPath() const
{
return m_path;
}
@@ -12,7 +12,10 @@
#pragma once
#include <TestImpactFramework/TestImpactRepoPath.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/containers/unordered_set.h>
#include <AzCore/std/string/string.h>
namespace TestImpact
@@ -21,11 +24,13 @@ namespace TestImpact
class SourceCoveringTests
{
public:
explicit SourceCoveringTests(const AZStd::string& path);
SourceCoveringTests(const AZStd::string& path, AZStd::vector<AZStd::string>&& coveringTestTargets);
//SourceCoveringTests(const SourceCoveringTests&);
explicit SourceCoveringTests(const RepoPath& path);
SourceCoveringTests(const RepoPath& path, AZStd::vector<AZStd::string>&& coveringTestTargets);
SourceCoveringTests(const RepoPath& path, AZStd::unordered_set<AZStd::string>&& coveringTestTargets);
//! Returns the path of this source file.
const AZStd::string& GetPath() const;
const RepoPath& GetPath() const;
//! Returns the number of unresolved test targets covering this source file.
size_t GetNumCoveringTestTargets() const;
@@ -33,7 +38,7 @@ namespace TestImpact
//! Returns the unresolved test targets covering this source file.
const AZStd::vector<AZStd::string>& GetCoveringTestTargets() const;
private:
AZStd::string m_path; //!< The path of this source file.
RepoPath m_path; //!< The path of this source file.
AZStd::vector<AZStd::string> m_coveringTestTargets; //!< The unresolved test targets that cover this source file.
};
@@ -52,14 +52,14 @@ namespace TestImpact
}
SourceDependency::SourceDependency(
const AZStd::string& path,
const RepoPath& path,
DependencyData&& dependencyData)
: m_path(path)
, m_dependencyData(AZStd::move(dependencyData))
{
}
const AZStd::string& SourceDependency::GetPath() const
const RepoPath& SourceDependency::GetPath() const
{
return m_path;
}
@@ -71,11 +71,11 @@ namespace TestImpact
{
public:
SourceDependency(
const AZStd::string& path,
const RepoPath& path,
DependencyData&& dependencyData);
//! Returns the path of this source file.
const AZStd::string& GetPath() const;
const RepoPath& GetPath() const;
//! Returns the number of parent build targets this source belongs to.
size_t GetNumParentTargets() const;
@@ -89,7 +89,7 @@ namespace TestImpact
//! Returns the test targets covering this source file.
const AZStd::unordered_set<const TestTarget*>& GetCoveringTestTargets() const;
private:
AZStd::string m_path; //!< The path of this source file.
RepoPath m_path; //!< The path of this source file.
DependencyData m_dependencyData; //!< The dependency data for this source file.
};
} // namespace TestImpact