~aleteoryx/muditaos

6eeb1d75704ae9b97e002c3d7b058ac532b14128 — DariuszSabala 4 years ago df24232
[BH-628] Cleaned up module-vfs cmake

Cleaned up pattern of sharing source files among libraries
using cached lists, ultimately leading to silent linkage
failures. Symbols build repeatedly in different libraries
was linked depending on which library was passed in linker
command arguments first, so for example in same cases
cellular bsp files compiled in module-vfs was linked instead
of those from module-bsp leading to failure of cellular work
despite no explicite build failure.
M Target_RT1051.cmake => Target_RT1051.cmake +0 -1
@@ 90,7 90,6 @@ set(TARGET_DIR_INCLUDES

set(BOARD_DIR_INCLUDES
        ${CMAKE_CURRENT_LIST_DIR}/board/rt1051/newlib/include
        ${CMAKE_SOURCE_DIR}/module-vfs/include/internal
)

set(TARGET_LIBRARIES

M module-vfs/CMakeLists.txt => module-vfs/CMakeLists.txt +80 -34
@@ 2,37 2,81 @@ add_library(module-vfs STATIC)

module_is_test_entity()

if(${PROJECT_TARGET} STREQUAL "TARGET_RT1051")
    include(targets/Target_RT1051.cmake)
elseif(${PROJECT_TARGET} STREQUAL "TARGET_Linux")
    include(targets/Target_Linux.cmake)
else()
    message(FATAL_ERROR "Invalid target!")
endif()

target_sources(module-vfs
    PRIVATE
        drivers/src/thirdparty/fatfs/ffsystem.cpp
        $<$<STREQUAL:${PROJECT_TARGET},TARGET_RT1051>:
            board/rt1051/newlib/vfs_io_syscalls.cpp
            board/rt1051/purefs/include/purefs/blkdev/disk_eeprom.hpp
            board/rt1051/purefs/include/purefs/blkdev/disk_emmc.hpp
            board/rt1051/purefs/src/blkdev/disk_eeprom.cpp
            board/rt1051/purefs/src/blkdev/disk_emmc.cpp
            board/rt1051/purefs/src/fs/thread_local_cwd.cpp
            board/rt1051/purefs/src/vfs_subsystem_internal.cpp
        >
        $<$<STREQUAL:${PROJECT_TARGET},TARGET_Linux>:
            board/linux/purefs/include/purefs/blkdev/disk_image.hpp
            board/linux/purefs/src/blkdev/disk_image.cpp
            board/linux/purefs/src/fs/thread_local_cwd.cpp
            board/linux/purefs/src/vfs_subsystem_internal.cpp
        >

        drivers/include/purefs/fs/drivers/directory_handle_littlefs.hpp
        drivers/include/purefs/fs/drivers/directory_handle_vfat.hpp
        drivers/include/purefs/fs/drivers/file_handle_littlefs.hpp
        drivers/include/purefs/fs/drivers/file_handle_vfat.hpp
        drivers/include/purefs/fs/drivers/filesystem_littlefs.hpp
        drivers/include/purefs/fs/drivers/filesystem_vfat.hpp
        drivers/include/purefs/fs/drivers/mount_point_littlefs.hpp
        drivers/include/purefs/fs/drivers/mount_point_vfat.hpp
        drivers/include/thirdparty/fatfs/ffconf.h
        drivers/include/thirdparty/fatfs/volume_mapper.hpp
        drivers/include/thirdparty/littlefs/volume_mapper.hpp
        drivers/src/purefs/fs/filesystem_littlefs.cpp
        drivers/src/purefs/fs/filesystem_vfat.cpp
        drivers/src/thirdparty/fatfs/ff_glue.cpp
        drivers/src/thirdparty/fatfs/ffsystem.cpp
        drivers/src/thirdparty/littlefs/lfs_glue.cpp
        src/purefs/filesystem_paths.cpp

        include/internal/purefs/blkdev/disk_handle.hpp
        include/internal/purefs/blkdev/partition_parser.hpp
        include/internal/purefs/fs/filesystem_operations.hpp
        include/internal/purefs/fs/notifier.hpp
        include/internal/purefs/fs/thread_local_cwd.hpp
        include/internal/purefs/vfs_subsystem_internal.hpp

        src/purefs/blkdev/disk_handle.cpp
        src/purefs/blkdev/disk_manager.cpp
        src/purefs/blkdev/disk.cpp
        src/purefs/blkdev/partition_parser.cpp
        src/purefs/blkdev/disk_handle.cpp
        src/purefs/fs/filesystem.cpp
        src/purefs/filesystem_paths.cpp
        src/purefs/fs/filesystem_cwd.cpp
        src/purefs/fs/filesystem_operations.cpp
        src/purefs/fs/filesystem_syscalls.cpp
        src/purefs/fs/filesystem_cwd.cpp
        src/purefs/vfs_subsystem.cpp
        src/purefs/fs/notifier.cpp
        src/purefs/fs/filesystem.cpp
        src/purefs/fs/fsnotify.cpp
        drivers/src/purefs/fs/filesystem_vfat.cpp
        drivers/src/purefs/fs/filesystem_littlefs.cpp
        ${BOARD_SOURCES}
        src/purefs/fs/notifier.cpp
        src/purefs/vfs_subsystem.cpp

    PUBLIC
        include/user/newlib/vfs_io_syscalls.hpp
        include/user/purefs/blkdev/defs.hpp
        include/user/purefs/blkdev/disk_manager.hpp
        include/user/purefs/blkdev/disk.hpp
        include/user/purefs/blkdev/partition.hpp
        include/user/purefs/filesystem_paths.hpp
        include/user/purefs/fs/directory_handle.hpp
        include/user/purefs/fs/file_handle.hpp
        include/user/purefs/fs/filesystem.hpp
        include/user/purefs/fs/fsnotify.hpp
        include/user/purefs/fs/handle_mapper.hpp
        include/user/purefs/fs/inotify_flags.hpp
        include/user/purefs/fs/inotify_message.hpp
        include/user/purefs/fs/inotify.hpp
        include/user/purefs/fs/mount_flags.hpp
        include/user/purefs/fs/mount_point.hpp
        include/user/purefs/vfs_subsystem.hpp
)

# Board specific compilation definitions,options,include directories and features
target_compile_definitions(module-vfs PUBLIC ${PROJECT_CONFIG_DEFINITIONS})
target_compile_definitions(module-vfs PUBLIC ${PROJECT_TARGET})
target_compile_definitions(module-vfs PUBLIC ${TARGET_COMPILE_DEFINITIONS})


@@ 44,27 88,29 @@ target_compile_options(module-vfs PUBLIC ${TARGET_COMPILE_OPTIONS})
target_link_options(module-vfs PUBLIC ${TARGET_LINK_OPTIONS})

target_include_directories(module-vfs
    PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}/include/user/
        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/include
    PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/include/internal
        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/include/thirdparty/fatfs
        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/include/thirdparty
        ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/fatfs/source
        $<BUILD_INTERFACE:
            $<$<STREQUAL:${PROJECT_TARGET},TARGET_RT1051>:${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/purefs/include>
            $<$<STREQUAL:${PROJECT_TARGET},TARGET_Linux>:${CMAKE_CURRENT_SOURCE_DIR}/board/linux/purefs/include>
            ${CMAKE_CURRENT_SOURCE_DIR}/drivers/include
            ${CMAKE_CURRENT_SOURCE_DIR}/drivers/include/thirdparty
            ${CMAKE_CURRENT_SOURCE_DIR}/drivers/include/thirdparty/fatfs
            ${CMAKE_CURRENT_SOURCE_DIR}/include/internal
        >
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/user/>
)

target_link_libraries(module-vfs 
    PUBLIC 
        ${TARGET_LIBRARIES} 
        module-os
        module-sys
        module-bsp 
        module-utils
    PRIVATE 
        littlefs::littlefs
        json::json
        fatfs::fatfs
        json::json
        littlefs::littlefs
        module-bsp 
        module-os
        module-utils
    PUBLIC 
        module-sys
)

if (${ENABLE_TESTS})

R module-vfs/src/newlib/vfs_io_syscalls.cpp => module-vfs/board/rt1051/newlib/vfs_io_syscalls.cpp +0 -1
@@ 399,4 399,3 @@ namespace vfsn::internal::syscalls
    }

} // namespace vfsn::internal::syscalls


R module-vfs/include/internal/newlib/vfs_io_syscalls.hpp => module-vfs/include/user/newlib/vfs_io_syscalls.hpp +0 -0
D module-vfs/targets/Target_Linux.cmake => module-vfs/targets/Target_Linux.cmake +0 -11
@@ 1,11 0,0 @@
set(BOARD_SOURCES
        ${CMAKE_CURRENT_SOURCE_DIR}/board/linux/purefs/src/blkdev/disk_image.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/board/linux/purefs/src/fs/thread_local_cwd.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/board/linux/purefs/src/vfs_subsystem_internal.cpp
        CACHE INTERNAL ""
)

set(BOARD_DIR_INCLUDES
        ${CMAKE_CURRENT_SOURCE_DIR}/board/linux/purefs/include/
        CACHE INTERNAL ""
)

D module-vfs/targets/Target_RT1051.cmake => module-vfs/targets/Target_RT1051.cmake +0 -16
@@ 1,16 0,0 @@
set(BOARD_SOURCES ${BOARD_SOURCES}
        ${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/purefs/src/blkdev/disk_emmc.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/purefs/src/blkdev/disk_eeprom.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/purefs/src/fs/thread_local_cwd.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/purefs/src/vfs_subsystem_internal.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/newlib/vfs_io_syscalls.cpp
        CACHE INTERNAL ""
)

set(BOARD_DIR_INCLUDES ${BOARD_DIR_INCLUDES}
    ${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051
    ${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/purefs/include/
    CACHE INTERNAL ""
)



M module-vfs/tests/CMakeLists.txt => module-vfs/tests/CMakeLists.txt +10 -8
@@ 10,6 10,8 @@ add_catch2_executable(
    NAME vfs-disk
    SRCS
        ${CMAKE_CURRENT_LIST_DIR}/unittest_disk_manager.cpp
    INCLUDE
        $<TARGET_PROPERTY:module-vfs,INCLUDE_DIRECTORIES>
    LIBS
        module-sys
        module-vfs


@@ 21,8 23,8 @@ add_catch2_executable(
    NAME vfs-core-fs
    SRCS
        ${CMAKE_CURRENT_LIST_DIR}/unittest_filesystem_core.cpp
    INCLUDE 
        ${CMAKE_CURRENT_SOURCE_DIR}/../include/internal
    INCLUDE
        $<TARGET_PROPERTY:module-vfs,INCLUDE_DIRECTORIES>
    LIBS
        module-sys
        module-vfs


@@ 40,8 42,8 @@ add_catch2_executable(
    NAME vfs-littlefs
    SRCS
        ${CMAKE_CURRENT_LIST_DIR}/unittest_filesystem_littlefs.cpp
    INCLUDE 
        ${CMAKE_CURRENT_SOURCE_DIR}/../include/internal
    INCLUDE
        $<TARGET_PROPERTY:module-vfs,INCLUDE_DIRECTORIES>
    LIBS
        module-sys
        module-vfs


@@ 53,8 55,8 @@ add_catch2_executable(
    NAME vfs-dualmount
    SRCS
        ${CMAKE_CURRENT_LIST_DIR}/unittest_filesystem_dualmount.cpp
    INCLUDE 
        ${CMAKE_CURRENT_SOURCE_DIR}/../include/internal
    INCLUDE
        $<TARGET_PROPERTY:module-vfs,INCLUDE_DIRECTORIES>
    LIBS
        module-sys
        module-vfs


@@ 69,8 71,8 @@ add_catch2_executable(
    LIBS
        module-sys
        module-vfs
    INCLUDE 
        ${CMAKE_CURRENT_SOURCE_DIR}/../include/internal
    INCLUDE
        $<TARGET_PROPERTY:module-vfs,INCLUDE_DIRECTORIES>
)

# prepare test assets

M products/BellHybrid/CMakeLists.txt => products/BellHybrid/CMakeLists.txt +2 -0
@@ 50,6 50,8 @@ target_link_libraries(BellHybrid
        application-music-player
        messagetype
        module-apps
        module-bsp
        module-vfs
        service-bluetooth
        service-desktop
        service-lwip

M products/PurePhone/CMakeLists.txt => products/PurePhone/CMakeLists.txt +2 -0
@@ 57,6 57,8 @@ target_link_libraries(PurePhone
        application-phonebook
        messagetype
        module-apps
        module-bsp
        module-vfs
        service-bluetooth
        service-desktop
        service-lwip

A tools/catch_duplicates.py => tools/catch_duplicates.py +48 -0
@@ 0,0 1,48 @@
#!/usr/bin/python3
# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

# Script detecting source files which are compiled twice and listing libraries where they are compiled
# Usage example: ./catch_duplicates.py ../build-rt1051-Release/compile_commands.json > what_compiles_twice.log

import sys, json

def print_duplicates(filename, occurs):
	print_duplicates.duplicate_number += 1
	print("Duplicate " + str(print_duplicates.duplicate_number) + "\n" + filename)
	for val in occurs:
		print(val)
	print("")
print_duplicates.duplicate_number = 0


def main():
	file_handle = open(sys.argv[1], "r")
	cc_dict = json.load(file_handle)
	known_files = set()

	for x in range(len(cc_dict)):
		filename1 = str(cc_dict[x]['file'])
		directory1 = str(cc_dict[x]['directory'])
		occurs = set()
		occurs.add(directory1)

		if filename1 not in known_files:

			for y in range(len(cc_dict)):
				filename2 = str(cc_dict[y]['file'])
				directory2 = str(cc_dict[y]['directory'])

				if filename1 == filename2 and x != y:
					occurs.add(directory2)

		if len(occurs) > 1:
			print_duplicates(filename1, occurs)
		
		known_files.add(filename1)

	file_handle.close()


if __name__ == '__main__':
    main()