-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add Arduino lib to arduino as IDF component #8115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
654abdd
Iniital commit
PilnyTomas f499a3e
Merge branch 'espressif:master' into add_lib
PilnyTomas f0d0ccb
Fixed naming of the CMakeLists.txt file in the doc text
PilnyTomas 04d5289
Finished the docmentation
PilnyTomas 3dc5190
Updated, but not yet tested script
PilnyTomas 1fe617d
Finished script
PilnyTomas 6725c1e
Merge branch 'master' into add_lib
PilnyTomas 555027b
Merge branch 'master' into add_lib
PilnyTomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#!/bin/bash | ||
HELP="This script help to add library when using arduino-esp32 as an ESP-IDF component | ||
The script accepts up to three arguments: | ||
-n NEW: URL address to new library on GIThub (cannot be combined with -e) | ||
-l LOCAL: Path to the project where the library should be placed locally (must be paired with -e or -n) | ||
-e EXISTING: path to existing libary- this will simply skip the download (cannot be combined with -n) | ||
|
||
Examples: | ||
./add_lib.sh -n https://github.com/me-no-dev/ESPAsyncWebServer | ||
./add_lib.sh -l ~/esp/esp-idf/examples/your_project | ||
./add_lib.sh -e ~/Arduino/libraries/existing_library | ||
|
||
./add_lib.sh -n https://github.com/me-no-dev/ESPAsyncWebServer -l ~/esp/esp-idf/examples/your_project | ||
./add_lib.sh -e ~/Arduino/libraries/existing_library -l ~/esp/esp-idf/examples/your_project" | ||
|
||
# Get the directory name where this script is located | ||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
# Construct the absolute path to libraries folder | ||
ARDUINO_LIBS_PATH="$SCRIPT_DIR/../libraries" | ||
|
||
# Define the default values for the parameters | ||
e_param="" | ||
l_param="" | ||
n_param="" | ||
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO the variable names should be more descriptive to help with code maintenance. |
||
|
||
# Parse the command-line arguments using getopts | ||
while getopts "he:l:n:" opt; do | ||
case $opt in | ||
h) | ||
echo "$HELP" | ||
exit 0 | ||
;; | ||
e) | ||
#e_param="$OPTARG" | ||
e_param="${OPTARG/#~/$HOME}" | ||
;; | ||
l) | ||
#l_param="$OPTARG" | ||
l_param="${OPTARG/#~/$HOME}" | ||
;; | ||
n) | ||
n_param=$OPTARG | ||
;; | ||
\?) | ||
echo "Invalid option: -$OPTARG" >&2 | ||
echo $HELP | ||
exit 1 | ||
;; | ||
:) | ||
echo "Option -$OPTARG requires an argument." >&2 | ||
echo $HELP | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# No parameter check | ||
if [[ -z "$e_param" ]] && [[ -z "$l_param" ]] && [[ -z "$n_param" ]]; then | ||
echo "Error: No parameters" >&2 | ||
echo "$HELP" | ||
exit 1 | ||
fi | ||
|
||
# Only local path check (not permitted) | ||
if [[ -z "$e_param" ]] && [[ ! -z "$l_param" ]] && [[ -z "$n_param" ]]; then | ||
echo "Error: -l parameter must be paired with -e or -n" >&2 | ||
echo "$HELP" | ||
exit 1 | ||
fi | ||
|
||
# Invalid combination check | ||
if [[ ! -z $e_param ]] && [[ ! -z $n_param ]]; then | ||
echo "ERROR: Cannot combine -n with -e" >&2 | ||
echo "$HELP" | ||
exit 1 | ||
fi | ||
|
||
# Check existing lib | ||
if [[ ! -z "$e_param" ]]; then | ||
if [[ ! -d "${e_param/#~/$HOME}" ]]; then # this works! | ||
echo "Error: existing library parameter - path does not exist" >&2 | ||
exit 1 | ||
fi | ||
fi | ||
|
||
LIBRARY="" | ||
|
||
# Only existing library was supplied | ||
if [[ ! -z $e_param ]] && [[ -z $l_param ]] && [[ -z $n_param ]]; then | ||
LIBRARY=$e_param | ||
fi | ||
|
||
# Install new lib | ||
if [ ! -z $n_param ]; then | ||
INSTALL_TARGET="" | ||
if [ -z $l_param ]; then | ||
# If local path for project is not supplied - use as INSTALL_TARGET Arduino libraries path | ||
INSTALL_TARGET=$ARDUINO_LIBS_PATH/$(basename "$n_param") | ||
else | ||
INSTALL_TARGET=$l_param/components/$(basename "$n_param") | ||
if [ ! -d "$l_param/components" ]; then | ||
echo "Folder components does not exist yet: mkdir -p "$l_param/components"" | ||
mkdir -p "$l_param/components" | ||
fi | ||
fi | ||
# clone the new lib | ||
echo "Cloning: git clone --recursive $n_param $INSTALL_TARGET" | ||
git clone --recursive $n_param $INSTALL_TARGET | ||
LIBRARY=$INSTALL_TARGET | ||
fi | ||
|
||
# Copy existing lib to local project | ||
if [[ ! -z $e_param ]] && [[ ! -z $l_param ]]; then | ||
if [ ! -d "$l_param/components" ]; then | ||
echo "Folder components does not exist yet: mkdir -p "$l_param/components"" | ||
mkdir -p "$l_param/components" | ||
fi | ||
echo "Copy from $e_param to $l_param" | ||
echo "cp -r $e_param $l_param/components/$(basename "$e_param")" | ||
cp -r $e_param $l_param/components/$(basename "$e_param") | ||
LIBRARY=$l_param/components/$(basename "$e_param") | ||
fi | ||
|
||
|
||
if [ -z "$LIBRARY" ]; then | ||
echo "ERROR: No library path" >&2 | ||
exit 1 | ||
fi | ||
|
||
# 1. get the source list: | ||
FILES=$(find $LIBRARY -name '*.c' -o -name '*.cpp' | xargs -I{} basename {}) | ||
|
||
# Fresh start | ||
if [ -f $LIBRARY/CMakeLists.txt ]; then | ||
rm $LIBRARY/CMakeLists.txt | ||
touch $LIBRARY/CMakeLists.txt | ||
fi | ||
|
||
# Generate CMakeLists.txt | ||
echo "idf_component_register(SRCS $(echo $FILES | sed -e 's/ /" "/g' | sed -e 's/^/"/' -e 's/$/"/')" >> $LIBRARY/CMakeLists.txt | ||
echo " INCLUDE_DIRS \".\"" >> $LIBRARY/CMakeLists.txt | ||
echo " REQUIRES \"arduino-esp32\"" >> $LIBRARY/CMakeLists.txt | ||
echo " )" >> $LIBRARY/CMakeLists.txt |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.