Skip to content

Commit

Permalink
Makefile: don't hard-code test binary location
Browse files Browse the repository at this point in the history
If a runner is set in cargo's config it will be executed with the
binary as the first argument. We use this to copy the test binary to
static location.

Signed-off-by: Tom Dohrmann <erbse.13@gmx.de>
  • Loading branch information
Freax13 committed Oct 9, 2023
1 parent 5719bd5 commit ace2c55
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@ FEATURES ?= "default"
CARGO_ARGS = --features ${FEATURES}

ifdef RELEASE
TARGET_PATH="release"
TARGET_PATH=release
CARGO_ARGS += --release
else
TARGET_PATH="debug"
TARGET_PATH=debug
endif

STAGE2_ELF = "target/x86_64-unknown-none/${TARGET_PATH}/stage2"
ifdef TEST
KERNEL_ELF = "target/x86_64-unknown-none/${TARGET_PATH}/deps/svsm-0651abaef6a489bb"
KERNEL_ELF = target/x86_64-unknown-none/${TARGET_PATH}/svsm-test
CARGO_ENV_KERNEL = LINK_TEST=1
CARGO_TOOLCHAIN_KERNEL = +nightly
CARGO_ARGS_KERNEL = --tests
CARGO_VERB_KERNEL = test
# Define a test runner that simply copies the binary to a static location for
# further processing. We do this because there's no good way to statically know
# the test binary location.
CARGO_ARGS_KERNEL += --config 'target.x86_64-unknown-none.runner=["sh", "-c", "cp $$0 ${KERNEL_ELF}"]'
else
KERNEL_ELF = "target/x86_64-unknown-none/${TARGET_PATH}/svsm"
CARGO_ENV_KERNEL =
CARGO_TOOLCHAIN_KERNEL =
CARGO_VERB_KERNEL = build
CARGO_ARGS_KERNEL = --bin svsm
endif
FS_FILE ?= none
Expand All @@ -44,7 +50,7 @@ stage1/stage2.bin:
objcopy -O binary ${STAGE2_ELF} $@

stage1/kernel.elf:
${CARGO_ENV_KERNEL} cargo ${CARGO_TOOLCHAIN_KERNEL} build ${CARGO_ARGS} ${CARGO_ARGS_KERNEL}
${CARGO_ENV_KERNEL} cargo ${CARGO_TOOLCHAIN_KERNEL} ${CARGO_VERB_KERNEL} ${CARGO_ARGS} ${CARGO_ARGS_KERNEL}
objcopy -O elf64-x86-64 --strip-unneeded ${KERNEL_ELF} $@

stage1/svsm-fs.bin:
Expand Down

0 comments on commit ace2c55

Please sign in to comment.