optimize build scripts

This commit is contained in:
Neucrack
2025-04-09 15:59:52 +08:00
parent 65eb914c21
commit 060a19bccd
13 changed files with 49 additions and 51 deletions

View File

@@ -75,16 +75,16 @@ def get_components_files(components, valid_components, kconfigs):
files[name] = []
return files
def get_component_requirements(component_name, component_dir, find_dirs):
def get_component_requirements(component_name, component_dir, find_dirs, platform):
requires = []
component_py = os.path.join(component_dir, "component.py")
if os.path.exists(component_py):
found, requires = execute_component_py_func(component_py, "add_requirements", find_dirs)
found, requires = execute_component_py_func(component_py, "add_requirements", platform, find_dirs)
if not found:
requires = []
return requires
def find_valid_components(components, find_dirs):
def find_valid_components(components, find_dirs, platform):
'''
get project depends(not accurately, just exclude some obvious not depend components)
return valid components name
@@ -95,7 +95,7 @@ def find_valid_components(components, find_dirs):
component_py = os.path.join(dir, "component.py")
found = False
if os.path.exists(component_py):
found, depends_component = execute_component_py_func(component_py, "add_requirements", find_dirs)
found, depends_component = execute_component_py_func(component_py, "add_requirements", platform, find_dirs)
if not found:
cmakelist = os.path.join(dir, "CMakeLists.txt")
with open(cmakelist, "r", encoding="utf-8") as f:
@@ -143,7 +143,7 @@ def get_components_find_dirs(configs):
def get_all_components_dl_info(find_dirs, kconfigs):
components = get_components_dirs(find_dirs)
valid_components = find_valid_components(components, find_dirs)
valid_components = find_valid_components(components, find_dirs, kconfigs["PLATFORM"])
files_info = get_components_files(components, valid_components, kconfigs)
return files_info
@@ -315,18 +315,19 @@ def menuconfig(sdk_path, build_path, configs, gui = True):
if __name__ == "__main__":
cmd = sys.argv[1]
platform = sys.argv[2]
if cmd == "get_valid_components":
find_dirs = sys.argv[2:]
find_dirs = sys.argv[3:]
for dir in find_dirs:
if " " in dir:
raise Exception("Path can not contain space or special characters")
components = get_components_dirs(find_dirs)
valid_components = find_valid_components(components, find_dirs)
valid_components = find_valid_components(components, find_dirs, platform)
print(";".join(valid_components), end="")
elif cmd == "get_requirements":
find_dirs = sys.argv[4:]
find_dirs = sys.argv[5:]
for dir in find_dirs:
if " " in dir:
raise Exception("Path can not contain space or special characters")
requires = get_component_requirements(sys.argv[2], sys.argv[3], find_dirs)
requires = get_component_requirements(sys.argv[3], sys.argv[4], find_dirs, platform)
print(";".join(requires), end="")

View File

@@ -231,7 +231,7 @@ function(register_component)
# Add requirements
# get requirements from component.py
set(cmd COMMAND ${python} -u ${SDK_PATH}/tools/cmake/build.py get_requirements ${component_name} ${component_dir} ${SDK_PATH}/components ${SDK_PATH}/components/3rd_party ${SDK_PATH}/components/ext_devs ${MAIXCDK_EXTRA_COMPONENTS_PATH} ${PY_PKG_COMPONENTS_PATH} ${PY_USR_PKG_COMPONENTS_PATH} ${PROJECT_SOURCE_DIR}/../components ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/components)
set(cmd COMMAND ${python} -u ${SDK_PATH}/tools/cmake/build.py get_requirements ${PLATFORM} ${component_name} ${component_dir} ${SDK_PATH}/components ${SDK_PATH}/components/3rd_party ${SDK_PATH}/components/ext_devs ${MAIXCDK_EXTRA_COMPONENTS_PATH} ${PY_PKG_COMPONENTS_PATH} ${PY_USR_PKG_COMPONENTS_PATH} ${PROJECT_SOURCE_DIR}/../components ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/components)
execute_process(${cmd} RESULT_VARIABLE cmd_res OUTPUT_VARIABLE component_requires)
if(NOT cmd_res EQUAL 0)
message(FATAL_ERROR "Get valid components failed")
@@ -569,7 +569,7 @@ macro(project name)
endif()
# guess components used
set(cmd COMMAND ${python} -u ${SDK_PATH}/tools/cmake/build.py get_valid_components ${SDK_PATH}/components ${SDK_PATH}/components/3rd_party ${SDK_PATH}/components/ext_devs ${MAIXCDK_EXTRA_COMPONENTS_PATH} ${PY_PKG_COMPONENTS_PATH} ${PY_USR_PKG_COMPONENTS_PATH} ${PROJECT_SOURCE_DIR}/../components ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/components)
set(cmd COMMAND ${python} -u ${SDK_PATH}/tools/cmake/build.py get_valid_components ${PLATFORM} ${SDK_PATH}/components ${SDK_PATH}/components/3rd_party ${SDK_PATH}/components/ext_devs ${MAIXCDK_EXTRA_COMPONENTS_PATH} ${PY_PKG_COMPONENTS_PATH} ${PY_USR_PKG_COMPONENTS_PATH} ${PROJECT_SOURCE_DIR}/../components ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/components)
execute_process(${cmd} RESULT_VARIABLE cmd_res OUTPUT_VARIABLE component_valid)
if(NOT cmd_res EQUAL 0)
message(FATAL_ERROR "Get valid components failed")

View File

@@ -26,6 +26,10 @@ def get_code_def(code):
start_idx = 0
while code[start_idx] in [" ", "\t", "\n"]:
start_idx += 1
if code[start_idx:].startswith("//"): # only API comment mode
start_idx += 2
while code[start_idx] in [" ", "\t"]:
start_idx += 1
code = code[start_idx:]
def_type = None
definition = None