Add missing SourceDependency.

This commit is contained in:
jonawals
2021-04-28 17:26:28 +01:00
parent b9dc7639b4
commit 692dd21b89
3 changed files with 187 additions and 1 deletions
@@ -0,0 +1,82 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <Dependency/TestImpactSourceDependency.h>
#include <Target/TestImpactBuildTarget.h>
#include <Target/TestImpactProductionTarget.h>
#include <Target/TestImpactTestTarget.h>
namespace TestImpact
{
ParentTarget::ParentTarget(const TestTarget* target)
: m_buildTarget(target)
, m_target(target)
{
}
ParentTarget::ParentTarget(const ProductionTarget* target)
: m_buildTarget(target)
, m_target(target)
{
}
bool ParentTarget::operator==(const ParentTarget& other) const
{
return m_buildTarget == other.m_buildTarget;
}
const BuildTarget* ParentTarget::GetBuildTarget() const
{
return m_buildTarget;
}
const AZStd::variant<const ProductionTarget*, const TestTarget*>& ParentTarget::GetTarget() const
{
return m_target;
}
SourceDependency::SourceDependency(
const AZStd::string& path,
DependencyData&& dependencyData)
: m_path(path)
, m_dependencyData(AZStd::move(dependencyData))
{
}
const AZStd::string& SourceDependency::GetPath() const
{
return m_path;
}
size_t SourceDependency::GetNumParentTargets() const
{
return m_dependencyData.m_parentTargets.size();
}
size_t SourceDependency::GetNumCoveringTestTargets() const
{
return m_dependencyData.m_coveringTestTargets.size();
}
const AZStd::unordered_set<ParentTarget>& SourceDependency::GetParentTargets() const
{
return m_dependencyData.m_parentTargets;
}
const AZStd::unordered_set<const TestTarget*>& SourceDependency::GetCoveringTestTargets() const
{
return m_dependencyData.m_coveringTestTargets;
}
} // namespace TestImpact
@@ -0,0 +1,96 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/std/string/string.h>
#include <AzCore/std/containers/unordered_map.h>
#include <AzCore/std/containers/unordered_set.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/containers/variant.h>
namespace TestImpact
{
class BuildTarget;
class ProductionTarget;
class TestTarget;
//! Representation of a source dependency's parent target.
class ParentTarget
{
public:
//! Constructor overload for test target types.
ParentTarget(const TestTarget* target);
//! Constructor overload for production target types.
ParentTarget(const ProductionTarget* target);
//! Returns the base build target pointer for this parent.
const BuildTarget* GetBuildTarget() const;
//! Returns the specialized target pointer for this parent.
const AZStd::variant<const ProductionTarget*, const TestTarget*>& GetTarget() const;
bool operator==(const ParentTarget& other) const;
private:
const BuildTarget* m_buildTarget; //! The base built target pointer for this parent.
AZStd::variant<const ProductionTarget*, const TestTarget*> m_target; //! The specialized target pointer for this parent.
};
}
namespace AZStd
{
//! Hash function for ParentTarget types for use in maps and sets
template<> struct hash<TestImpact::ParentTarget>
{
size_t operator()(const TestImpact::ParentTarget& parentTarget) const noexcept
{
return reinterpret_cast<size_t>(parentTarget.GetBuildTarget());
}
};
}
namespace TestImpact
{
struct DependencyData
{
AZStd::unordered_set<ParentTarget> m_parentTargets;
AZStd::unordered_set<const TestTarget*> m_coveringTestTargets;
};
//! Test target coverage and build target dependency information for a given source file in the dynamic dependency map.
class SourceDependency
{
public:
SourceDependency(
const AZStd::string& path,
DependencyData&& dependencyData);
//! Returns the path of this source file.
const AZStd::string& GetPath() const;
//! Returns the number of parent build targets this source belongs to.
size_t GetNumParentTargets() const;
//! Returns the number of test targets covering this source file.
size_t GetNumCoveringTestTargets() const;
//! Returns the parent targets that this source file belongs to.
const AZStd::unordered_set<ParentTarget>& GetParentTargets() const;
//! 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.
DependencyData m_dependencyData; //!<
};
} // namespace TestImpact
@@ -52,7 +52,15 @@ set(FILES
Source/Process/JobRunner/TestImpactProcessJobRunner.h
Source/Process/Scheduler/TestImpactProcessScheduler.cpp
Source/Process/Scheduler/TestImpactProcessScheduler.h
Source/Dependency/TestImpactDynamicDependencyMap.cpp
Source/Dependency/TestImpactDynamicDependencyMap.h
Source/Dependency/TestImpactChangeDependencyList.cpp
Source/Dependency/TestImpactChangeDependencyList.h
Source/Dependency/TestImpactDependencyException.h
Source/Dependency/TestImpactSourceDependency.h
Source/Dependency/TestImpactSourceDependency.cpp
Source/Dependency/TestImpactSourceCoveringTestsList.h
Source/Dependency/TestImpactSourceCoveringTestsList.cpp
Source/Target/TestImpactBuildTarget.cpp
Source/Target/TestImpactBuildTarget.h
Source/Target/TestImpactBuildTargetList.h