mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-27 20:59:29 +01:00
add new command to idf
This commit is contained in:
@@ -758,7 +758,7 @@ endmenu\n" >> ${IDF_PATH}/Kconfig
|
||||
clean_build_dir
|
||||
mkdir -p components/esp32
|
||||
echo "idf_component_get_property(overriden_dir \${COMPONENT_NAME} COMPONENT_OVERRIDEN_DIR)" >> components/esp32/CMakeLists.txt
|
||||
echo "message(STATUS overriden_dir:\${overriden_dir})" >> components/esp32/CMakeLists.txt
|
||||
echo "message(STATUS overriden_dir:\${overriden_dir})" >> components/esp32/CMakeLists.txt
|
||||
(idf.py reconfigure | grep "overriden_dir:$IDF_PATH/components/esp32") || failure "Failed to get overriden dir" # no registration, overrides registration as well
|
||||
print_status "Overriding Kconfig"
|
||||
echo "idf_component_register(KCONFIG \${overriden_dir}/Kconfig)" >> components/esp32/CMakeLists.txt
|
||||
@@ -767,6 +767,44 @@ endmenu\n" >> ${IDF_PATH}/Kconfig
|
||||
(idf.py reconfigure | grep "kconfig:$IDF_PATH/components/esp32/Kconfig") || failure "Failed to verify original `main` directory"
|
||||
rm -rf components
|
||||
|
||||
print_status "Create project using idf.py and build it"
|
||||
echo "Trying to create project."
|
||||
(idf.py -C projects create-project temp_test_project) || failure "Failed to create the project."
|
||||
cd "$IDF_PATH/projects/temp_test_project"
|
||||
echo "Building the project temp_test_project . . ."
|
||||
idf.py build || failure "Failed to build the project."
|
||||
cd "$IDF_PATH"
|
||||
rm -rf "$IDF_PATH/projects/temp_test_project"
|
||||
|
||||
print_status "Create component using idf.py, create project using idf.py."
|
||||
print_status "Add the component to the created project and build the project."
|
||||
echo "Trying to create project . . ."
|
||||
(idf.py -C projects create-project temp_test_project) || failure "Failed to create the project."
|
||||
echo "Trying to create component . . ."
|
||||
(idf.py -C components create-component temp_test_component) || failure "Failed to create the component."
|
||||
${SED} -i '5i\\tfunc();' "$IDF_PATH/projects/temp_test_project/main/temp_test_project.c"
|
||||
${SED} -i '5i#include "temp_test_component.h"' "$IDF_PATH/projects/temp_test_project/main/temp_test_project.c"
|
||||
cd "$IDF_PATH/projects/temp_test_project"
|
||||
idf.py build || failure "Failed to build the project."
|
||||
cd "$IDF_PATH"
|
||||
rm -rf "$IDF_PATH/projects/temp_test_project"
|
||||
rm -rf "$IDF_PATH/components/temp_test_component"
|
||||
|
||||
print_status "Check that command for creating new project will fail if the target folder is not empty."
|
||||
mkdir "$IDF_PATH/example_proj/"
|
||||
touch "$IDF_PATH/example_proj/tmp_130698"
|
||||
EXPECTED_EXIT_VALUE=3
|
||||
expected_failure $EXPECTED_EXIT_VALUE idf.py create-project --path "$IDF_PATH/example_proj/" temp_test_project || failure "Command exit value is wrong."
|
||||
rm -rf "$IDF_PATH/example_proj/"
|
||||
|
||||
print_status "Check that command for creating new project will fail if the target path is file."
|
||||
touch "$IDF_PATH/example_proj"
|
||||
EXPECTED_EXIT_VALUE=4
|
||||
expected_failure $EXPECTED_EXIT_VALUE idf.py create-project --path "$IDF_PATH/example_proj" temp_test_project || failure "Command exit value is wrong."
|
||||
rm -rf "$IDF_PATH/example_proj"
|
||||
|
||||
|
||||
|
||||
print_status "All tests completed"
|
||||
if [ -n "${FAILURES}" ]; then
|
||||
echo "Some failures were detected:"
|
||||
@@ -791,6 +829,15 @@ function failure()
|
||||
FAILURES="${FAILURES}${STATUS} :: $1\n"
|
||||
}
|
||||
|
||||
function expected_failure() {
|
||||
"${@:2}"
|
||||
EXIT_VALUE=$?
|
||||
if [ $EXIT_VALUE != "$1" ]; then
|
||||
echo "[ERROR] Exit value of executed command is $EXIT_VALUE (expected $1)"; return 1
|
||||
else return 0
|
||||
fi
|
||||
}
|
||||
|
||||
TESTDIR=${PWD}/build_system_tests_$$
|
||||
mkdir -p ${TESTDIR}
|
||||
# set NOCLEANUP=1 if you want to keep the test directory around
|
||||
|
||||
@@ -210,6 +210,7 @@ def action_extensions(base_actions, project_path):
|
||||
},
|
||||
{
|
||||
"names": ["-C", "--project-dir"],
|
||||
"scope": "shared",
|
||||
"help": "Project directory.",
|
||||
"type": click.Path(),
|
||||
"default": os.getcwd(),
|
||||
|
||||
120
tools/idf_py_actions/create_ext.py
Normal file
120
tools/idf_py_actions/create_ext.py
Normal file
@@ -0,0 +1,120 @@
|
||||
from __future__ import print_function
|
||||
from distutils.dir_util import copy_tree
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def get_type(action):
|
||||
return action.split("-")[1]
|
||||
|
||||
|
||||
def replace_in_file(filename, pattern, replacement):
|
||||
with open(filename, 'r+') as f:
|
||||
content = f.read()
|
||||
overwritten_content = re.sub(pattern, replacement, content, flags=re.M)
|
||||
f.seek(0)
|
||||
f.write(overwritten_content)
|
||||
f.truncate()
|
||||
|
||||
|
||||
def is_empty_and_create(path, action):
|
||||
abspath = os.path.abspath(path)
|
||||
if not os.path.exists(abspath):
|
||||
os.makedirs(abspath)
|
||||
elif not os.path.isdir(abspath):
|
||||
print("Your target path is not a directory. Please remove the", os.path.abspath(abspath),
|
||||
"or use different target path.")
|
||||
sys.exit(4)
|
||||
elif len(os.listdir(path)) > 0:
|
||||
print("The directory", abspath, "is not empty. To create a", get_type(action),
|
||||
"you must empty the directory or choose a different path.")
|
||||
sys.exit(3)
|
||||
|
||||
|
||||
def create_project(target_path, name):
|
||||
copy_tree(os.path.join(os.environ['IDF_PATH'], "examples", "get-started", "sample_project"), target_path)
|
||||
main_folder = os.path.join(target_path, "main")
|
||||
os.rename(os.path.join(main_folder, "main.c"), os.path.join(main_folder, ".".join((name, "c"))))
|
||||
replace_in_file(os.path.join(main_folder, "CMakeLists.txt"), "main", name)
|
||||
replace_in_file(os.path.join(target_path, "CMakeLists.txt"), "main", name)
|
||||
os.remove(os.path.join(target_path, "README.md"))
|
||||
|
||||
# after manual removing "Makefile" and "component.mk" from `examples/get-started/sample_project`
|
||||
# remove following two lines as well
|
||||
os.remove(os.path.join(target_path, "Makefile"))
|
||||
os.remove(os.path.join(target_path, "main", "component.mk"))
|
||||
|
||||
|
||||
def create_component(target_path, name):
|
||||
copy_tree(os.path.join(os.environ['IDF_PATH'], "tools", "templates", "sample_component"), target_path)
|
||||
os.rename(os.path.join(target_path, "main.c"), os.path.join(target_path, ".".join((name, "c"))))
|
||||
os.rename(os.path.join(target_path, "include", "main.h"),
|
||||
os.path.join(target_path, "include", ".".join((name, "h"))))
|
||||
|
||||
replace_in_file(os.path.join(target_path, ".".join((name, "c"))), "main", name)
|
||||
replace_in_file(os.path.join(target_path, "CMakeLists.txt"), "main", name)
|
||||
|
||||
|
||||
def action_extensions(base_actions, project_path):
|
||||
def create_new(action, ctx, global_args, **action_args):
|
||||
target_path = action_args.get('path') or os.path.join(project_path, action_args['name'])
|
||||
|
||||
is_empty_and_create(target_path, action)
|
||||
|
||||
func_action_map = {"create-project": create_project, "create-component": create_component}
|
||||
func_action_map[action](target_path, action_args['name'])
|
||||
|
||||
print("The", get_type(action), "was created in", os.path.abspath(target_path))
|
||||
|
||||
# after the command execution, no other commands are accepted and idf.py terminates
|
||||
sys.exit(0)
|
||||
|
||||
return {
|
||||
"actions": {
|
||||
"create-project": {
|
||||
"callback": create_new,
|
||||
"short_help": "Create a new project.",
|
||||
"help": ("Create a new project with the name NAME specified as argument. "
|
||||
"For example: "
|
||||
"`idf.py create-project new_proj` "
|
||||
"will create a new project in subdirectory called `new_proj` "
|
||||
"of the current working directory. "
|
||||
"For specifying the new project's path, use either the option --path for specifying the "
|
||||
"destination directory, or the global option -C if the project should be created as a "
|
||||
"subdirectory of the specified directory. "
|
||||
"If the target path does not exist it will be created. If the target folder is not empty "
|
||||
"then the operation will fail with return code 3. "
|
||||
"If the target path is not a folder, the script will fail with return code 4. "
|
||||
"After the execution idf.py terminates "
|
||||
"so this operation should be used alone."),
|
||||
"arguments": [{"names": ["name"]}],
|
||||
"options": [
|
||||
{
|
||||
"names": ["-p", "--path"],
|
||||
"help": ("Set the path for the new project. The project "
|
||||
"will be created directly in the given folder if it does not contain anything"),
|
||||
},
|
||||
],
|
||||
|
||||
},
|
||||
"create-component": {
|
||||
"callback": create_new,
|
||||
"short_help": "Create a new component.",
|
||||
"help": ("Create a new component with the name NAME specified as argument. "
|
||||
"For example: "
|
||||
"`idf.py create-component new_comp` "
|
||||
"will create a new component in subdirectory called `new_comp` "
|
||||
"of the current working directory. "
|
||||
"For specifying the new component's path use the option -C. "
|
||||
"If the target path does not exist then it will be created. "
|
||||
"If the target folder is not empty "
|
||||
"then the operation will fail with return code 3. "
|
||||
"If the target path is not a folder, the script will fail with return code 4. "
|
||||
"After the execution idf.py terminates "
|
||||
"so this operation should be used alone."),
|
||||
"arguments": [{"names": ["name"]}],
|
||||
}
|
||||
}
|
||||
}
|
||||
2
tools/templates/sample_component/CMakeLists.txt
Normal file
2
tools/templates/sample_component/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "main.c"
|
||||
INCLUDE_DIRS "include")
|
||||
1
tools/templates/sample_component/include/main.h
Normal file
1
tools/templates/sample_component/include/main.h
Normal file
@@ -0,0 +1 @@
|
||||
void func(void);
|
||||
7
tools/templates/sample_component/main.c
Normal file
7
tools/templates/sample_component/main.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include "main.h"
|
||||
|
||||
void func(void)
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user