From b59c69252a6f8145da2521e3764273d02ad0ca4c Mon Sep 17 00:00:00 2001 From: Juan Leni Date: Mon, 25 May 2020 14:23:57 +0200 Subject: [PATCH] adding missing file --- deps/ledger-zxlib/dockerized_build.mk | 195 ++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 deps/ledger-zxlib/dockerized_build.mk diff --git a/deps/ledger-zxlib/dockerized_build.mk b/deps/ledger-zxlib/dockerized_build.mk new file mode 100644 index 00000000..24bc057c --- /dev/null +++ b/deps/ledger-zxlib/dockerized_build.mk @@ -0,0 +1,195 @@ +#******************************************************************************* +#* (c) 2019 Zondax GmbH +#* +#* Licensed under the Apache License, Version 2.0 (the "License"); +#* you may not use this file except in compliance with the License. +#* You may obtain a copy of the License at +#* +#* http://www.apache.org/licenses/LICENSE-2.0 +#* +#* Unless required by applicable law or agreed to in writing, software +#* distributed under the License is distributed on an "AS IS" BASIS, +#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#* See the License for the specific language governing permissions and +#* limitations under the License. +#******************************************************************************** + +.PHONY: all deps build clean load delete check_python show_info_recovery_mode + +TESTS_ZEMU_DIR?=$(CURDIR)/tests_zemu +TESTS_ZEMU_JS_PACKAGE?= +TESTS_ZEMU_JS_DIR?= + +LEDGER_SRC=$(CURDIR)/app +DOCKER_APP_SRC=/project +DOCKER_APP_BIN=$(DOCKER_APP_SRC)/app/bin/app.elf + +DOCKER_BOLOS_SDK=/project/deps/nanos-secure-sdk +DOCKER_BOLOS_SDKX=/project/deps/nano2-sdk + +SCP_PUBKEY=049bc79d139c70c83a4b19e8922e5ee3e0080bb14a2e8b0752aa42cda90a1463f689b0fa68c1c0246845c2074787b649d0d8a6c0b97d4607065eee3057bdf16b83 +SCP_PRIVKEY=ff701d781f43ce106f72dc26a46b6a83e053b5d07bb3d4ceab79c91ca822a66b + +INTERACTIVE:=$(shell [ -t 0 ] && echo 1) +USERID:=$(shell id -u) +$(info USERID : $(USERID)) +$(info TESTS_ZEMU_DIR : $(TESTS_ZEMU_DIR)) +$(info TESTS_ZEMU_JS_DIR : $(TESTS_ZEMU_JS_DIR)) +$(info TESTS_ZEMU_JS_PACKAGE : $(TESTS_ZEMU_JS_PACKAGE)) + +ifeq ($(USERID),1001) +# TODO: Use podman inside circleci machines? +DOCKER_IMAGE=zondax/builder-bolos-1001:latest +else +DOCKER_IMAGE=zondax/builder-bolos:latest +endif + +ifdef INTERACTIVE +INTERACTIVE_SETTING:="-i" +TTY_SETTING:="-t" +else +INTERACTIVE_SETTING:= +TTY_SETTING:= +endif + +define run_docker + docker run $(TTY_SETTING) $(INTERACTIVE_SETTING) --rm \ + -e SCP_PRIVKEY=$(SCP_PRIVKEY) \ + -e BOLOS_SDK=$(1) \ + -e BOLOS_ENV=/opt/bolos \ + -u $(USERID) \ + -v $(shell pwd):/project \ + $(DOCKER_IMAGE) \ + "$(2)" +endef + +all: build + +.PHONY: check_python +check_python: + @python -c 'import sys; sys.exit(3-sys.version_info.major)' || (echo "The python command does not point to Python 3"; exit 1) + +.PHONY: deps +deps: check_python + @echo "Install dependencies" + $(CURDIR)/deps/ledger-zxlib/scripts/install_deps.sh + +.PHONY: pull +pull: + docker pull $(DOCKER_IMAGE) + +.PHONY: build_rust +build_rust: + $(call run_docker,$(DOCKER_BOLOS_SDK),make -C $(DOCKER_APP_SRC) rust) + +.PHONY: build +build: build_rust + $(info Replacing app icon) + @cp $(LEDGER_SRC)/nanos_icon.gif $(LEDGER_SRC)/glyphs/icon_app.gif + $(info calling make inside docker) + $(call run_docker,$(DOCKER_BOLOS_SDK),make -C $(DOCKER_APP_SRC)) + +.PHONY: buildX +buildX: build_rust + @cp $(LEDGER_SRC)/nanos_icon.gif $(LEDGER_SRC)/glyphs/icon_app.gif + @convert $(LEDGER_SRC)/nanos_icon.gif -crop 14x14+1+1 +repage -negate $(LEDGER_SRC)/nanox_icon.gif + $(call run_docker,$(DOCKER_BOLOS_SDKX),make -C $(DOCKER_APP_SRC)) + +.PHONY: clean +clean: + $(call run_docker,$(DOCKER_BOLOS_SDK),make -C $(DOCKER_APP_SRC) clean) + +.PHONY: shell +shell: + $(call run_docker,$(DOCKER_BOLOS_SDK) -t,bash) + +.PHONY: load +load: + ${LEDGER_SRC}/pkg/zxtool.sh load + +.PHONY: delete +delete: + ${LEDGER_SRC}/pkg/zxtool.sh delete + +.PHONY: show_info_recovery_mode +show_info_recovery_mode: + @echo "This command requires a Ledger Nano S in recovery mode. To go into recovery mode, follow:" + @echo " 1. Settings -> Device -> Reset all and confirm" + @echo " 2. Unplug device, press and hold the right button, plug-in again" + @echo " 3. Navigate to the main menu" + @echo "If everything was correct, no PIN needs to be entered." + +# This target will initialize the device with the integration testing mnemonic +.PHONY: dev_init +dev_init: show_info_recovery_mode + @echo "Initializing device with test mnemonic! WARNING TAKES 2 MINUTES AND REQUIRES RECOVERY MODE" + @python -m ledgerblue.hostOnboard --apdu --id 0 --prefix "" --passphrase "" --pin 5555 --words "equip will roof matter pink blind book anxiety banner elbow sun young" + +# This target will initialize the device with the secondary integration testing mnemonic (Bob) +.PHONY: dev_init_secondary +dev_init_secondary: check_python show_info_recovery_mode + @echo "Initializing device with secondary test mnemonic! WARNING TAKES 2 MINUTES AND REQUIRES RECOVERY MODE" + @python -m ledgerblue.hostOnboard --apdu --id 0 --prefix "" --passphrase "" --pin 5555 --words "elite vote proof agree february step sibling sand grocery axis false cup" + +# This target will setup a custom developer certificate +.PHONY: dev_ca +dev_ca: check_python + @python -m ledgerblue.setupCustomCA --targetId 0x31100004 --public $(SCP_PUBKEY) --name zondax + +.PHONY: dev_ca_delete +dev_ca_delete: check_python + @python -m ledgerblue.resetCustomCA --targetId 0x31100004 + +# This target will setup a custom developer certificate +.PHONY: dev_ca2 +dev_ca2: check_python + @python -m ledgerblue.setupCustomCA --targetId 0x33000004 --public $(SCP_PUBKEY) --name zondax + +.PHONY: dev_ca_delete2 +dev_ca_delete2: check_python + @python -m ledgerblue.resetCustomCA --targetId 0x33000004 + +########################## ZEMU Section ############################### + +.PHONY: zemu_install_js_link +ifeq ($(TESTS_ZEMU_JS_DIR),) +zemu_install_js_link: + @echo "No local package defined" +else +zemu_install_js_link: + # First unlink everything + cd $(TESTS_ZEMU_JS_DIR) && yarn unlink || true + cd $(TESTS_ZEMU_DIR) && yarn unlink $(TESTS_ZEMU_JS_PACKAGE) || true + # Now build and link + cd $(TESTS_ZEMU_JS_DIR) && yarn install && yarn build || true + cd $(TESTS_ZEMU_JS_DIR) && yarn link || true + cd $(TESTS_ZEMU_DIR) && yarn link $(TESTS_ZEMU_JS_PACKAGE) || true +endif + +.PHONY: zemu_install +zemu_install: zemu_install_js_link + # and now install everything + cd $(TESTS_ZEMU_DIR) && yarn install + +.PHONY: zemu +zemu: + cd $(TESTS_ZEMU_DIR)/tools && node debug.mjs + +.PHONY: zemu_debug +zemu_debug: + cd $(TESTS_ZEMU_DIR)/tools && node debug.mjs debug + +########################## TEST Section ############################### + +.PHONY: zemu_test +zemu_test: + cd $(TESTS_ZEMU_DIR) && yarn test + +.PHONY: rust_test +rust_test: + cd app/rust && cargo test + +.PHONY: cpp_test +cpp_test: + mkdir -p build && cd build && cmake -DDISABLE_DOCKER_BUILDS=ON -DCMAKE_BUILD_TYPE=Debug .. && make + cd build && GTEST_COLOR=1 ASAN_OPTIONS=detect_leaks=0 ctest -VV