Skip to content

Commit

Permalink
feat: support empty components
Browse files Browse the repository at this point in the history
  • Loading branch information
cuinixam authored and xxthunder committed Sep 13, 2024
1 parent 3810076 commit f0d69e4
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 93 deletions.
4 changes: 2 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

param(
[switch]$clean ## clean build, wipe out all build artifacts
, [switch]$install ## install mandatory packages
, [switch]$install ## install dependencies, only
)

function Invoke-CommandLine {
Expand Down Expand Up @@ -43,7 +43,7 @@ function Invoke-CommandLine {

function Invoke-Bootstrap {
# Download bootstrap scripts from external repository
Invoke-RestMethod https://raw.githubusercontent.com/avengineers/bootstrap-installer/v1.12.0/install.ps1 | Invoke-Expression
Invoke-RestMethod https://raw.githubusercontent.com/avengineers/bootstrap-installer/v1.13.0/install.ps1 | Invoke-Expression
# Execute bootstrap script
. .\.bootstrap\bootstrap.ps1
}
Expand Down
5 changes: 4 additions & 1 deletion cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ macro(spl_add_component component_path)
add_subdirectory(${CMAKE_SOURCE_DIR}/${component_path})

if(BUILD_KIT STREQUAL prod)
target_link_libraries(${LINK_TARGET_NAME} ${component_name})
# Only add the target link libraries ${component_name} if the library is defined.
if(TARGET ${component_name})
target_link_libraries(${LINK_TARGET_NAME} ${component_name})
endif()
endif()
endmacro()

Expand Down
193 changes: 103 additions & 90 deletions tests/cmake/common.cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,90 +1,103 @@
# boilerplate to get CMake running
cmake_minimum_required(VERSION 3.22.0)
project(test-common-cmake C ASM)
set(VARIANT mytestvariant)

# ## IUT ####################################
include(${CMAKE_CURRENT_LIST_DIR}/../../../cmake/common.cmake)

# ## test: _spl_slash_to_underscore #########
# given
set(string_with_slashes "abc/def/ghi")

# when
_spl_slash_to_underscore(string_with_underscore ${string_with_slashes})

# then
if(NOT string_with_underscore STREQUAL "abc_def_ghi")
message(FATAL_ERROR "Failing Test case: string_with_slashes = ${string_with_slashes}.")
endif()

# ## test: _spl_get_absolute_path #########
# when
_spl_get_absolute_path(absolute_path "${PROJECT_SOURCE_DIR}/some_dir")

# then
set(expected_path tests/cmake/common.cmake/some_dir)
string(FIND "${absolute_path}" "${expected_path}" out)

if(NOT "${out}" GREATER 0)
message(FATAL_ERROR "Failing Test case: ${absolute_path} does not contain ${expected_path}.")
endif()

# when
_spl_get_absolute_path(absolute_path "${PROJECT_BINARY_DIR}/some_output")

# then
set(expected_path out/test_cmake/common.cmake/some_output)
string(FIND "${absolute_path}" "${expected_path}" out)

if(NOT "${out}" GREATER 0)
message(FATAL_ERROR "Failing Test case: ${absolute_path} does not contain ${expected_path}.")
endif()

# ## test: spl_add_source #########
# given
set(source_file src/some_source_file.c)
set(other_source_file src/some_other_source_file.c)

# when
spl_add_source(${source_file})
spl_add_source(${other_source_file})

# then
_spl_get_absolute_path(expected_source_file "${source_file}")
_spl_get_absolute_path(expected_other_source_file "${other_source_file}")
_spl_get_absolute_path(unexpected_source_file "not_expected.c")

if(NOT expected_source_file IN_LIST SOURCES)
message(FATAL_ERROR "Failing Test case: ${expected_source_file} not found inside ${SOURCES}.")
endif()

if(NOT expected_other_source_file IN_LIST SOURCES)
message(FATAL_ERROR "Failing Test case: ${expected_other_source_file} not found inside ${SOURCES}.")
endif()

if(unexpected_source_file IN_LIST SOURCES)
message(FATAL_ERROR "Failing Test case: ${unexpected_source_file} not found inside ${SOURCES}.")
endif()

#cleanup
unset(SOURCES)

# ## test: spl_add_component ###############

# given
set(some_file src/some_file.c)
set(some_other_file src/some_other_file.c)

# when
spl_add_component(component)
spl_add_component(some_other_component)
set_target_properties(component PROPERTIES LINKER_LANGUAGE C)

# then
if(NOT "component" IN_LIST COMPONENT_NAMES)
message(FATAL_ERROR "Failing Test case: component not found inside ${COMPONENT_NAMES}.")
endif()

# ## test: _spl_create_build_info_file (tests are written in test_cmake.py)#####
_spl_create_build_info_file()
# boilerplate to get CMake running
cmake_minimum_required(VERSION 3.22.0)
project(test-common-cmake C ASM)
set(VARIANT mytestvariant)

# ## IUT ####################################
include(${CMAKE_CURRENT_LIST_DIR}/../../../cmake/common.cmake)

# ## test: _spl_slash_to_underscore #########
# given
set(string_with_slashes "abc/def/ghi")

# when
_spl_slash_to_underscore(string_with_underscore ${string_with_slashes})

# then
if(NOT string_with_underscore STREQUAL "abc_def_ghi")
message(FATAL_ERROR "Failing Test case: string_with_slashes = ${string_with_slashes}.")
endif()

# ## test: _spl_get_absolute_path #########
# when
_spl_get_absolute_path(absolute_path "${PROJECT_SOURCE_DIR}/some_dir")

# then
set(expected_path tests/cmake/common.cmake/some_dir)
string(FIND "${absolute_path}" "${expected_path}" out)

if(NOT "${out}" GREATER 0)
message(FATAL_ERROR "Failing Test case: ${absolute_path} does not contain ${expected_path}.")
endif()

# when
_spl_get_absolute_path(absolute_path "${PROJECT_BINARY_DIR}/some_output")

# then
set(expected_path out/test_cmake/common.cmake/some_output)
string(FIND "${absolute_path}" "${expected_path}" out)

if(NOT "${out}" GREATER 0)
message(FATAL_ERROR "Failing Test case: ${absolute_path} does not contain ${expected_path}.")
endif()

# ## test: spl_add_source #########
# given
set(source_file src/some_source_file.c)
set(other_source_file src/some_other_source_file.c)

# when
spl_add_source(${source_file})
spl_add_source(${other_source_file})

# then
_spl_get_absolute_path(expected_source_file "${source_file}")
_spl_get_absolute_path(expected_other_source_file "${other_source_file}")
_spl_get_absolute_path(unexpected_source_file "not_expected.c")

if(NOT expected_source_file IN_LIST SOURCES)
message(FATAL_ERROR "Failing Test case: ${expected_source_file} not found inside ${SOURCES}.")
endif()

if(NOT expected_other_source_file IN_LIST SOURCES)
message(FATAL_ERROR "Failing Test case: ${expected_other_source_file} not found inside ${SOURCES}.")
endif()

if(unexpected_source_file IN_LIST SOURCES)
message(FATAL_ERROR "Failing Test case: ${unexpected_source_file} not found inside ${SOURCES}.")
endif()

# cleanup
unset(SOURCES)

# ## test: spl_add_component ###############

# given
set(some_file src/some_file.c)
set(some_other_file src/some_other_file.c)

# when
spl_add_component(component)
spl_add_component(some_other_component)
spl_add_component(comp_without_sources)
set_target_properties(component PROPERTIES LINKER_LANGUAGE C)

# then
foreach(component IN ITEMS component some_other_component comp_without_sources)
if(NOT "${component}" IN_LIST COMPONENT_NAMES)
message(FATAL_ERROR "Failing Test case: ${component} not found inside ${COMPONENT_NAMES}.")
endif()

if(NOT TARGET ${component})
message(FATAL_ERROR "Failing Test case: ${component} not found as a target.")
endif()
endforeach()

_spl_get_absolute_path(expected_include "comp_without_sources/src")

if(NOT expected_include IN_LIST target_include_directories__INCLUDES)
message(FATAL_ERROR "Failing Test case: ${expected_include} not found inside ${target_include_directories__INCLUDES}.")
endif()

# ## test: _spl_create_build_info_file (tests are written in test_cmake.py)#####
_spl_create_build_info_file()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spl_create_component(LONG_NAME "Some component without sources")
Empty file.

0 comments on commit f0d69e4

Please sign in to comment.