Skip to content

Commit

Permalink
Merge pull request #46 from raharper/feat/include-version-in-source-v2
Browse files Browse the repository at this point in the history
Generate git version and include that in source output
  • Loading branch information
hallyn authored Mar 18, 2024
2 parents ee55074 + 3666982 commit 9768251
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 9 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ jobs:
sudo apt-get update --quiet
sudo apt-get install --quiet --assume-yes --no-install-recommends gnu-efi build-essential
sudo apt-get install --quiet --assume-yes --no-install-recommends \
dosfstools mtools ovmf python3-minimal python3-prettytable \
coreutils dosfstools git mtools python3-minimal python3-prettytable \
qemu-system-x86 qemu-utils shim-signed swtpm
# use a specific version of OVMF which does not have uefi-shell
# disabled. See: https://bugs.launchpad.net/ubuntu/+source/edk2/+bug/2040137
sudo apt-get install --quiet --assume-yes --no-install-recommends \
ovmf=0~20191122.bd85bf54-2ubuntu3
- name: Collect Inputs
run: |
mkdir ./test-inputs/
./test/collect-firmwares --no-install ./test-inputs
./test/get-krd ./test-inputs
- name: Build
run: |
make show-version
make build
- name: Upload Build
uses: actions/upload-artifact@v3
Expand All @@ -47,9 +52,11 @@ jobs:
- name: Boot Test
run: |
fails=""
set -x
for m in nvram efi-shell; do
echo "== $m =="
KVM=false ./test/harness run "--boot-mode=$m" \
KVM=false ./test/harness \
run "--boot-mode=$m" \
--inputs=./test-inputs "--results=./test-results/$m" \
--sbat=sbat.csv --stubby=stubby.efi \
--num-threads=$(grep -c processor /proc/cpuinfo) \
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.so
*.efi
test-cmdline
git-version
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ LINUX_TEST_CFLAGS := -DLINUX_TEST $(filter-out -fshort-wchar,$(CFLAGS))
test-%: test-%-lt.o $(TEST_OBJS)
$(CC) $(LINUX_TEST_CFLAGS) -o $@ $^

.PHONY: show-version
show-version:
@echo $(VERSION)

.PHONY: clean
tarball:
@[ -s git-version ] || echo $(VERSION)
./tools/make-tarball

.PHONY: clean
Expand Down
10 changes: 9 additions & 1 deletion make.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
SHELL=/bin/bash

ARCH ?= $(shell uname -m | sed s,i[3456789]86,ia32,)

Expand All @@ -30,10 +31,17 @@ EFILIB ?= ${LIB}
EFI_CRT_OBJS = ${EFILIB}/crt0-efi-${ARCH}.o
EFI_LDS = ${EFILIB}/elf_${ARCH}_efi.lds

GIT_VERSION = $(shell git describe --always --dirty --match="v[0-9]*" 2>/dev/null)
ifeq ($(GIT_VERSION),)
VERSION = $(shell cat git-version 2>/dev/null)
else
VERSION = $(shell echo $(GIT_VERSION) | tee git-version)
endif

CFLAGS = \
-Wall -Werror \
${EFIINCS} -fno-stack-protector -fpic -fshort-wchar \
-DGIT_VERSION=\"$(shell git rev-parse HEAD | cut -c1-12)\"
-DVERSION=\"$(VERSION)\"
ifeq (${ARCH},x86_64)
CFLAGS += -DEFI_FUNCTION_WRAPPER -mno-red-zone
endif
Expand Down
4 changes: 2 additions & 2 deletions stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

/* magic string to find in the binary image */
static const char __attribute__((used)) magic[] =
"#### LoaderInfo: stubby " GIT_VERSION " ####";
"#### LoaderInfo: stubby " VERSION " ####";

BOOLEAN use_shell_cmdline(UINTN len)
{
Expand Down Expand Up @@ -199,7 +199,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table)
/* add StubInfo */
if (efivar_get_raw(&loader_guid,
L"StubInfo", NULL, NULL) != EFI_SUCCESS)
efivar_set(L"StubInfo", L"stubby " GIT_VERSION, FALSE);
efivar_set(L"StubInfo", L"stubby " VERSION, FALSE);

err = linux_exec(image, cmdline, cmdline_len,
(UINTN)loaded_image->ImageBase + addrs[1],
Expand Down
9 changes: 8 additions & 1 deletion test/collect-firmwares
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ set --
[ -d "$outd" ] || mkdir "$outd" ||
fail "failed to make output dir"

ovmf_version=""
# https://bugs.launchpad.net/ubuntu/+source/edk2/+bug/2040137
if [ "$(lsb_release -sc)" = "focal" ]; then
ovmf_version="=0~20191122.bd85bf54-2ubuntu3"
fi

if [ "$install" = "true" ]; then
[ "$(id -u)" = "0" ] ||
fail "must be root for install (try sudo or --no-install)"
apt-get update --quiet || fail "apt-get update failed."
apt-get install --quiet \
--assume-yes --no-install-recommends \
ovmf shim-signed ||
ovmf${ovmfversion} shim-signed ||
fail "failed install deps"
else
echo "skipping install"
Expand Down Expand Up @@ -101,6 +107,7 @@ for line in "$@"; do
*)
cp "$src" "$outd/$target" || fail "failed copy $src -> $target"
echo "copied $src to $target"
md5sum $src $outd/$target
;;
esac
done
Expand Down
6 changes: 6 additions & 0 deletions test/harness
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ class Runner:
self.workdir = os.path.abspath(workdir)
ensure_dir(self.workdir)

self.verbose = cliargs.verbose
self.timeout = cliargs.timeout
self.testinfo = load_test_data(cliargs.testdata)
errors = _check_run_args(cliargs)
Expand Down Expand Up @@ -772,6 +773,11 @@ class Runner:
rlogfp.close()
res = result.split(":")[0]
print("Finished %s [%.2fs]: %s" % (name, time.time() - start, res))
if self.verbose > 0:
print("\n --- TEST [%s] serial.log ---\n" % name)
with open(serial_log) as fh:
print("%s\n" % "".join(fh.readlines()))
print(" --- TEST [%s] end log ---\n" % name)

def _run(self, testdata, run_d, results_d, qemu_log, serial_log, log):
esp = path_join(run_d, "esp.raw")
Expand Down
15 changes: 12 additions & 3 deletions tools/make-tarball
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fi
version=${version#v}
archive_base="stubby-$version"
if [ -z "$output" ]; then
output="$archive_base.tar.gz"
output="$archive_base.tar"
fi

# when building an archiving from HEAD, ensure that there aren't any
Expand All @@ -66,6 +66,15 @@ if [ "$rev" = HEAD ] && ! git diff-index --quiet HEAD --; then
fi
fi

git archive --format=tgz "--output=$output" "--prefix=$archive_base/" "$rev" ||
# generate tar format to enable version insertion
git archive --format=tar "--output=$output" "--prefix=$archive_base/" "$rev" ||
fail "git archive failed"
echo "$output"

# insert the git-version value
echo "$version" > git-version
tar --append -f ${output} --transform "s,^,$archive_base/," git-version ||
fail "appending git-version to archive failed"
gzip ${output} ||
fail "failed to compress archive"

echo "${output}.gz"

0 comments on commit 9768251

Please sign in to comment.