Skip to content

Commit

Permalink
O3DE engine Gem rename support (o3de#17059)
Browse files Browse the repository at this point in the history
* O3DE engine Gem rename support

The following changes have been made to all of the Gems that come with
the O3DE engine source code to make it easier to rename a Gem.

Updated all of the Gems CMakeLists.txt to use the "${gem_name}" variable
when referencing the Gem in CMake Targets.

This allows the name of the CMake targets to update whenever the
"gem_name" in the gem.json is changed.

Updated all of the `AZ_DECLARE_MODULE_CLASS` macro invocations to
reference the `O3DE_GEM_NAME` preprocessor token which is use to
substitute the "gem_name" in the gem.json for the extern "C"
`CreateModuleClass_Gem_*` function which the launcher_generator.cmake
invokes in Monolithic builds to create an AZ::Module derived class instance for each active gem.

resolves o3de#17034

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Removed the boilerplate comments from Gems AZ_DECLARE_MODULE_CLASS

All the comments that started with "DO NOT MODIFY THIS LINE UNLESS YOU RENAME THE GEM" have been removed.

The externed "C" function that instantiates an AZ::Module derived class
in monolithic build now automatically adjust account for a rename of the
Gem.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Replace all O3DE engine Gems and Gem Templates Gem variable boilerplate

The repeat boilerplate logic in each Gem has been replaced with a CMake
macro called "o3de_gem_setup" which uses the directory of the calling
CMakeLists.txt file to locate the nearest ancestor gem.json file.

It uses that directory of that gem.json file as the `${gem_path}` value.
It reads the "gem_name" field from that gem.json and sets that as the
`${gem_name}` variable.
It also reads the "version" field from that gem.json and sets that as
the `${gem_version}` variable.

Finally it sets the `${pal_dir}` variable based to the equivalent
`<CMakeLists.txt directory>/Platform/<configured platform>/` directory
using the directory of the calling CMakeLists.txt and the current
platform that CMake is being configured for(Windows, Linux, Android,
MacOS, iOS, or a "restricted platform").

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the SimpleSchema, ChildAllocatorSchema `NumAllocateBytes`
function to also output the name of the Allocator when the Assert
Triggers

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fixed memory tracking issue with the `HpAllocator::deallocate` function
returning a different value for the amount of bytes deallocated, than
were allocated.

The issue is that when the HpAllocator is used for aligned allocation of
>=32 bytes, it could find a block that could fulfill the allocation
request, but wasn't aligned.

If the block need to be adjusted for a size that was >0 but less than
the size of block header(16 bytes) + the size of the free node(40
bytes), than instead of being to split the block into two blocks where
the first block would be a free block that gets added to the free list
and the second block would be the actual aligned block, the code would
try to shift the previous block to be large enough such that the next
block would start aligned on the specified alignent using the
`shift_block` function.

This would result in previous block storing a larger size value.

So when the memory associated with the block was deallocated, it would
report a size larger than the size reported when it was allocated.

This fixes an issue where the Tracking the number of allocated bytes in
the ChildAllocatorSchema and SimpleAllocatorSchema would result in a
non-zero value after all of the allocations have been deleted.

This because the `ChildAllocatorSchema::allocate` function relies on
amount of bytes returned from the actual child allocator `allocate()` call
to be matched when the pointer that was allocated is deallocated via the
`ChildAllocatorSchema::deallocate` function which uses the child
allocator `deallocate()` call.

```
20:28:39  [----------] 1 test from MotionSetFixture

20:28:39  [ RUN      ] MotionSetFixture.MeshLoadTest

20:28:39
   D:\workspace\o3de\Code\Framework\AzCore\AzCore/Memory/ChildAllocatorSchema.h(155):
   error: Child Allocator "EMotionFXAllocator": Total allocated bytes is
   less than zero with a value of -16. Was deallocate() invoked with an
   address that is not associated with this allocator? This should never
   occur

   20:28:39
      D:\workspace\o3de\Code\Framework\AzCore\AzCore/UnitTest/TestTypes.h(76):
      error: Expected equality of these values:

      20:28:39    sizeBeforeTestRan

      20:28:39      Which is: 0

      20:28:39    sizeAfterTestRan

      20:28:39      Which is: 18446744073709551600

      20:28:39  for allocator EMotionFXAllocator with 0 allocation
	 records
```

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Update Code/Framework/AzCore/AzCore/Memory/HphaAllocator.cpp

Co-authored-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>
Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

---------

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Co-authored-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>
  • Loading branch information
lemonade-dm and spham-amzn authored Nov 18, 2023
1 parent 51c617f commit 324c031
Showing 408 changed files with 4,161 additions and 2,326 deletions.
9 changes: 5 additions & 4 deletions AutomatedTesting/Gem/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -6,9 +6,10 @@
#
#

set(gem_path ${CMAKE_CURRENT_LIST_DIR})
set(gem_json ${gem_path}/gem.json)
o3de_restricted_path(${gem_json} gem_restricted_path gem_parent_relative_path)
o3de_gem_setup("AutomatedTesting")

ly_add_external_target_path(${CMAKE_CURRENT_SOURCE_DIR}/3rdParty)

add_subdirectory(Code)
add_subdirectory(PythonTests)

add_subdirectory(PythonTests)
23 changes: 16 additions & 7 deletions AutomatedTesting/Gem/Code/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
o3de_pal_dir(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} "${gem_restricted_path}" "${gem_path}" "${gem_parent_relative_path}")

ly_add_target(
NAME AutomatedTesting ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
NAME ${gem_name} ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
NAMESPACE Gem
FILES_CMAKE
automatedtesting_files.cmake
@@ -36,14 +36,23 @@ ly_add_target(
*.AutoComponent.xml,AutoComponentTypes_Source.jinja,$path/AutoComponentTypes.cpp
)

# Inject the gem name into the Module source file
ly_add_source_properties(
SOURCES
Source/AutomatedTestingModule.cpp
PROPERTY COMPILE_DEFINITIONS
VALUES
O3DE_GEM_NAME=${gem_name}
O3DE_GEM_VERSION=${gem_version})

# if enabled, AutomatedTesting is used by all kinds of applications
ly_create_alias(NAME AutomatedTesting.Builders NAMESPACE Gem TARGETS Gem::AutomatedTesting)
ly_create_alias(NAME AutomatedTesting.Tools NAMESPACE Gem TARGETS Gem::AutomatedTesting)
ly_create_alias(NAME AutomatedTesting.Clients NAMESPACE Gem TARGETS Gem::AutomatedTesting)
ly_create_alias(NAME AutomatedTesting.Servers NAMESPACE Gem TARGETS Gem::AutomatedTesting)
ly_create_alias(NAME AutomatedTesting.Unified NAMESPACE Gem TARGETS Gem::AutomatedTesting)
ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name})
ly_create_alias(NAME ${gem_name}.Tools NAMESPACE Gem TARGETS Gem::${gem_name})
ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name})
ly_create_alias(NAME ${gem_name}.Servers NAMESPACE Gem TARGETS Gem::${gem_name})
ly_create_alias(NAME ${gem_name}.Unified NAMESPACE Gem TARGETS Gem::${gem_name})

# Add project to the list server projects to create the AutomatedTesting.ServerLauncher
# Add project to the list server projects to create the ${gem_name}.ServerLauncher
if(PAL_TRAIT_BUILD_SERVER_SUPPORTED)
set_property(GLOBAL APPEND PROPERTY LY_LAUNCHER_SERVER_PROJECTS AutomatedTesting)
endif()
7 changes: 4 additions & 3 deletions AutomatedTesting/Gem/Code/Source/AutomatedTestingModule.cpp
Original file line number Diff line number Diff line change
@@ -44,7 +44,8 @@ namespace AutomatedTesting
};
}

// DO NOT MODIFY THIS LINE UNLESS YOU RENAME THE GEM
// The first parameter should be GemName_GemIdLower
// The second should be the fully qualified name of the class above
#if defined(O3DE_GEM_NAME)
AZ_DECLARE_MODULE_CLASS(AZ_JOIN(Gem_, O3DE_GEM_NAME), AutomatedTesting::AutomatedTestingModule)
#else
AZ_DECLARE_MODULE_CLASS(Gem_AutomatedTesting, AutomatedTesting::AutomatedTestingModule)
#endif
6 changes: 3 additions & 3 deletions AutomatedTesting/Gem/PythonCoverage/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@
#
#

set(gem_path ${CMAKE_CURRENT_LIST_DIR})
set(gem_json ${gem_path}/gem.json)
o3de_restricted_path(${gem_json} gem_restricted_path gem_parent_relative_path)
o3de_gem_setup("PythonCoverage")

ly_add_external_target_path(${CMAKE_CURRENT_SOURCE_DIR}/3rdParty)

add_subdirectory(Code)
21 changes: 15 additions & 6 deletions AutomatedTesting/Gem/PythonCoverage/Code/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ include(${pal_dir}/PAL_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
if(PAL_TRAIT_PYTHONCOVERAGE_SUPPORTED)
if(PAL_TRAIT_BUILD_HOST_TOOLS)
ly_add_target(
NAME PythonCoverage.Editor.Static STATIC
NAME ${gem_name}.Editor.Static STATIC
NAMESPACE Gem
FILES_CMAKE
pythoncoverage_editor_files.cmake
@@ -34,10 +34,10 @@ if(PAL_TRAIT_PYTHONCOVERAGE_SUPPORTED)
)

ly_add_target(
NAME PythonCoverage.Editor GEM_MODULE
NAME ${gem_name}.Editor GEM_MODULE
NAMESPACE Gem
AUTOMOC
OUTPUT_NAME Gem.PythonCoverage.Editor
OUTPUT_NAME Gem.${gem_name}.Editor
FILES_CMAKE
pythoncoverage_editor_shared_files.cmake
COMPILE_DEFINITIONS
@@ -50,10 +50,19 @@ if(PAL_TRAIT_PYTHONCOVERAGE_SUPPORTED)
Include
BUILD_DEPENDENCIES
PUBLIC
Gem::PythonCoverage.Editor.Static
Gem::${gem_name}.Editor.Static
)

ly_create_alias(NAME PythonCoverage.Tools NAMESPACE Gem TARGETS Gem::PythonCoverage.Editor)
ly_create_alias(NAME PythonCoverage.Builders NAMESPACE Gem TARGETS Gem::PythonCoverage.Editor)
# Inject the gem name into the Module source file
ly_add_source_properties(
SOURCES
Source/PythonCoverageEditorModule.cpp
PROPERTY COMPILE_DEFINITIONS
VALUES
O3DE_GEM_NAME=${gem_name}
O3DE_GEM_VERSION=${gem_version})

ly_create_alias(NAME ${gem_name}.Tools NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
endif()
endif()
Original file line number Diff line number Diff line change
@@ -31,4 +31,8 @@ namespace PythonCoverage
}
} // namespace PythonCoverage

AZ_DECLARE_MODULE_CLASS(Gem_PythonCoverageEditor, PythonCoverage::PythonCoverageEditorModule)
#if defined(O3DE_GEM_NAME)
AZ_DECLARE_MODULE_CLASS(AZ_JOIN(Gem_, O3DE_GEM_NAME, _Editor), PythonCoverage::PythonCoverageEditorModule)
#else
AZ_DECLARE_MODULE_CLASS(Gem_PythonCoverage_Editor, PythonCoverage::PythonCoverageEditorModule)
#endif
4 changes: 2 additions & 2 deletions Code/Framework/AzCore/AzCore/Memory/ChildAllocatorSchema.h
Original file line number Diff line number Diff line change
@@ -150,9 +150,9 @@ namespace AZ
{
AZ_Assert(
m_totalAllocatedBytes >= 0,
"Total allocated bytes is less than zero with a value of %td. Was deallocate() invoked with an address "
R"(Child Allocator "%s": Total allocated bytes is less than zero with a value of %td. Was deallocate() invoked with an address )"
"that is not associated with this allocator? This should never occur",
m_totalAllocatedBytes.load());
GetName(), m_totalAllocatedBytes.load());
return static_cast<size_type>(m_totalAllocatedBytes);
}

Loading

0 comments on commit 324c031

Please sign in to comment.