Skip to content

Commit

Permalink
update tos,support project_version
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingcys committed Aug 16, 2024
1 parent 40426bb commit 1e51c74
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
19 changes: 9 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ add_library(${COMPONENTS_ALL_LIB} STATIC ${all_need})
# add example
set(EXAMPLE_NAME "${TOS_PROJECT_NAME}")
message(STATUS "[TOP] Using example [${EXAMPLE_NAME}].")
if(NOT DEFINED CONFIG_PROJECT_VERSION)
set(CONFIG_PROJECT_VERSION "1.0.0")
endif()
set(EXAMPLE_LIB "tuyaapp")
set(EXAMPLE_VER "1.0.0" CACHE STRING "Example Version")
string(REPLACE ";" " " PLATFORM_NEED_HDIR "${HEADER_DIR}")
set(PLATFORM_NEED_LIBS "${EXAMPLE_LIB} ${COMPONENTS_ALL_LIB}")
message(STATUS "[TOP] PLATFORM_NEED_LIBS: ${PLATFORM_NEED_LIBS}")
Expand Down Expand Up @@ -130,10 +132,7 @@ add_custom_command(
show_menuconfig

COMMAND
${CMAKE_COMMAND} -E echo " ${Cyan}[make menuconfig]${ColourReset}"

COMMAND
${CMAKE_COMMAND} -E echo " ${Cyan}[ccmake ..]${ColourReset}"
${CMAKE_COMMAND} -E echo " ${Cyan}[tos menuconfig]${ColourReset}"

COMMAND
${CMAKE_COMMAND} -E echo ""
Expand All @@ -149,7 +148,7 @@ add_custom_command(
${PLATFORM_PATH}

COMMAND
./build_example.sh "${EXAMPLE_NAME}" "${EXAMPLE_VER}" "${PLATFORM_NEED_HDIR}"
./build_example.sh "${EXAMPLE_NAME}" "${CONFIG_PROJECT_VERSION}" "${PLATFORM_NEED_HDIR}"
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}" "${PLATFORM_NEED_LIBS}"
"${EXECUTABLE_OUTPUT_PATH}" "build" "${PLATFORM_CHIP}"

Expand All @@ -163,7 +162,7 @@ add_custom_target(platform_clean
${PLATFORM_PATH}

COMMAND
./build_example.sh "${EXAMPLE_NAME}" "${EXAMPLE_VER}" "${PLATFORM_NEED_HDIR}"
./build_example.sh "${EXAMPLE_NAME}" "${CONFIG_PROJECT_VERSION}" "${PLATFORM_NEED_HDIR}"
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}" "${PLATFORM_NEED_LIBS}"
"${EXECUTABLE_OUTPUT_PATH}" "clean"

Expand All @@ -176,7 +175,7 @@ add_custom_target(platform_menuconfig
${PLATFORM_PATH}

COMMAND
./build_example.sh "${EXAMPLE_NAME}" "${EXAMPLE_VER}" "${PLATFORM_NEED_HDIR}"
./build_example.sh "${EXAMPLE_NAME}" "${CONFIG_PROJECT_VERSION}" "${PLATFORM_NEED_HDIR}"
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}" "${PLATFORM_NEED_LIBS}"
"${EXECUTABLE_OUTPUT_PATH}" "menuconfig"

Expand All @@ -198,8 +197,8 @@ add_subdirectory("${TOP_SOURCE_DIR}/tools/ut")

# prompt
message(STATUS "[TOP] If you want to build example
${Cyan}[make example]${ColourReset}.
${Cyan}[tos build]${ColourReset}.
")
message(STATUS "[TOP] If you want to clean project
${Cyan}[make clean_all]${ColourReset}.
${Cyan}[tos clean]${ColourReset}.
")
21 changes: 17 additions & 4 deletions tools/kconfiglib/set_catalog_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,24 @@
KCONFIG = "Kconfig"


def set_config(board, src_dir, output_config):
context = "# CatalogKconfig\n"
def set_config(board, src_dir, app_dir, output_config):
context = '''# CatalogKconfig
config PROJECT_VERSION
string "PROJECT_VERSION"
default "1.0.0"
'''
config_path = os.path.join(src_dir, KCONFIG)
if os.path.exists(config_path):
context += f'source \"{config_path}\"\n'
if board:
config_path = os.path.join(board, KCONFIG)
if os.path.exists(config_path):
context += f'source \"{config_path}\"\n'
if app_dir:
config_path = os.path.join(app_dir, KCONFIG)
if os.path.exists(config_path):
context += f'source \"{config_path}\"\n'

with open(output_config, 'w', encoding='utf-8') as f:
f.write(context)
Expand All @@ -38,22 +47,26 @@ def main():
help="Board name. [None]", metavar="")
parse.add_argument('-s', '--src', type=str, default="src",
help="Src directory. [src]", metavar="")
parse.add_argument('-a', '--app', type=str, default=None,
help="Application directory. [None]", metavar="")
parse.add_argument('-o', '--output', type=str, default="cache/Kconfig",
help="Output file of Kconfig. [cache/Kconfig]",
metavar="")
args = parse.parse_args()

board = args.board
src_dir = args.src
app_dir = args.app
output_config = args.output
# print(f'board: {board}')
# print(f'src_dir: {src_dir}')
# print(f'app_dif: {app_dif}')
print(f'output_config: {output_config}')
output_dir = os.path.dirname(output_config)
if not os.path.exists(output_dir):
if output_dir and not os.path.exists(output_dir):
os.makedirs(output_dir)

set_config(board, src_dir, output_config)
set_config(board, src_dir, app_dir, output_config)
pass


Expand Down
15 changes: 10 additions & 5 deletions tools/ut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ endif()
option(UT_ENABLE "Enable UT" OFF)

if(NOT UT_ENABLE)
message(STATUS "[UT] Disable UT.
If you want to use UT,
${Cyan}[ccmake ..]${ColourReset} and turn on ${Cyan}[UT_ENABLE]${ColourReset},
${Cyan}[cmake ..]${ColourReset} again.
")
message(STATUS "[UT] Disable UT.")
return()
endif()

# if(NOT UT_ENABLE)
# message(STATUS "[UT] Disable UT.
# If you want to use UT,
# ${Cyan}[ccmake ..]${ColourReset} and turn on ${Cyan}[UT_ENABLE]${ColourReset},
# ${Cyan}[cmake ..]${ColourReset} again.
# ")
# return()
# endif()

message(STATUS "[UT] Enable UT.
If you want to use UT,
${Cyan}[make pre_test]${ColourReset}.
Expand Down
16 changes: 6 additions & 10 deletions tos
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@ function download_platform()
PLATFORMS_DIR=$OPEN_SDK_ROOT/platform
PLATFORM_PATH="${PLATFORMS_DIR}/${PLATFORM_NAME}"
DEFAULT_CONFIG_NAME="default.config"
KCONFIG_CATALOG=$PLATFORM_PATH/CatalogKconfig
if [ -d "$PLATFORM_PATH" ]; then
show "" "Skip download, exist [$PLATFORM_PATH]."
show "${fore[yellow]}" "If you want to download it again, please remove it."
else
show "" "Download platform ..."
git clone --depth 1 "$PLATFORM_REPO" "$PLATFORM_PATH"
git clone "$PLATFORM_REPO" "$PLATFORM_PATH"
if [ ! "0" = "$?" ]; then
show "${fore[red]}" "Clone repo [$PLATFORM_REPO] failed, please try again."
if [ -d "$PLATFORM_PATH" ]; then
Expand All @@ -102,7 +101,6 @@ function download_platform()
show "${fore[red]}" "Error: not found [$PLATFORM_PATH/$DEFAULT_CONFIG_NAME]."
exit 1
fi
python3 $KCONFIG_TOOLS/set_catalog_config.py -b $PLATFORM_PATH -s $OPEN_SDK_ROOT/src -o $KCONFIG_CATALOG
}

function download_platform_by_name()
Expand Down Expand Up @@ -264,25 +262,23 @@ function menuconfig_exec()
fi
PROJECT_PLATFORM=$(echo "$PROJECT_INFO" | grep -oP '(?<=platform = ).*(?=$)')

if [ ! -d ".build/$PROJ" ]; then
NOTE="The project does not exist yet, run [$OPEN_BUILD build $PROJ] first"
show "${fore[yellow]}" "$NOTE"
exit 1
fi

PLATFORMS_DIR="$OPEN_SDK_ROOT/platform"
PLATFORM_PATH="${PLATFORMS_DIR}/${PROJECT_PLATFORM}"
KCONFIG_CATALOG="$PLATFORM_PATH/CatalogKconfig"
DOT_CONFIG_DIR="$PROJECT_ROOT/.build/$PROJ/cache"
KCONFIG_CATALOG="CatalogKconfig"
DOT_CONFIG="using.config"
CMAKE_CONFIG="using.cmake"
HEADER_DIR="$PROJECT_ROOT/.build/$PROJ/include"
HEADER_FILE="tuya_kconfig.h"
HEADER_IN_PATH="${KCONFIG_TOOLS}/config.h.in"

mkdir -p ${DOT_CONFIG_DIR}
cd ${DOT_CONFIG_DIR}
python3 $KCONFIG_TOOLS/set_catalog_config.py -b $PLATFORM_PATH -s $OPEN_SDK_ROOT/src -a $PROJECT_ROOT -o $KCONFIG_CATALOG
bash ${KCONFIG_TOOLS}/run_menuconfig.sh "${KCONFIG_CATALOG}" "$DOT_CONFIG"
python3 ${KCONFIG_TOOLS}/conf2cmake.py -c "${DOT_CONFIG_DIR}/${DOT_CONFIG}" -o "${CMAKE_CONFIG}"

mkdir -p ${HEADER_DIR}
cd ${HEADER_DIR}
python3 ${KCONFIG_TOOLS}/conf2h.py -c "${DOT_CONFIG_DIR}/${DOT_CONFIG}" -o "${HEADER_FILE}" -i "${HEADER_IN_PATH}"
cd - > /dev/null
Expand Down

0 comments on commit 1e51c74

Please sign in to comment.