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/ .vscode/
__pycache__/ __pycache__/
*.pyc *.pyc
/build

View File

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

View File

@ -1,19 +1,24 @@
#!/bin/bash #!/bin/bash
set -e set -e
cd "$(dirname $0)/.."
BOOTLOADER_COMMIT=${1:-HEAD} BOOTLOADER_COMMIT=${1:-HEAD}
FIRMWARE_COMMIT=${2:-HEAD} FIRMWARE_COMMIT=${2:-HEAD}
if [ "$BOOTLOADER_COMMIT" = "EMU" ]; then if [ "$BOOTLOADER_COMMIT" = "EMU" ]; then
export EMULATOR=1 export EMULATOR=1
fi fi
if [ "$EMULATOR" = 1 ]; then if [ "$EMULATOR" = 1 ]; then
IMAGE=trezor-mcu-emulator IMAGE=trezor-mcu-emulator
else else
IMAGE=trezor-mcu-build IMAGE=trezor-mcu-build
fi fi
docker build -t "$IMAGE" --build-arg EMULATOR=$EMULATOR . USER=$(ls -lnd . | awk '{ print $3 }')
docker run -it -v $(pwd):/src:z --user="$(stat -c "%u:%g" .)" "$IMAGE" \ GROUP=$(ls -lnd . | awk '{ print $4 }')
/src/script/fullbuild "$BOOTLOADER_COMMIT" "$FIRMWARE_COMMIT"
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 set -e
cd "$(dirname "$0")/.." cd "$(dirname "$0")/../.."
git submodule update --init --recursive git submodule update --init --recursive

View File

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