1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

build: make build scripts work from monorepo root

incidentally fixes #9 and the dreaded non-bug #8
This commit is contained in:
matejcik 2019-04-18 14:52:24 +02:00
parent ec38a8ce3f
commit 9f8ebcf183
5 changed files with 71 additions and 45 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@
.vscode/
__pycache__/
*.pyc
/build

View File

@ -1,6 +1,8 @@
#!/bin/sh
set -e
cd "$(dirname $0)/.."
if [ "$1" = "--gcc_source" ]; then
TOOLCHAIN_FLAVOR=src
shift
@ -9,23 +11,30 @@ else
fi
IMAGE=trezor-core-build.$TOOLCHAIN_FLAVOR
TAG=${1:-master}
if [ -z "$1" ]; then
TAG=master
else
TAG=core/${1}
fi
REPOSITORY=${2:-trezor}
PRODUCTION=${PRODUCTION:-0}
if [ "$REPOSITORY" = "local" ]; then
REPOSITORY=file:///local/
else
REPOSITORY=https://github.com/$REPOSITORY/trezor-core.git
REPOSITORY=https://github.com/$REPOSITORY/trezor-firmware.git
fi
docker build -t $IMAGE --build-arg TOOLCHAIN_FLAVOR=$TOOLCHAIN_FLAVOR .
docker build -t $IMAGE --build-arg TOOLCHAIN_FLAVOR=$TOOLCHAIN_FLAVOR core
mkdir -p $(pwd)/build-docker
docker run -t -v $(pwd):/local -v $(pwd)/build-docker:/build:z --user="$(stat -c "%u:%g" .)" $IMAGE /bin/sh -c "\
USER=$(ls -lnd . | awk '{ print $3 }')
GROUP=$(ls -lnd . | awk '{ print $4 }')
mkdir -p $(pwd)/build/core
docker run -t -v $(pwd):/local -v $(pwd)/build/core:/build:z --user="$USER:$GROUP" $IMAGE /bin/sh -c "\
cd /tmp && \
git clone $REPOSITORY trezor-core && \
cd trezor-core && \
git clone $REPOSITORY trezor-firmware && \
cd trezor-firmware/core && \
ln -s /build build &&
git checkout $TAG && \
git submodule update --init --recursive && \

View File

@ -1,6 +1,8 @@
#!/bin/bash
set -e
cd "$(dirname $0)/.."
BOOTLOADER_COMMIT=${1:-HEAD}
FIRMWARE_COMMIT=${2:-HEAD}
@ -14,6 +16,9 @@ else
IMAGE=trezor-mcu-build
fi
docker build -t "$IMAGE" --build-arg EMULATOR=$EMULATOR .
docker run -it -v $(pwd):/src:z --user="$(stat -c "%u:%g" .)" "$IMAGE" \
/src/script/fullbuild "$BOOTLOADER_COMMIT" "$FIRMWARE_COMMIT"
USER=$(ls -lnd . | awk '{ print $3 }')
GROUP=$(ls -lnd . | awk '{ print $4 }')
docker build -t "$IMAGE" --build-arg EMULATOR=$EMULATOR legacy
docker run -it -v $(pwd):/src:z --user="$USER:$GROUP" "$IMAGE" \
/src/legacy/script/fullbuild "$BOOTLOADER_COMMIT" "$FIRMWARE_COMMIT"

View File

@ -5,6 +5,6 @@
set -e
cd "$(dirname "$0")/.."
cd "$(dirname "$0")/../.."
git submodule update --init --recursive

View File

@ -9,22 +9,24 @@ export LANG=C.UTF-8
set -eu
cd "$(dirname "$0")/.."
cd "$(dirname "$0")/../.."
readonly MCU_ROOT=legacy
readonly ARTIFACT_EXTENSIONS=(bin elf)
readonly BUILD_DIR="$(readlink -f build)"
readonly BOOTLOADER_DIR="$BUILD_DIR/bootloader"
readonly BOOTLOADER_FILENAME="bootloader/bootloader.bin"
readonly BOOTLOADER_DIR="$BUILD_DIR/legacy/bootloader"
readonly BOOTLOADER_FILENAME="$MCU_ROOT/bootloader/bootloader.bin"
readonly BOOTLOADER_PATH="$BOOTLOADER_DIR/$BOOTLOADER_FILENAME"
readonly FIRMWARE_DIR="$BUILD_DIR/firmware"
readonly FIRMWARE_FILENAME="firmware/trezor.bin"
readonly FIRMWARE_DIR="$BUILD_DIR/legacy/firmware"
readonly FIRMWARE_FILENAME="$MCU_ROOT/firmware/trezor.bin"
readonly FIRMWARE_PATH="$FIRMWARE_DIR/$FIRMWARE_FILENAME"
readonly EMULATOR_DIR="$FIRMWARE_DIR"
readonly EMULATOR_FILENAME="firmware/trezor-emulator.elf"
readonly EMULATOR_PATH="$EMULATOR_DIR/firmware/trezor.elf"
readonly EMULATOR_FILENAME="$MCU_ROOT/firmware/trezor-emulator.elf"
readonly EMULATOR_PATH="$EMULATOR_DIR/$MCU_ROOT/firmware/trezor.elf"
worktree_setup() {
local path="$1"
@ -36,14 +38,18 @@ worktree_setup() {
# Use `git rev-parse` so that we can use any reference from the working repository.
git -C "$path" checkout "$(git rev-parse "$commit")"
( cd "$path" && script/setup )
( cd "$path/$MCU_ROOT" && script/setup )
}
worktree_build() {
local path="$1"
if [ -e "$path/Pipfile" ]; then
pushd $path
if [ ! -e "$path/$MCU_ROOT/Pipfile" ]; then
echo "Can't handle pre-monorepo tags properly. You will have to check out manually"
exit 1
fi
pushd $path/$MCU_ROOT
if ! pipenv install; then
# older tags can fail because they don't have protobuf in Pipfile
pipenv run pip install "protobuf==3.4.0"
@ -51,12 +57,6 @@ worktree_build() {
fi
pipenv run script/cibuild
popd
else
# even older tags don't have Pipfile!
# use current one
pipenv install
( cd "$path" && pipenv run script/cibuild )
fi
}
worktree_copy() {
@ -64,18 +64,23 @@ worktree_copy() {
local filename="$2"
local pattern="$3"
local describe="$(git -C "$path" describe --tags --match "$pattern")"
local describe="$(git -C "$path" describe --tags --match "legacy/$pattern")"
describe="${describe##legacy/}"
local src="$path/$filename"
local basename="$(basename "$filename")"
local dest="$BUILD_DIR/${basename%.*}-$describe.${basename##*.}"
if [ "$EMULATOR" = 1 ]; then
install -Dm0644 "${src%.*}.elf" "${dest%.*}.elf"
else
for extension in "${ARTIFACT_EXTENSIONS[@]}"; do
install -Dm0644 \
"${src%.*}.$extension" \
"${dest%.*}.$extension"
done
fi
printf "%s" "$dest"
}
@ -84,7 +89,13 @@ main() {
local bootloader_commit="$1"
local firmware_commit="$2"
script/bootstrap
if [ "$bootloader_commit" != "HEAD" ]; then
bootloader_commit="legacy/$bootloader_commit"
fi
if [ "$firmware_commit" != "HEAD" ]; then
firmware_commit="legacy/$firmware_commit"
fi
worktree_setup "$FIRMWARE_DIR" "$firmware_commit"
if [ "$EMULATOR" != 1 ]; then
@ -116,13 +127,13 @@ main() {
"$BOOTLOADER_FILENAME" \
"bl*")"
printf "\n\n"; $PYTHON script/fingerprint \
printf "\n\n"; $PYTHON $MCU_ROOT/script/fingerprint \
"$bootloader_path" \
--max-size 32768 \
--double
fi
printf "\n\n"; $PYTHON script/fingerprint \
printf "\n\n"; $PYTHON $MCU_ROOT/script/fingerprint \
"$firmware_path" \
--offset 256 \
--max-size 983296 # 256 + 64*1024 + 3*128*1024 + 4*128*1024