Commit 146352a8 authored by Erwan Gouriou's avatar Erwan Gouriou
Browse files

scripts: ble_library: Simplify script

Remove usage of template for CMakeLists.txt and README generation when
updating BLE library.

Generating CMakeLists.txt for BLE lib is not something that has added
value, in the contrary of CMakeLists.txt use in Cube Package, for which
each file has similar usage. In BLE lib, each file is specific and this
is a developper choice if a file should be added or removed.
Besides, each time this file is generated, the file list ordering is
modified with no reason, which is only generating noise.

Similarly, fully generating README in current case is error prone
as user can't suspect this is a generated file. Hence, users tend
to update README file directly rather than the template file itself.
Modify this to only update the SHA1 and version information.

Signed-off-by: default avatarErwan Gouriou <erwan.gouriou@linaro.org>
parent b8f135ba
Loading
Loading
Loading
Loading
+0 −12
Changes for scripts/ble_CMakeLists_template.txt: 0 added lines, 12 removed lines.
Original line number Diff line number Diff line
# Makefile - STLIB SDK
#
# Copyright (c) 2016 Linaro Limited
#
# SPDX-License-Identifier: Apache-2.0

if(CONFIG_HAS_STM32LIB)
  if(CONFIG_BT_STM32_IPM)
{{include_dir_list}}
{{source_file_list}}
  endif()
endif()
 No newline at end of file

scripts/ble_README_template.txt

deleted100644 → 0
+0 −68
Changes for scripts/ble_README_template.txt: 0 added lines, 68 removed lines.
Original line number Diff line number Diff line
STM32WB HCI
###########

Origin:
   ST Microelectronics
   https://github.com/STMicroelectronics/STM32CubeWB

Status:
   version {{ version }}

Purpose:
   This library is used on stm32wb series to enable HCI communication between
   a host BLE running on CM-4 STM32WB core and a controller BLE firmware running
   on CM-0 core.

Description:
   This library provides an API for shared RAM communication with BLE controller
   firmware running on STM32WB C-M0 core.

   It is build using  the following files extracted the STM32CubeWB package:
{{ extracted_file_list }}
Dependencies:
   This library depends on STM32Cube IPCC HAL API.
   It is available in stm32cube/stm32wbxx/drivers

URL:
   https://github.com/STMicroelectronics/STM32CubeWB

commit:
   {{ commit }}
Maintained-by:
   External

License:
   BSD-3-Clause

License Link:
   opensource.org/licenses/BSD-3-Clause

Patch List:
--> please check that the following list
        * Move some files license from ST SLA0044 to BSD-3 Clause
            Following files are distributed under ST License SLA0044.
            For Zephyr they are made available under BSD-3 Clause.
            - hw_if.h
            - hw_ipcc.c
            - app_common.h
            - app_conf.h
            - stm32_wpan_common.h
            - ble_bufsize.h
            - tl_dbg_conf.h

        *  (Z-WB-1) Remove dependency to hw_conf.h
            This file is not actually needed. Remove inclusion so we don't need
            to include it in library.
          Impacted file: app_conf.h

        *  (Z-WB-2) Remove use of useless section SYSTEM_DRIVER_CONTEXT
            Section has no use. Remove it.
          Impacted file: shci_tl.c

        *  (Z-WB-3) Inform C-M0 that BLE host should not be used.
            In case C-M0 binary includes BLE Host, inform that it should not be
            used as, in Zephyr context, it is  running on C-M4 side.
          Impacted file: app_conf.h


	* Remove trailing whitespaces
+36 −62
Changes for scripts/ble_library.py: 36 added lines, 62 removed lines.
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@ import shutil
import subprocess
from pathlib import Path
import logging
from jinja2 import Environment, FileSystemLoader
from common_utils import common_utils

include_dir = ["stm32wb/hci"]
@@ -89,69 +88,45 @@ def copy_hci_files(src_repo_path, dest_lib_path):
            sys.exit()


def create_ble_lib_readme(dest_lib_path, version, commit):
    """Create README for ble library """
def update_ble_lib_readme(lib_path, make_version, make_commit):
    """Update README file

    # prepare variables for jinja2 template
    extracted_file_list = ""
    for file in file_list:
        extracted_file_list = extracted_file_list + "     " + file + "\n"

    # Create file from Jinja2 template
    templates_dir = dest_lib_path / ".." / "scripts"
    j2_env = Environment(
        loader=FileSystemLoader(str(templates_dir)),
        trim_blocks=True,
        lstrip_blocks=True,
    )
    readme_j2_template = j2_env.get_template("ble_README_template.txt")
    readme_path = dest_lib_path / "stm32wb" / "hci" / "README"
    with open(readme_path, "w") as readme:
        readme.write(
            readme_j2_template.render(
                version=version,
                extracted_file_list=extracted_file_list,
                commit=commit,
            )
        )


def create_ble_lib_cmakelist(dest_lib_path):
    """Create CMakeLists.txt for ble library """
    # remove CMakeLists.txt file before re-creating it
    cmakelist_path = Path(dest_lib_path / "CMakeLists.txt")
    cmakelist_path.unlink()
    Args:
        dest_lib_path: library path
        make_version: latest STM32Cube version.
        make_commit: Commit corresponding to latest STM32Cube version.
    """

    # prepare variables for jinja2 template
    include_dir_list = ""
    source_file_list = ""
    for directory in include_dir:
        include_dir_list = (
            f"{include_dir_list}    zephyr_include_directories({directory})\n"
        )
    for child in Path(dest_lib_path / "stm32wb" / "hci").iterdir():
        if child.is_file and child.suffix == ".c":
            source_file_list = (
                f"{source_file_list}    "
                + f"zephyr_sources(stm32wb/hci/{str(child.name)})\n"
    readme_path = Path(lib_path / "stm32wb" / "hci" / "README")

    with readme_path.open(mode="r") as readme_prev:
        lines = (x for x in readme_prev.read().splitlines())

    readme_path.unlink()

    # Write README from previous one if exists
    with open(str(readme_path), "w") as readme_file:
        for LineItem in lines:
            # change version nb
            if "status" in LineItem.lower():
                readme_file.write("Status:\n")
                readme_file.write(f"   version {make_version}\n")
                next(lines)  # skip next line
            elif "commit" in LineItem.lower():
                readme_file.write("Commit:\n")
                readme_file.write(f"   {make_commit}")
                next(lines)  # skip next line
            # change patch list with a link to the release_note.html
            elif "Patch List" in LineItem:
                readme_file.write("Patch List:\n")
                readme_file.write(
                    "--> please check that the following list "
                    + "is still valid:\n"
                )
            else:
                readme_file.write(f"{LineItem}\n")

    # Create file from Jinja2 template
    templates_dir = dest_lib_path / ".." / "scripts"
    j2_env = Environment(
        loader=FileSystemLoader(str(templates_dir)),
        trim_blocks=True,
        lstrip_blocks=True,
    )
    cmakelists_j2_template = j2_env.get_template("ble_CMakeLists_template.txt")
    cmakelists_txt = dest_lib_path / "CMakeLists.txt"
    with open(cmakelists_txt, "w") as cmakelists:
        cmakelists.write(
            cmakelists_j2_template.render(
                include_dir_list=include_dir_list,
                source_file_list=source_file_list,
            )
        )
        readme_file.flush()


def build_patch_from_current_zephyr_version(
@@ -250,8 +225,7 @@ def update(
    )
    copy_hci_files(src_repo_path, dest_lib_path)
    common_utils.apply_patch(dest_lib_path / "ble_zephyr.patch", dest_lib_path)
    create_ble_lib_readme(dest_lib_path, update_version, commit)
    create_ble_lib_cmakelist(dest_lib_path)
    update_ble_lib_readme(dest_lib_path, update_version, commit)


if __name__ == "__main__":