Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@
[submodule "projects/rocprofiler-systems/external/googletest"]
path = projects/rocprofiler-systems/external/googletest
url = https://github.com/google/googletest.git
[submodule "projects/rocprofiler-systems/external/filesystem"]
path = projects/rocprofiler-systems/external/filesystem
url = https://github.com/gulrak/filesystem.git
58 changes: 58 additions & 0 deletions projects/rocprofiler-systems/cmake/GhcFilesystem.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# MIT License
#
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

include_guard(GLOBAL)

message(STATUS "Setting up ghc::filesystem for tests")
Comment thread
habajpai-amd marked this conversation as resolved.

include(FetchContent)

rocprofiler_systems_checkout_git_submodule(
RELATIVE_PATH external/filesystem
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
TEST_FILE include/ghc/filesystem.hpp
REPO_URL https://github.com/gulrak/filesystem.git
REPO_BRANCH "v1.5.14"
)

# Configure ghc/filesystem options before adding it
set(GHC_FILESYSTEM_BUILD_TESTING OFF CACHE BOOL "Disable ghc filesystem tests" FORCE)
set(GHC_FILESYSTEM_BUILD_EXAMPLES OFF CACHE BOOL "Disable ghc filesystem examples" FORCE)
set(GHC_FILESYSTEM_WITH_INSTALL OFF CACHE BOOL "Disable ghc filesystem install" FORCE)

# Declare ghc/filesystem from the submodule
FetchContent_Declare(ghc_filesystem SOURCE_DIR ${PROJECT_SOURCE_DIR}/external/filesystem)

# Make ghc/filesystem available
FetchContent_MakeAvailable(ghc_filesystem)

# Create interface library that wraps ghc::filesystem target
add_library(rocprofiler-systems-ghc-filesystem INTERFACE)

target_link_libraries(rocprofiler-systems-ghc-filesystem INTERFACE ghc_filesystem)

target_compile_definitions(
rocprofiler-systems-ghc-filesystem
INTERFACE ROCPROFSYS_TESTS_HAS_GHC_LIB_FILESYSTEM=1
)

message(STATUS "ghc::filesystem configured successfully using FetchContent")
1 change: 1 addition & 0 deletions projects/rocprofiler-systems/cmake/Packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ include(NlohmannJson)

if(ROCPROFSYS_BUILD_TESTING)
include(GTest)
include(GhcFilesystem)
endif()

# ----------------------------------------------------------------------------------------#
Expand Down
1 change: 1 addition & 0 deletions projects/rocprofiler-systems/external/filesystem
Submodule filesystem added at 8a2edd
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ remove_env(std::vector<char*>& _environ, std::string_view _env_var,
}

// Remove null entries
_environ.erase(std::remove_if(_environ.begin(), _environ.end(), match),
_environ.erase(std::remove_if(_environ.begin(), _environ.end(),
[](const char* ptr) { return ptr == nullptr; }),
_environ.end());

// Restore from original_envs if previously existed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

add_library(lib-common-tests OBJECT test_update_env.cpp)
add_library(
lib-common-tests
OBJECT
test_discover_llvm_libdir.cpp
test_path.cpp
test_remove_env.cpp
test_update_env.cpp
)

target_link_libraries(
lib-common-tests
PUBLIC rocprofiler-systems-common-library rocprofiler-systems-googletest-library
PUBLIC
rocprofiler-systems-common-library
rocprofiler-systems-googletest-library
rocprofiler-systems-ghc-filesystem
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// MIT License
//
// Copyright (c) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once

#if !defined(ROCPROFSYS_TESTS_HAS_GHC_LIB_FILESYSTEM)
# if defined __has_include
# if __has_include(<ghc/filesystem.hpp>)
# define ROCPROFSYS_TESTS_HAS_GHC_LIB_FILESYSTEM 1
# else
# define ROCPROFSYS_TESTS_HAS_GHC_LIB_FILESYSTEM 0
# endif
# else
# define ROCPROFSYS_TESTS_HAS_GHC_LIB_FILESYSTEM 0
# endif
#endif

#if ROCPROFSYS_TESTS_HAS_GHC_LIB_FILESYSTEM == 0
# if defined __has_include
# if __has_include(<version>)
# include <version>
# endif
# endif

# if defined(__cpp_lib_filesystem)
# define ROCPROFSYS_TESTS_HAS_CPP_LIB_FILESYSTEM 1
# else
# if defined __has_include
# if __has_include(<filesystem>)
# define ROCPROFSYS_TESTS_HAS_CPP_LIB_FILESYSTEM 1
# endif
# endif
# endif
#endif

#if defined(ROCPROFSYS_TESTS_HAS_GHC_LIB_FILESYSTEM) && \
ROCPROFSYS_TESTS_HAS_GHC_LIB_FILESYSTEM > 0
# include <ghc/filesystem.hpp>
#elif defined(ROCPROFSYS_TESTS_HAS_CPP_LIB_FILESYSTEM) && \
ROCPROFSYS_TESTS_HAS_CPP_LIB_FILESYSTEM > 0
# include <filesystem>
#else
# include <experimental/filesystem>
#endif

namespace test_common
{
#if defined(ROCPROFSYS_TESTS_HAS_GHC_LIB_FILESYSTEM) && \
ROCPROFSYS_TESTS_HAS_GHC_LIB_FILESYSTEM > 0
namespace fs = ::ghc::filesystem; // NOLINT(misc-unused-alias-decls)
#elif defined(ROCPROFSYS_TESTS_HAS_CPP_LIB_FILESYSTEM) && \
ROCPROFSYS_TESTS_HAS_CPP_LIB_FILESYSTEM > 0
namespace fs = ::std::filesystem; // NOLINT(misc-unused-alias-decls)
#else
namespace fs = ::std::experimental::filesystem; // NOLINT(misc-unused-alias-decls)
#endif
} // namespace test_common
Loading