From 98b99155f84b5107208f55516d07e812d8ab0a68 Mon Sep 17 00:00:00 2001 From: Noah Zemlin Date: Thu, 27 Feb 2020 13:21:48 -0600 Subject: [PATCH] Automatic Keyword Generation (#29) * Automatic keyword generation - Adds automatic keyword generation when running build.sh using https://github.com/r89m/arduino-keywords - Updates keywords.txt using the automatic keyword generation - Updates CI to test for correct keywords.txt - Updates dependency installation process * Fix dependencies for dependencies * Install wheel first * Temporarily enable keyword verifcation output * Upgrade pip in deps * Use direct path to arduino-keywords * Use set comparison for keyword verification * Create keywords directory --- .github/workflows/robotlib.yml | 4 ++- .gitignore | 5 +-- README.md | 4 +++ build-avr.sh | 4 +-- build.sh | 16 ++++++--- install-deps.sh | 8 +++++ keywords.txt | 60 +++++++++++++++++++++++----------- tests/README.md | 4 +-- verify-keywords | 29 ++++++++++++++++ 9 files changed, 103 insertions(+), 31 deletions(-) create mode 100755 install-deps.sh create mode 100755 verify-keywords diff --git a/.github/workflows/robotlib.yml b/.github/workflows/robotlib.yml index b8979ee..52c94f6 100644 --- a/.github/workflows/robotlib.yml +++ b/.github/workflows/robotlib.yml @@ -8,7 +8,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Install deps - run: sudo apt-get install lcov gcc-avr binutils-avr avr-libc + run: ./install-deps.sh + - name: Verify keywords + run: ./verify-keywords - name: Run build-avr run: ./build-avr.sh - name: Run build diff --git a/.gitignore b/.gitignore index 7d7755b..206a6f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ -#ignore build files +# Ignore build and dev files build/ +keywords/ .vscode/ -#ignore coverage files +# Ignore coverage files out/ *.gch \ No newline at end of file diff --git a/README.md b/README.md index f4e2d07..7c6c51d 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,7 @@ You can view examples using RobotLib in Arduino. Go to File > Examples > RobotLi ## Installation and Documentation Instructions for how to install as well as documentation are both available on [our Github wiki](https://github.com/Sooner-Competitive-Robotics/RobotLib/wiki). + +## Contributing + +Please see [tests/README.md](tests/README.md). \ No newline at end of file diff --git a/build-avr.sh b/build-avr.sh index ea1025b..ba9a275 100755 --- a/build-avr.sh +++ b/build-avr.sh @@ -1,8 +1,8 @@ -#make build dir +# Make build dir rm -r build #for local development mkdir build cd build -#make the project +# Make the project cmake -DCMAKE_CXX_COMPILER='/usr/bin/avr-gcc' .. make \ No newline at end of file diff --git a/build.sh b/build.sh index 44c4dc7..7011bb3 100755 --- a/build.sh +++ b/build.sh @@ -1,19 +1,25 @@ -#make build dir +# Generate keywords from src folder into ../keywords.txt +~/.local/bin/arduino-keywords src --output .. + +# Remove operator= from keywords.txt +sed -i '/operator=/d' keywords.txt + +# Make build dir rm -r build #for local development mkdir build cd build -#make the project +# Make the project cmake -DCMAKE_BUILD_TYPE=Coverage .. make -#create baseline +# Create baseline lcov -c -i -d src/CMakeFiles/ -o base.info -#testing +# Testing ctest --output-on-failure . -#merge baseline with testing +# Merge baseline with testing lcov -c -d tests/CMakeFiles/ -o test.info lcov -l test.info #debug lcov -a base.info -a test.info -o total.info #merge base and test info diff --git a/install-deps.sh b/install-deps.sh new file mode 100755 index 0000000..aa05e2c --- /dev/null +++ b/install-deps.sh @@ -0,0 +1,8 @@ +# Dependencies for building +sudo apt-get update +sudo apt-get install gcc lcov gcc-avr binutils-avr avr-libc -y + +# Depdendencies for arduinokeywords +sudo apt-get install python-pip -y +python -m pip install --upgrade pip setuptools wheel +pip install arduinokeywords \ No newline at end of file diff --git a/keywords.txt b/keywords.txt index d68e460..5fc9f4a 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,36 +1,58 @@ +BusInOut KEYWORD1 +mode KEYWORD2 +read KEYWORD2 +write KEYWORD2 Encoder KEYWORD1 -HallEffectEncoder KEYWORD1 -Motor KEYWORD1 -PIDController KEYWORD1 -QuadratureEncoder KEYWORD1 -RLUtil KEYWORD1 -StepperMotor KEYWORD1 -TrackingLoop KEYWORD1 -pullup KEYWORD2 +getTicks KEYWORD2 +getValue KEYWORD2 process KEYWORD2 reset KEYWORD2 +HallEffectEncoder KEYWORD1 +begin KEYWORD2 getTicks KEYWORD2 getValue KEYWORD2 -begin KEYWORD2 +process KEYWORD2 +reset KEYWORD2 setDirection KEYWORD2 -reverse KEYWORD2 -setDefaultOnZero KEYWORD2 -output KEYWORD2 -outputBool KEYWORD2 +Motor KEYWORD1 +begin KEYWORD2 disableOutput KEYWORD2 enableOutput KEYWORD2 getNumPins KEYWORD2 +output KEYWORD2 +outputBool KEYWORD2 +reverse KEYWORD2 +setDefaultOnZero KEYWORD2 +PIDController KEYWORD1 +begin KEYWORD2 +getIntegratorValue KEYWORD2 +reset KEYWORD2 setBounded KEYWORD2 +setIntegratorBounds KEYWORD2 setOutputRange KEYWORD2 +setTolerance KEYWORD2 update KEYWORD2 -getIntegratorValue KEYWORD2 +QuadratureEncoder KEYWORD1 +begin KEYWORD2 +getTicks KEYWORD2 +getValue KEYWORD2 +process KEYWORD2 +pullup KEYWORD2 +reset KEYWORD2 +setResolution KEYWORD2 +RLUtil KEYWORD1 clamp KEYWORD2 lerp KEYWORD2 slerp KEYWORD2 -step KEYWORD2 -setRPM KEYWORD2 +StepperMotor KEYWORD1 +begin KEYWORD2 getCurrentSteps KEYWORD2 +reset KEYWORD2 +setRPM KEYWORD2 +step KEYWORD2 +TrackingLoop KEYWORD1 +getAccelEstimate KEYWORD2 +getPositionEstimate KEYWORD2 getVelocityEstimate KEYWORD2 -getAccelEstimate KEYWORD2 -setIntegratorBounds KEYWORD2 -setTolerance KEYWORD2 \ No newline at end of file +reset KEYWORD2 +update KEYWORD2 diff --git a/tests/README.md b/tests/README.md index 5d6080c..3de3141 100644 --- a/tests/README.md +++ b/tests/README.md @@ -13,8 +13,8 @@ The build process will automatically find your new file during compilation. ## Running tests locally -First, make sure you have gcc and lcov installed. +First, make sure you have necessary dependencies. -`sudo apt-get install gcc lcov` +`./install-deps.sh` You can run the unit tests by running `build.sh` while in base directory. This will create a new folder `build` with all the output. Any errors will be shown in stdout along with a brief summary of the coverage. If you would like to view a summary of the coverage in a webpage, you can run `genhtml build/total.info -o out/` and it will create a folder `out` that contains a static website. \ No newline at end of file diff --git a/verify-keywords b/verify-keywords new file mode 100755 index 0000000..d898bad --- /dev/null +++ b/verify-keywords @@ -0,0 +1,29 @@ +#! /usr/bin/env python +import os +import sys + +# Run arduino-keywords +os.system("mkdir keywords") +os.system("~/.local/bin/arduino-keywords src --output ../keywords > /dev/null 2>&1") +os.system("sed -i '/operator=/d' keywords/keywords.txt > /dev/null 2>&1") + +# Get a set of the lines from a file +# Using a set to ignore order (as arduino-keyword search order is system dependent) +def get_keywords(filename): + results = set() + with open(filename, "r") as f: + for line in f: + results.add(line) + return results + +# Read both keywords.txt +existing_set = get_keywords("keywords.txt") +new_set = get_keywords("keywords/keywords.txt") + +# Are they the same? +if existing_set != new_set: + print("keywords.txt is not correct. Please run build.sh to generate keywords.txt!") + print("Differences:") + for keyword in existing_set.symmetric_difference(new_set): + print(keyword) + sys.exit(1) \ No newline at end of file