Commit bbe5e1e6 authored by Yong Cong Sin's avatar Yong Cong Sin Committed by Henrik Brix Andersen
Browse files

build: namespace the generated headers with `zephyr/`



Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: default avatarYong Cong Sin <ycsin@meta.com>
parent d034106b
Loading
Loading
Loading
Loading
+40 −18
Original line number Diff line number Diff line
@@ -109,6 +109,15 @@ add_library(zephyr_interface INTERFACE)
# flags that come with zephyr_interface.
zephyr_library_named(zephyr)

if(CONFIG_LEGACY_GENERATED_INCLUDE_PATH)
  zephyr_include_directories(${PROJECT_BINARY_DIR}/include/generated/zephyr)
  message(WARNING "
    Warning: CONFIG_LEGACY_GENERATED_INCLUDE_PATH is currently enabled by default
    so that user applications can continue to use the legacy include paths for the
    generated headers. This Kconfig will be deprecated and eventually removed in
    the future releases.")
endif()

zephyr_include_directories(
  include
  ${PROJECT_BINARY_DIR}/include/generated
@@ -541,9 +550,9 @@ if(ZEPHYR_GIT_INDEX)
endif()

add_custom_command(
  OUTPUT ${PROJECT_BINARY_DIR}/include/generated/version.h
  OUTPUT ${PROJECT_BINARY_DIR}/include/generated/zephyr/version.h
  COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE}
    -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/version.h
    -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/zephyr/version.h
    -DVERSION_TYPE=KERNEL
    -DVERSION_FILE=${ZEPHYR_BASE}/VERSION
    -DKERNEL_VERSION_CUSTOMIZATION="$<TARGET_PROPERTY:version_h,KERNEL_VERSION_CUSTOMIZATION>"
@@ -552,13 +561,13 @@ add_custom_command(
  DEPENDS ${ZEPHYR_BASE}/VERSION ${git_dependency}
  COMMAND_EXPAND_LISTS
)
add_custom_target(version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/version.h)
add_custom_target(version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/zephyr/version.h)

if(EXISTS ${APPLICATION_SOURCE_DIR}/VERSION)
  add_custom_command(
    OUTPUT ${PROJECT_BINARY_DIR}/include/generated/app_version.h
    OUTPUT ${PROJECT_BINARY_DIR}/include/generated/zephyr/app_version.h
    COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE}
      -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/app_version.h
      -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/zephyr/app_version.h
      -DVERSION_TYPE=APP
      -DVERSION_FILE=${APPLICATION_SOURCE_DIR}/VERSION
      -DAPP_VERSION_CUSTOMIZATION="$<TARGET_PROPERTY:app_version_h,APP_VERSION_CUSTOMIZATION>"
@@ -567,7 +576,9 @@ if(EXISTS ${APPLICATION_SOURCE_DIR}/VERSION)
    DEPENDS ${APPLICATION_SOURCE_DIR}/VERSION ${git_dependency}
    COMMAND_EXPAND_LISTS
  )
  add_custom_target(app_version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/app_version.h)
  add_custom_target(
    app_version_h
    DEPENDS ${PROJECT_BINARY_DIR}/include/generated/zephyr/app_version.h)
  add_dependencies(zephyr_interface app_version_h)
endif()

@@ -622,8 +633,8 @@ set(ZEPHYR_CURRENT_CMAKE_DIR)
get_property(LIBC_LINK_LIBRARIES TARGET zephyr_interface PROPERTY LIBC_LINK_LIBRARIES)
zephyr_link_libraries(${LIBC_LINK_LIBRARIES})

set(syscall_list_h   ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h)
set(edk_syscall_list_h   ${CMAKE_CURRENT_BINARY_DIR}/edk/include/generated/syscall_list.h)
set(syscall_list_h   ${CMAKE_CURRENT_BINARY_DIR}/include/generated/zephyr/syscall_list.h)
set(edk_syscall_list_h   ${CMAKE_CURRENT_BINARY_DIR}/edk/include/generated/zephyr/syscall_list.h)
set(syscalls_json    ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls.json)
set(struct_tags_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/struct_tags.json)

@@ -761,7 +772,7 @@ add_custom_target(${SYSCALL_LIST_H_TARGET} DEPENDS ${syscall_list_h} ${picolibc_
set_property(TARGET ${SYSCALL_LIST_H_TARGET}
             APPEND PROPERTY
             ADDITIONAL_CLEAN_FILES
             ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscalls
             ${CMAKE_CURRENT_BINARY_DIR}/include/generated/zephyr/syscalls
)

add_custom_target(${PARSE_SYSCALLS_TARGET}
@@ -781,19 +792,30 @@ if(CONFIG_TIMEOUT_64BIT)
  set(SYSCALL_SPLIT_TIMEOUT_ARG --split-type k_timeout_t --split-type k_ticks_t)
endif()

# percepio/TraceRecorder/kernelports/Zephyr/scripts/tz_parse_syscalls.py hardcodes the path
# to the `syscall_list.h`, make a copy of the generated file so that percepio is able to build
if(CONFIG_LEGACY_GENERATED_INCLUDE_PATH)
  set(LEGACY_SYSCALL_LIST_H_ARGS
    ${CMAKE_COMMAND} -E copy
    ${syscall_list_h}
    ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h)
endif()

add_custom_command(OUTPUT include/generated/syscall_dispatch.c ${syscall_list_h}
  # Also, some files are written to include/generated/syscalls/
  # Also, some files are written to include/generated/zephyr/syscalls/
  COMMAND
  ${PYTHON_EXECUTABLE}
  ${ZEPHYR_BASE}/scripts/build/gen_syscalls.py
  --json-file        ${syscalls_json}                     # Read this file
  --base-output      include/generated/syscalls           # Write to this dir
  --base-output      include/generated/zephyr/syscalls    # Write to this dir
  --syscall-dispatch include/generated/syscall_dispatch.c # Write this file
  --syscall-export-llext  include/generated/syscall_export_llext.c
  --syscall-list     ${syscall_list_h}
  $<$<BOOL:${CONFIG_USERSPACE}>:--gen-mrsh-files>
  ${SYSCALL_LONG_REGISTERS_ARG}
  ${SYSCALL_SPLIT_TIMEOUT_ARG}
  COMMAND
  ${LEGACY_SYSCALL_LIST_H_ARGS}
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  DEPENDS ${PARSE_SYSCALLS_TARGET}
  )
@@ -801,7 +823,7 @@ add_custom_command(OUTPUT include/generated/syscall_dispatch.c ${syscall_list_h}
# This is passed into all calls to the gen_kobject_list.py script.
set(gen_kobject_list_include_args --include-subsystem-list ${struct_tags_json})

set(DRV_VALIDATION ${PROJECT_BINARY_DIR}/include/generated/driver-validation.h)
set(DRV_VALIDATION ${PROJECT_BINARY_DIR}/include/generated/zephyr/driver-validation.h)
add_custom_command(
  OUTPUT ${DRV_VALIDATION}
  COMMAND
@@ -834,7 +856,7 @@ add_dependencies(zephyr_generated_headers
set(OFFSETS_LIB offsets)

set(OFFSETS_C_PATH ${ARCH_DIR}/${ARCH}/core/offsets/offsets.c)
set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/offsets.h)
set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/zephyr/offsets.h)

add_library(          ${OFFSETS_LIB} OBJECT ${OFFSETS_C_PATH})
target_include_directories(${OFFSETS_LIB} PRIVATE
@@ -1197,7 +1219,7 @@ if(CONFIG_USERSPACE)
    PUBLIC $<TARGET_PROPERTY:zephyr_interface,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
  )

  set(KOBJECT_LINKER_HEADER_DATA "${PROJECT_BINARY_DIR}/include/generated/linker-kobject-prebuilt-data.h")
  set(KOBJECT_LINKER_HEADER_DATA "${PROJECT_BINARY_DIR}/include/generated/zephyr/linker-kobject-prebuilt-data.h")

  add_custom_command(
    OUTPUT ${KOBJECT_LINKER_HEADER_DATA}
@@ -1205,7 +1227,7 @@ if(CONFIG_USERSPACE)
    ${PYTHON_EXECUTABLE}
    ${ZEPHYR_BASE}/scripts/build/gen_kobject_placeholders.py
    --object $<TARGET_OBJECTS:kobj_prebuilt_hash_output_lib>
    --outdir ${PROJECT_BINARY_DIR}/include/generated
    --outdir ${PROJECT_BINARY_DIR}/include/generated/zephyr
    --datapct ${CONFIG_KOBJECT_DATA_AREA_RESERVE_EXTRA_PERCENT}
    --rodata ${CONFIG_KOBJECT_RODATA_AREA_EXTRA_BYTES}
    $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
@@ -1962,7 +1984,7 @@ if(LOG_DICT_DB_NAME_ARG)
      ${ZEPHYR_BASE}/scripts/logging/dictionary/database_gen.py
      ${KERNEL_ELF_NAME}
      ${LOG_DICT_DB_NAME_ARG}=${LOG_DICT_DB_NAME}
      --build-header ${PROJECT_BINARY_DIR}/include/generated/version.h
      --build-header ${PROJECT_BINARY_DIR}/include/generated/zephyr/version.h
    WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
    COMMENT "Generating logging dictionary database: ${LOG_DICT_DB_NAME}"
    DEPENDS ${logical_target_for_zephyr_elf}
@@ -2093,12 +2115,12 @@ add_custom_command(
    OUTPUT ${llext_edk_file}
    # Regenerate syscalls in case CONFIG_LLEXT_EDK_USERSPACE_ONLY
    COMMAND ${CMAKE_COMMAND}
        -E make_directory edk/include/generated
        -E make_directory edk/include/generated/zephyr
    COMMAND
        ${PYTHON_EXECUTABLE}
        ${ZEPHYR_BASE}/scripts/build/gen_syscalls.py
        --json-file        ${syscalls_json}                     # Read this file
        --base-output      edk/include/generated/syscalls           # Write to this dir
        --base-output      edk/include/generated/zephyr/syscalls           # Write to this dir
        --syscall-dispatch edk/include/generated/syscall_dispatch.c # Write this file
        --syscall-list     ${edk_syscall_list_h}
        $<$<BOOL:${CONFIG_LLEXT_EDK_USERSPACE_ONLY}>:--userspace-only>
+17 −0
Original line number Diff line number Diff line
@@ -1048,3 +1048,20 @@ config BOOTLOADER_BOSSA_ADAFRUIT_UF2
endchoice

endmenu

menu "Compatibility"

config LEGACY_GENERATED_INCLUDE_PATH
	bool "Legacy include path for generated headers"
	default y
	help
	  Allow applications and libraries to use the Zephyr legacy include
	  path for the generated headers which does not use the `zephyr/` prefix.

	  From now on, i.e., the preferred way to include the `version.h` header is to
	  use <zephyr/version.h>, this Kconfig is currently enabled by default so that
	  user applications won't immediately fail to compile.

	  This Kconfig will be deprecated and eventually removed in the future releases.

endmenu
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
#ifndef ZEPHYR_ARCH_ARC_INCLUDE_OFFSETS_SHORT_ARCH_H_
#define ZEPHYR_ARCH_ARC_INCLUDE_OFFSETS_SHORT_ARCH_H_

#include <offsets.h>
#include <zephyr/offsets.h>

/* kernel */

+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
#ifndef ZEPHYR_ARCH_ARM_INCLUDE_OFFSETS_SHORT_ARCH_H_
#define ZEPHYR_ARCH_ARM_INCLUDE_OFFSETS_SHORT_ARCH_H_

#include <offsets.h>
#include <zephyr/offsets.h>

/* kernel */

+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
#include <zephyr/toolchain.h>
#include <zephyr/linker/sections.h>
#include <zephyr/arch/cpu.h>
#include <offsets.h>
#include <zephyr/offsets.h>
#include "boot.h"
#include "macro_priv.inc"

Loading