Skip to content

Commit

Permalink
Restructure build system
Browse files Browse the repository at this point in the history
All targets (such as bootloader, bootloader-develop and firmware) are
defined in the CMake build system.

Due to limitations to CMake we need one build directory per compiler:
* build will contain everything compiled for ARM.
* build-build will contain everything compiled for the *build* machine.

When creating the build directory it is now possible to choose "profile"
or "CMAKE_BUILD_TYPE". By default we use "RelWithDebInfo". "Debug" will
create binaries with less optimizations to simplify debugging.

All dependencies are "vendored" into "external" so CMake does not need
to fetch sources over the network. Some of them are git submodules and
must therefore be initialized with `git submodule update --init`.

Address and Undefined behavior santizing is enabled by default when
building for the build machine, which means that all unit tests will use
those features.
  • Loading branch information
Niklas Claesson authored and NickeZ committed Jul 31, 2019
1 parent 98ac6b0 commit c21a313
Show file tree
Hide file tree
Showing 61 changed files with 1,042 additions and 1,025 deletions.
9 changes: 8 additions & 1 deletion .ci/check-pep8
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ set -o pipefail

PYLINT=${PYLINT:-pylint}
BLACK=${BLACK:-black}
MYPY=${MYPY:-mypy}

command -v git >/dev/null 2>&1 || { echo >&2 "git is missing"; exit 1; }
command -v ${PYLINT} >/dev/null 2>&1 || { echo >&2 "${PYLINT} is missing"; exit 1; }
command -v ${BLACK} >/dev/null 2>&1 || { echo >&2 "${BLACK} is missing"; exit 1; }
command -v ${MYPY} >/dev/null 2>&1 || { echo >&2 "${MYPY} is missing"; exit 1; }

# check if stdout is a terminal.
if test -t 1; then
Expand All @@ -37,13 +39,18 @@ fi
# 32 usage error

# grep will exit with 1 if no lines are found
FILES=$(git --no-pager diff --diff-filter=d --name-only origin/master | grep -v "old/" | grep -E ".py\$" || exit 0)
FILES=$(git --no-pager diff --diff-filter=d --name-only origin/master | grep -v -e "old/" -e "generated/" | grep -E ".py\$" || exit 0)
if [ -z "${FILES}" ] ; then
exit 0
fi

${BLACK} --check --fast ${FILES}

# implicit-reexport: `from foo import bar` re-exports (normal Python3 behavior), otherwise mypy expects
# `from foo import bar as bar`.
# namespace-packages: follow imports in subfolders without `__init__.py` (also normal Python3 behavior).
${MYPY} --implicit-reexport --namespace-packages --ignore-missing-imports --strict py

${PYLINT} --persistent=no ${FILES} || {
pylint_status=$?
exitcode=0
Expand Down
14 changes: 7 additions & 7 deletions .ci/ci
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ set -e
./.ci/check-style
make -C py
./.ci/check-pep8
# implicit-reexport: `from foo import bar` re-exports (normal Python3 behavior), otherwise mypy expects
# `from foo import bar as bar`.
# namespace-packages: follow imports in subfolders without `__init__.py` (also normal Python3 behavior).
(cd py && mypy --implicit-reexport --namespace-packages --ignore-missing-imports --strict .)

# Bootloader variants
make -j8 bootloader
Expand All @@ -19,12 +15,16 @@ make -j8 bootloader-production

# Firmware
make -j8 firmware
./scripts/tidy # run tidy on the firmware build

make -j8 factory-setup

# Unit tests
# Build and run Unit tests
make -j8 unit-test
make -j8 run-unit-tests

make -C tools/go/src/atecc608a test

# Build device tests
make -j8 device-test
# make -j8 device-test

# ./scripts/tidy # run tidy on the firmware build
28 changes: 4 additions & 24 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
build
build-vagrant
version.h
/build/
/build-*/
NOTES.md
.vagrant
.DS_Store
.ycm*
*.o
.vagrant/
*.pyc
*.sw*
*.bak
*.bin
!*.c
.mypy_cache/

# gnu global
/src/GPATH
/src/GRTAGS
/src/GTAGS

.vimrc
external/*
!external/cryptoauthlib
!external/ctaes
!external/FatFs
!external/sha3
!external/bignum
!external/base32
!external/CMakeLists.txt
src/generated
py/bitbox02/generated
py/.mypy_cache
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
[submodule "external/FatFs"]
path = external/FatFs
url = https://github.com/digitalbitbox/FatFs.git
[submodule "external/noise-c"]
path = external/noise-c
url = https://github.com/shiftdevices/noise-c.git
[submodule "external/libwally-core"]
path = external/libwally-core
url = https://github.com/shiftdevices/libwally-core.git
4 changes: 2 additions & 2 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ Plug in both the J-Link hardware and the BitBox02 device into USB ports on your

Build the firmware:
```
git clone https://github.com/shiftdevices/firmware_v2 && cd firmware_v2
git clone --recurse-submodules https://github.com/shiftdevices/firmware_v2 && cd firmware_v2
# or via ssh
git clone [email protected]:shiftdevices/firmware_v2.git && cd firmware_v2
git clone --recurse-submodules [email protected]:shiftdevices/firmware_v2.git && cd firmware_v2
make firmware # requires a GNU ARM toolchain for cross-compiling
```

Expand Down
Loading

0 comments on commit c21a313

Please sign in to comment.