|
| 1 | +# Development Tools |
| 2 | + |
| 3 | +### Overview |
| 4 | + |
| 5 | +This directory hosts MySensors development tools. The following |
| 6 | +conventions are employed to facilitate consistent re-use/invocation |
| 7 | +across modalitiies (e.g. local development, continuous integration, |
| 8 | +editor linters, etc.) |
| 9 | + |
| 10 | +1. All common tools are hosted and managed in |
| 11 | + the tools directory (used for both local development |
| 12 | + and continuous integration) |
| 13 | +2. Each tool comprises a directory, akin to a bundle, |
| 14 | + that encapsulates declarative command-line options, |
| 15 | + configuration files and a run script |
| 16 | +3. A single bootstrap script configures a |
| 17 | + development environment |
| 18 | +4. A lightweight runtime provides a common set of |
| 19 | + convenience functions and variables to all scripts |
| 20 | +5. Support for all MySensors development environments |
| 21 | + |
| 22 | +### Usage |
| 23 | + |
| 24 | +The [boostrap-dev](bootstrap-dev.sh) script completely configures a |
| 25 | +development environment. The boostrap-dev script validates development |
| 26 | +prerequisites such as verifying the git repo ```origin``` & |
| 27 | +```upstream``` remotes, tools needed for the git client hooks, |
| 28 | +installing local commit hooks, and creating git aliases, etc. |
| 29 | + |
| 30 | +```shell-script |
| 31 | +$ cd MySensors # git repo |
| 32 | +$ .mystools/bootstrap-dev.sh |
| 33 | +Checking operating system support: darwin16... |
| 34 | +Checking github 'origin' & 'upstream' remotes... |
| 35 | +Checking tool/utility prerequisites... |
| 36 | +Installing git client-side hooks... |
| 37 | +Configuring git aliases for running mysensor tool bundles... |
| 38 | +Successfully configured your repo for MySensors development... Thanks for your support! |
| 39 | +$ |
| 40 | +``` |
| 41 | +**Note:** If the bootstrap can not find required command-line |
| 42 | +utilities, you will be requested to install the required tools and |
| 43 | +re-run bootstrap.sh. See [Installation instructions for prerequisite |
| 44 | +tools](#installtools). |
| 45 | + |
| 46 | +Once the bootstrapping process is complete, a git alias for each tool |
| 47 | +is available to conveniently run the tool with the pre-configured |
| 48 | +mysensors options and settings (no need to remember all those |
| 49 | +command-line options or where the configuration files reside). |
| 50 | +Furthermore, you can run the command against staged files, unstaged |
| 51 | +modified files or a list of files common to most git commands. |
| 52 | + |
| 53 | +```shell-script |
| 54 | +$ # Run cppcheck on an individual file |
| 55 | +$ git cppcheck core/MyMessage.cpp |
| 56 | +$ |
| 57 | +$ # Run cppcheck on all changed files |
| 58 | +$ git cppcheck |
| 59 | +$ |
| 60 | +$ # Run astyle on staged files |
| 61 | +$ git astyle --cached |
| 62 | +``` |
| 63 | + |
| 64 | +Available tool aliases: |
| 65 | + |
| 66 | +* git cppcheck [--cached] [files] |
| 67 | +* git astyle [--cached] [files] |
| 68 | + |
| 69 | +Finally, to maintain code quality and a legible git revision history, |
| 70 | +two git hooks are installed that will trigger whenever you commit |
| 71 | +changes to your local repo. The hooks will examine your changes to |
| 72 | +ensure they satisfy the [MySensors Code Contribution |
| 73 | +Guidelines](https://www.mysensors.org/download/contributing) before |
| 74 | +you push your changes to GitHub for merging by the core MySensors |
| 75 | +team. Gitler will also enforce the coding guidelines so the hooks are |
| 76 | +provided to reduce development cycle times by detecting standards |
| 77 | +variances locally before pushing to GitHub. |
| 78 | + |
| 79 | +### <a name="installtools"></a>Installation instructions for prerequisite tools |
| 80 | + |
| 81 | +This first time you run the bootstrap script, it may inform you that |
| 82 | +certain development tools are missing from your path or system: |
| 83 | + |
| 84 | +``` |
| 85 | +Checking operating system support: darwin16... |
| 86 | +Checking github 'origin' & 'upstream' remotes... |
| 87 | +Checking tool/utility prerequisites... |
| 88 | +astyle not installed or not in current path. |
| 89 | +cppcheck not installed or not in current path. |
| 90 | +One or more required tools not found. Install required tools and re-run .mystools/bootstrap-dev.sh |
| 91 | +``` |
| 92 | + |
| 93 | +To finish the bootstrap process, you will need to install the required |
| 94 | +tools for your specific operating system as follows. Currently we use |
| 95 | +Astyle 2.0.5 or later and Cppcheck 1.76 or later. Once you have |
| 96 | +installed AStyle and Cppcheck, re-run bootstrap-dev.sh to finish |
| 97 | +configuring your development environment. |
| 98 | + |
| 99 | +##### macOS |
| 100 | + |
| 101 | +```brew install astyle cppcheck``` |
| 102 | + |
| 103 | +#### Linux Xenial or later |
| 104 | + |
| 105 | +```apt-get install astyle cppcheck``` |
| 106 | + |
| 107 | +#### Linux Trusty or earlier |
| 108 | + |
| 109 | +##### Note: The apt versions are too old on Trusty so follow the [Linux - Build and Install from Source](#buildFromSource) instructions |
| 110 | + |
| 111 | +##### Windows - GitHub Git Shell |
| 112 | + |
| 113 | +###### *IMPORTANT: Be sure to launch PowerShell As Administrator* |
| 114 | + |
| 115 | +``` |
| 116 | +### Install AStyle |
| 117 | +
|
| 118 | +# Download |
| 119 | +iwr 'https://sourceforge.net/projects/astyle/files/astyle/astyle%202.05.1/AStyle_2.05.1_windows.zip/download' -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::FireFox -OutFile astyle.2.05.zip |
| 120 | +
|
| 121 | +# Unzip the filed & move the C:\Program Files |
| 122 | +expand-archive astyle.2.05.zip |
| 123 | +mv .\astyle.2.05 'C:\Program Files\AStyle\' |
| 124 | +
|
| 125 | +# Add AStyle to your path |
| 126 | +[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\AStyle\bin", [EnvironmentVariableTarget]::Machine) |
| 127 | +
|
| 128 | +### Install Cppcheck (either 64-bit or 32-bit depending upon your version of Windows - pick one below) |
| 129 | +
|
| 130 | +# 64-bit |
| 131 | +iwr 'http://github.com/danmar/cppcheck/releases/download/1.76.1/cppcheck-1.76.1-x64-Setup.msi' -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::FireFox -OutFile cppcheck-1.76.1-Setup.msi |
| 132 | +
|
| 133 | +# 32-bit |
| 134 | +iwr 'http://github.com/danmar/cppcheck/releases/download/1.76.1/cppcheck-1.76.1-x86-Setup.msi' -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::FireFox -OutFile cppcheck-1.76.1-Setup.msi |
| 135 | +
|
| 136 | +# Launch installer to install Cppcheck |
| 137 | +& .\cppcheck-1.76.1-Setup.msi |
| 138 | +
|
| 139 | +### Add Cppcheck to your path |
| 140 | +[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Cppcheck", [EnvironmentVariableTarget]::Machine) |
| 141 | +
|
| 142 | +### At this point you need to reboot for the path changes to take effect |
| 143 | +``` |
| 144 | + |
| 145 | +##### Windows - bash |
| 146 | + |
| 147 | +###### NOTE: At the time of this writing, the apt vresions of cppcheck and astyle are too old. Follow the [Linux - Build and Install from Source](#buildFromSource) instructions |
| 148 | + |
| 149 | +##### Windows - Cygwin |
| 150 | +``` |
| 151 | +Run Either Cygwin Setup-x86-64.exe or Setup-x86.exe depending upon your OS. Select and install astyle and cppcheck |
| 152 | +``` |
| 153 | + |
| 154 | +##### <a name="buildFromSource"></a>Linux - Build and Install from Source |
| 155 | + |
| 156 | +``` |
| 157 | +### Install AStyle |
| 158 | +
|
| 159 | +# Download |
| 160 | +curl -L 'https://sourceforge.net/projects/astyle/files/astyle/astyle%202.05.1/astyle_2.05.1_linux.tar.gz/download' | tar xvz |
| 161 | +
|
| 162 | +# Compile and install |
| 163 | +cd astyle/build/gcc && sudo make shared release shared static install |
| 164 | +
|
| 165 | +### Install Cppcheck |
| 166 | +
|
| 167 | +# Download |
| 168 | +curl -L 'https://sourceforge.net/projects/cppcheck/files/cppcheck/1.76.1/cppcheck-1.76.1.tar.gz/download' | tar xvz |
| 169 | +
|
| 170 | +# Compile and install |
| 171 | +cd cppcheck-1.76.1 |
| 172 | +sudo apt-get install libpcre++-dev |
| 173 | +sudo make SRCDIR=build CFGDIR=/usr/share/cppcheck HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function" install |
| 174 | +
|
| 175 | +``` |
| 176 | + |
| 177 | +### Implementation Details |
| 178 | + |
| 179 | +*This section is intended for developers curious about the |
| 180 | +implementation details or interested in extending the development |
| 181 | +environment to support additional tools, aliases, etc.* |
| 182 | + |
| 183 | +A lightweight [runtime](.bundle_runtime.sh) (less than 70 lines of |
| 184 | +code) provides a simple API to consistently run the MySensors toolset |
| 185 | +across modalities including, but not limited to, local development and |
| 186 | +continuous integration. The core concept is that each tool |
| 187 | +encapsulates all runtime configuration settings in a simple, |
| 188 | +stand-alone bundle, that can be executed by the bundle runtime. The |
| 189 | +runtime provides an API to execute a tool bundle along with |
| 190 | +convenience functions and environment variables common to all tools. |
| 191 | + |
| 192 | +Each tool bundle is laid out as follows: |
| 193 | + |
| 194 | +``` |
| 195 | +${TOOLSDIR} [e.g. ${GITREPO}/.mystools}] |
| 196 | +.../tool [e.g. cppcheck, astyle] |
| 197 | +....../run.sh [tool run script] |
| 198 | +....../options.sh [command-line options] |
| 199 | +....../config [supporting config files] |
| 200 | +........./some.cfg |
| 201 | +``` |
| 202 | + |
| 203 | +All bundle runtime dependencies are defined withing the namespace / |
| 204 | +context of a git repo so users are free to rename or move repos or |
| 205 | +even use multiple copies of the same repo without encountering |
| 206 | +intra-repo tool settings/configuration conflicts. |
| 207 | + |
| 208 | +During the bootstrap process, certain keys and aliases are defined |
| 209 | +that the runtime leverages. |
| 210 | + |
| 211 | +#####git config keys |
| 212 | + |
| 213 | +* mysensors.toolsdir = .mystools (defined as a repo-relative path - location agnostic) |
| 214 | +* mysensors.bootstrap-cksum = \<git sha of bootstrap-dev.sh used to detect an outdated environment> |
| 215 | + |
| 216 | +#####git aliases |
| 217 | + |
| 218 | +* mystoolspath = *returns the absolute path to the tools dir* |
| 219 | +* \<bundle name> = *(e.g. cppcheck) runs the tool bundle* |
| 220 | + |
| 221 | + NOTE: The \<bundle> aliases are auto-generated by enumerating the bundles located |
| 222 | +in *mystoolspath*. |
| 223 | + |
| 224 | +While the ```git <tool> args``` API is designed to cover many the |
| 225 | +common use cases, tool and hook authors may need to source the |
| 226 | +[runtime](.bundle_runtime.sh) into their script context in order to |
| 227 | +use the convenience functions and environment variables as follows: |
| 228 | + |
| 229 | +```shell-script |
| 230 | +. "$(git config mystoolspath).bundle_runtime.sh" |
| 231 | +``` |
| 232 | + |
| 233 | +The runtime shim will instantiate the following environment variables |
| 234 | +and convenience functions in the script context for use within a tool |
| 235 | +or script. |
| 236 | + |
| 237 | +``` |
| 238 | +TOOLSDIR - absolute path to repo tools dir. Maintained in |
| 239 | + a location-agnostic fashion (e.g. if the user |
| 240 | + moves the repo, changes tools directory within |
| 241 | + repo, etc. |
| 242 | +GITREPO - absolute path to the git repo |
| 243 | +GITDIR - absolute path to the repo .git directory |
| 244 | +
|
| 245 | +runBundle() - Run a given tool / bundle |
| 246 | +is_installed() - true if a given utility is installed |
| 247 | +supported_os() - true if running on a supported os |
| 248 | +log() - log a message in default color to console |
| 249 | +warn() - log a message in yellow to console |
| 250 | +err() - log a message in red and exit with non-zero status |
| 251 | +``` |
| 252 | + |
| 253 | +Many of the aforementioned details can be safely ignored if you want |
| 254 | +to add a new development tool to the toolset. Simply create a bundle |
| 255 | +that follows the layout above, declare the tool command-line options |
| 256 | +in the [bundle]/options.sh and any configuration files in |
| 257 | +[bundle]/config/. While it should not be necessary to alter the |
| 258 | +bundle execution behavior beyond declaring command-line options and |
| 259 | +configuration files, you can override it by modifing the [bundle] |
| 260 | +run.sh script. |
0 commit comments