From 692dd21b892dfc647053734230e26bda3bbfa9b4 Mon Sep 17 00:00:00 2001 From: jonawals Date: Wed, 28 Apr 2021 17:26:28 +0100 Subject: [PATCH] Add missing SourceDependency. --- .../Dependency/TestImpactSourceDependency.cpp | 82 ++++++++++++++++ .../Dependency/TestImpactSourceDependency.h | 96 +++++++++++++++++++ .../testimpactframework_runtime_files.cmake | 10 +- 3 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 Code/Tools/TestImpactFramework/Runtime/Code/Source/Dependency/TestImpactSourceDependency.cpp create mode 100644 Code/Tools/TestImpactFramework/Runtime/Code/Source/Dependency/TestImpactSourceDependency.h diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Dependency/TestImpactSourceDependency.cpp b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Dependency/TestImpactSourceDependency.cpp new file mode 100644 index 0000000000..49d82e341a --- /dev/null +++ b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Dependency/TestImpactSourceDependency.cpp @@ -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 +#include +#include +#include + +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& 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& SourceDependency::GetParentTargets() const + { + return m_dependencyData.m_parentTargets; + } + + const AZStd::unordered_set& SourceDependency::GetCoveringTestTargets() const + { + return m_dependencyData.m_coveringTestTargets; + } + +} // namespace TestImpact diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Dependency/TestImpactSourceDependency.h b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Dependency/TestImpactSourceDependency.h new file mode 100644 index 0000000000..e6cd89df9d --- /dev/null +++ b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Dependency/TestImpactSourceDependency.h @@ -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 +#include +#include +#include +#include + +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& GetTarget() const; + + bool operator==(const ParentTarget& other) const; + private: + const BuildTarget* m_buildTarget; //! The base built target pointer for this parent. + AZStd::variant 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 + { + size_t operator()(const TestImpact::ParentTarget& parentTarget) const noexcept + { + return reinterpret_cast(parentTarget.GetBuildTarget()); + } + }; +} + +namespace TestImpact +{ + struct DependencyData + { + AZStd::unordered_set m_parentTargets; + AZStd::unordered_set 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& GetParentTargets() const; + + //! Returns the test targets covering this source file. + const AZStd::unordered_set& GetCoveringTestTargets() const; + private: + AZStd::string m_path; //!< The path of this source file. + DependencyData m_dependencyData; //!< + }; +} // namespace TestImpact diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/testimpactframework_runtime_files.cmake b/Code/Tools/TestImpactFramework/Runtime/Code/testimpactframework_runtime_files.cmake index f4128f7002..19f3ec23f7 100644 --- a/Code/Tools/TestImpactFramework/Runtime/Code/testimpactframework_runtime_files.cmake +++ b/Code/Tools/TestImpactFramework/Runtime/Code/testimpactframework_runtime_files.cmake @@ -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