Fun with git
cover Fun with git
I ended up looking at the use of git in the build system. There is some inconsistency in use/behavior and I really dislike how certain pieces of it have evolved. Most of what I'm sending is RFC since I've got too many questions, but the first two are appropriate right now.
I find it unsurprising the script predates Xen's conversion to git. Likely the script made it rather more obvious git was winning, then it finally came time to officially convert Xen to using git.
Of the four uses of the git-checkout.sh script 1 gives a full path and 3 give only the subdirectory. I'm unsure which is appropriate, but inconsistency is a Bad Thing(tm).
What is with the naming of the subproject repository directories? Why the "-dir" for "qemu-xen-dir", "ovmf-dir" and "seabios-dir"? Whereas for mini-os it is "extras/mini-os". I imagine there was some good reason at some point, but now it simply seems odd.
Then there is the issue of all the duplicated project subdirectory variants. If the git-checkout.sh script is used it creates <repo>-remote, than a symbolic link <repo> -> <repo>-remote. Then for most (all?) of these the directory <repo>-build is created where the actual build is done.
Then there are the problems with factors related to the existence of the script and the way it works.
One problem with the script is is breaks cleaning the repository. "Hmm, git status --ignored still shows directories, okay let merm -rf tools/firmware/*-dir tools/qemu-xen-dir extras/mini-os" Then
the next build you end up redownloading those repositories from scratch. Perhaps the Xen Project's git server can handle the load, but it certainly adds some.
Then there is a major slowdown in the build process. Clone the git repository, then move to your fast build machine with lots of processors. Suddenly you're waiting on your Internet link. Then it gets worse if that is the moment when the git server is down. Just to make it worse this also functions as a tracker for finding people building Xen.
Yet another issue is, is it still possible to build Xen 4.0? Nominally most/all of the repository histories reach back that far, but you'll have no idea which versions were in use. The combination of outside repository versions needed for a given Xen version build might be quite hard to figure out in the future.
I'm including some patches I created while looking into this situation. I think the first is worthwhile no matter what choices are made. The rest are simply resolving issues I found. The last is a proposed adjustment to the script. The script adjustment is unfinished, it is somehow breaking Qemu's build process. It also only successfully addresses the issue of needing to redownload full repositories.
A better option might be using git subtree. This would address all my concerns in regards to the handling of external project repositories. Does seem a largish step though.
Elliott Mitchell (5):
make: add use of $(realpath ) in top and main Rules.mk files Config.mk: record hash of SeaBIOS tag scripts/git-checkout.sh: add standard scripting safety steps tools/build: use full path when checking out git repositories scripts/git-checkout.sh: store repositories with Xen, use worktrees
Config.mk | 3 ++- Makefile | 12 +++++++---- scripts/git-checkout.sh | 44 ++++++++++++++++++++++++----------------- tools/Makefile | 12 ++++------- tools/Rules.mk | 2 ++ tools/firmware/Makefile | 14 ++++++------- 6 files changed, 48 insertions(+), 39 deletions(-)
Signature · 1 line
2.47.3
PATCH 1/5 make: add use of $(realpath ) in top and main Rules.mk files
Date: Sat, 17 Oct 2026 12:25:36 -0700
Without this "/.." tend to accumulate in $(XEN_ROOT) and eventually things start breaking. Address this before something subtlely breaks.
--- Makefile | 2 +- tools/Rules.mk | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
Makefile +1 -1
@@ -15,7 +15,7 @@ TARGS_BUILD=$(patsubst %, build-%, $(SUBSYSTEMS)) TARGS_CLEAN=$(patsubst %, clean-%, $(SUBSYSTEMS)) TARGS_DISTCLEAN=$(patsubst %, distclean-%, $(SUBSYSTEMS)) -export XEN_ROOT=$(CURDIR) +export XEN_ROOT:=$(realpath $(CURDIR)) include Config.mk .PHONY: mini-os-dir
tools/Rules.mk +2 -0
@@ -1,5 +1,7 @@ # -*- mode: Makefile; -*- +override XEN_ROOT:=$(realpath $(XEN_ROOT)) + # `all' is the default target all:
Signature · 1 line
2.47.3
Re: [PATCH 1/5] make: add use of $(realpath ) in top and main Rules.mk files
Quoted 4 lines · Elliott Mitchell
Date: Sat, 17 Oct 2026 12:25:36 -0700
Without this "/.." tend to accumulate in $(XEN_ROOT) and eventually things start breaking.
"breaking" as in what exactly happening?
Jan
Quoted 3 lines
Address this before something subtlely breaks.
Signed-off-by Elliott Mitchell <[email protected]>
Re: [PATCH 1/5] make: add use of $(realpath ) in top and main Rules.mk files
Quoted 7 lines · Jan Beulich
Quoted 4 lines · Elliott Mitchell
Date: Sat, 17 Oct 2026 12:25:36 -0700
Without this "/.." tend to accumulate in $(XEN_ROOT) and eventually things start breaking.
"breaking" as in what exactly happening?
This is a scar from a project I was involved in several years back. One issue is dependencies are computed/compared as strings. In particular if multiple parent directory references are made one part of a project might end up depending on:
foo/../bar/../baz
While another might end up depending on:
bar/../foo/../bar
If building is done in parallel you can end up with two processes entering the same directory at the same time and colliding.
I imagine other problems/manifestations can occur. I have not observed any of these occuring with Xen's build, but this is something I tend to preemptively address. Strings including "/../" do occur in Xen's build so there is some concern issues could occur in the future.
Certainly not urgent, but something which could become an issue.
Signature · 4 lines
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/) \BS ( | [email protected] PGP 87145445 | ) / \_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/ 8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
PATCH 2/5 Config.mk: record hash of SeaBIOS tag
In reply to Elliott MitchellDate: Sun, 18 Oct 2026 14:12:43 -0700
Recording the tag as a comment, but directing git at the hash allows bypassing downloading tags (git does not selectively download tags). While remote branches get prefixed with the remote name. The result is identical, the tag is simply a reference to the hash.
--- Config.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Config.mk +2 -1
@@ -220,7 +220,8 @@ MINIOS_UPSTREAM_URL ?= https://xenbits.xen.org/git-http/mini-os.git MINIOS_UPSTREAM_REVISION ?= 26ceb2daf95dd9e7fed9c83d36be3aaf1a0fa8a1 SEABIOS_UPSTREAM_URL ?= https://xenbits.xen.org/git-http/seabios.git -SEABIOS_UPSTREAM_REVISION ?= rel-1.17.0 +# rel-1.17.0 +SEABIOS_UPSTREAM_REVISION ?= b52ca86e094d19b58e2304417787e96b940e39c6 ETHERBOOT_NICS ?= rtl8139 8086100e
Signature · 1 line
2.47.3
Re: [PATCH 2/5] Config.mk: record hash of SeaBIOS tag
Quoted 6 lines · Elliott Mitchell
Date: Sun, 18 Oct 2026 14:12:43 -0700
Recording the tag as a comment, but directing git at the hash allows bypassing downloading tags (git does not selectively download tags). While remote branches get prefixed with the remote name. The result is identical, the tag is simply a reference to the hash.
I don't quite get what the win is. The middle sentence also feels, to me, unrelated to anything else here. The fact that ...
Config.mk MINIOS_UPSTREAM_URL ?= https://xenbits.xen.org/git-http/mini-os.git · line 220
Quoted 4 lines
Config.mk +0
-0@@ -220,7 +220,8 @@ MINIOS_UPSTREAM_URL ?= https://xenbits.xen.org/git-http/mini-os.git MINIOS_UPSTREAM_REVISION ?= 26ceb2daf95dd9e7fed9c83d36be3aaf1a0fa8a1
... we use a hash here, for example, doesn't warrant ...
Config.mk MINIOS_UPSTREAM_URL ?= https://xenbits.xen.org/git-http/mini-os.git · line 224
Quoted 4 lines
Config.mk +2
-1SEABIOS_UPSTREAM_URL ?= https://xenbits.xen.org/git-http/seabios.git -SEABIOS_UPSTREAM_REVISION ?= rel-1.17.0 +# rel-1.17.0 +SEABIOS_UPSTREAM_REVISION ?= b52ca86e094d19b58e2304417787e96b940e39c6
... the use here. IOW if this is to be pursued, more explanation is going to be necessary.
Jan
Re: [PATCH 2/5] Config.mk: record hash of SeaBIOS tag
Quoted 18 lines · Jan Beulich
Quoted 6 lines · Elliott Mitchell
Date: Sun, 18 Oct 2026 14:12:43 -0700
Recording the tag as a comment, but directing git at the hash allows bypassing downloading tags (git does not selectively download tags). While remote branches get prefixed with the remote name. The result is identical, the tag is simply a reference to the hash.
I don't quite get what the win is. The middle sentence also feels, to me, unrelated to anything else here. The fact that ...
Config.mk MINIOS_UPSTREAM_URL ?= https://xenbits.xen.org/git-http/mini-os.git · line 220
Quoted 4 lines
Config.mk +0
-0@@ -220,7 +220,8 @@ MINIOS_UPSTREAM_URL ?= https://xenbits.xen.org/git-http/mini-os.git MINIOS_UPSTREAM_REVISION ?= 26ceb2daf95dd9e7fed9c83d36be3aaf1a0fa8a1... we use a hash here, for example, doesn't warrant ...
Quoted 7 lines
Config.mk MINIOS_UPSTREAM_URL ?= https://xenbits.xen.org/git-http/mini-os.git · line 224
Quoted 4 lines
Config.mk +2
-1SEABIOS_UPSTREAM_URL ?= https://xenbits.xen.org/git-http/seabios.git -SEABIOS_UPSTREAM_REVISION ?= rel-1.17.0 +# rel-1.17.0 +SEABIOS_UPSTREAM_REVISION ?= b52ca86e094d19b58e2304417787e96b940e39c6... the use here. IOW if this is to be pursued, more explanation is going to be necessary.
Issue is git's handling of tags isn't very good. In particular it really wants to either get all tags or no tags. I've found it quite difficult (read: I've yet to suceed) trying to get it retrieve a single tag. Instead what it does is resolve the tag to the commit hash (by asking the server) and then only saving the commit to persistent storage.
If you have git save all tags, it will download nearly everything. Not just the branch/tag you need, but any branch which has a tag. This means somewhere 2-10x the storage, 2-10x the download bandwidth, 2-10x the time spent waiting for the download.
The situation with Qemu is far more concerning. Since $(QEMU_UPSTREAM_REVISION) points at a branch on Xen's git server, every time that branch moves you get a different build. Since different versions will have different bugs/features unless there is a public record of where the branch was over time, older builds become impossible to reproduce.
The favored solution to these problems would be to switch to using git subtree. This though would be a pretty major move. I was hoping this series would get a discussion started about option.
Signature · 4 lines
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/) \BS ( | [email protected] PGP 87145445 | ) / \_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/ 8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
RFC PATCH 3/5 scripts/git-checkout.sh: add standard scripting safety steps
In reply to Elliott MitchellDate: Fri, 16 Oct 2026 19:11:11 -0700
Add doublequotes to all variable references. This ensures building doesn't fail if the full build directory has spaces in it. Also move the set -e to the front of the script.
Add a default value for $GIT.
Rename $TREE to $REPO. These are generally called "repositories", the checked out directory is a tree.
--- scripts/git-checkout.sh | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
scripts/git-checkout.sh +18 -16
@@ -1,28 +1,30 @@ #!/bin/sh +set -e + if test $# -lt 3; then - echo "Usage: $0 <tree> <committish> <dir>" + echo "Usage: $0 <repo> <committish> <dir>" exit 1 fi -TREE=$1 -COMMITTISH=$2 -DIR=$3 +GIT="${GIT:-git}" -set -e +REPO="$1" +COMMITTISH="$2" +DIR="$3" -if test \! -d $DIR-remote; then - rm -rf $DIR-remote $DIR-remote.tmp - mkdir -p $DIR-remote.tmp; rmdir $DIR-remote.tmp - $GIT clone $TREE $DIR-remote.tmp +if test \! -d "$DIR-remote"; then + rm -rf "$DIR-remote" "$DIR-remote.tmp" + mkdir -p "$DIR-remote.tmp"; rmdir "$DIR-remote.tmp" + "$GIT" clone "$REPO" "$DIR-remote.tmp" if test "$COMMITTISH" ; then - cd $DIR-remote.tmp - $GIT fetch origin "$COMMITTISH" - $GIT branch -D dummy >/dev/null 2>&1 ||: - $GIT checkout -b dummy FETCH_HEAD + cd "$DIR-remote.tmp" + "$GIT" fetch origin "$COMMITTISH" + "$GIT" branch -D dummy >/dev/null 2>&1 ||: + "$GIT" checkout -b dummy FETCH_HEAD cd - fi - mv $DIR-remote.tmp $DIR-remote + mv "$DIR-remote.tmp" "$DIR-remote" fi -rm -f $DIR -ln -sf $(basename $DIR-remote) $DIR +rm -f "$DIR" +ln -sf $(basename "$DIR-remote") "$DIR"
Signature · 1 line
2.47.3
RFC PATCH 4/5 tools/build: use full path when checking out git repositories
In reply to Elliott MitchellDate: Fri, 16 Oct 2026 18:23:28 -0700
This makes the invocations of the git-checkout script consistent. This makes it easier to understand what is actually occurring.
--- tools/Makefile | 2 +- tools/firmware/Makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
tools/Makefile +1 -1
@@ -135,7 +135,7 @@ qemu-xen-dir-find: mkdir -p qemu-xen-dir; \ else \ export GIT=$(GIT); \ - $(XEN_ROOT)/scripts/git-checkout.sh $(QEMU_UPSTREAM_LOC) $(QEMU_UPSTREAM_REVISION) qemu-xen-dir ; \ + $(XEN_ROOT)/scripts/git-checkout.sh $(QEMU_UPSTREAM_LOC) $(QEMU_UPSTREAM_REVISION) $(XEN_ROOT)/tools/qemu-xen-dir ; \ fi .PHONY: qemu-xen-dir-force-update
tools/firmware/Makefile +2 -2
@@ -20,11 +20,11 @@ SEABIOSLD ?= $(LD) SEABIOS_EXTRAVERSION ?= "-Xen" ovmf-dir: - GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh $(OVMF_UPSTREAM_URL) $(OVMF_UPSTREAM_REVISION) ovmf-dir + GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh $(OVMF_UPSTREAM_URL) $(OVMF_UPSTREAM_REVISION) $(XEN_ROOT)/tools/firmware/ovmf-dir cp ovmf-makefile ovmf-dir/Makefile; seabios-dir: - GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh $(SEABIOS_UPSTREAM_URL) $(SEABIOS_UPSTREAM_REVISION) seabios-dir + GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh $(SEABIOS_UPSTREAM_URL) $(SEABIOS_UPSTREAM_REVISION) $(XEN_ROOT)/tools/firmware/seabios-dir cp seabios-config seabios-dir/.config; $(MAKE) -C seabios-dir olddefconfig CC=$(SEABIOSCC) LD=$(SEABIOSLD) rm -f seabios-dir/.version
Signature · 1 line
2.47.3
RFC PATCH 5/5 scripts/git-checkout.sh: store repositories with Xen, use worktrees
In reply to Elliott MitchellDate: Fri, 16 Oct 2026 19:42:44 -0700
The problem with checking out repositories in subdirectories is they may get removed by git clean. Whereas storing them with the Xen repository renders them immune to this. Then git worktrees can be used for checking out the specified trees.
Remote the addition of "-remote" to the checkout directory names. This is very confusing and a great source for bugs.
---
WARNING: As of this writing this is known to break qemu-xen building. I've been trying to figure this out, but so far I'm puzzled.
--- Makefile | 10 +++++++--- scripts/git-checkout.sh | 42 +++++++++++++++++++++++------------------ tools/Makefile | 12 ++++-------- tools/firmware/Makefile | 14 ++++++-------- 4 files changed, 41 insertions(+), 37 deletions(-)
Makefile +7 -3
@@ -22,6 +22,7 @@ include Config.mk mini-os-dir: if [ ! -d $(XEN_ROOT)/extras/mini-os ]; then \ GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh \ + mini-os \ $(MINIOS_UPSTREAM_URL) \ $(MINIOS_UPSTREAM_REVISION) \ $(XEN_ROOT)/extras/mini-os ; \
@@ -31,9 +32,12 @@ mini-os-dir: mini-os-dir-force-update: mini-os-dir set -ex; \ if [ "$(MINIOS_UPSTREAM_REVISION)" ]; then \ - cd extras/mini-os-remote; \ - $(GIT) fetch origin; \ - $(GIT) reset --hard $(MINIOS_UPSTREAM_REVISION); \ + rm -rf extras/mini-os; \ + GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh \ + mini-os \ + $(MINIOS_UPSTREAM_URL) \ + $(MINIOS_UPSTREAM_REVISION) \ + $(XEN_ROOT)/extras/mini-os ; \ fi export XEN_TARGET_ARCH
scripts/git-checkout.sh +24 -18
52 lines not on this page · raw message
tools/Makefile +4 -8
@@ -111,9 +111,7 @@ endif # # Directories for external trees: # ${target}-dir -# Used for local builds. Usually a link to ${target}-dir-remote -# ${target}-dir-remote -# Where remote repositories are cloned +# Used for local builds. # ${target} # Where a copy of the source files are put when building a source # tarball for release
@@ -134,17 +132,15 @@ qemu-xen-dir-find: if test -d $(QEMU_UPSTREAM_LOC) ; then \ mkdir -p qemu-xen-dir; \ else \ - export GIT=$(GIT); \ - $(XEN_ROOT)/scripts/git-checkout.sh $(QEMU_UPSTREAM_LOC) $(QEMU_UPSTREAM_REVISION) $(XEN_ROOT)/tools/qemu-xen-dir ; \ + GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh qemu-xen $(QEMU_UPSTREAM_LOC) $(QEMU_UPSTREAM_REVISION) $(XEN_ROOT)/tools/qemu-xen-dir ; \ fi .PHONY: qemu-xen-dir-force-update qemu-xen-dir-force-update: qemu-xen-dir-find set -ex; \ if [ "$(QEMU_UPSTREAM_REVISION)" ]; then \ - cd qemu-xen-dir-remote; \ - $(GIT) fetch origin; \ - $(GIT) reset --hard $(QEMU_UPSTREAM_REVISION); \ + rm -rf qemu-xen-dir; \ + GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh qemu-xen $(QEMU_UPSTREAM_LOC) $(QEMU_UPSTREAM_REVISION) $(XEN_ROOT)/tools/qemu-xen-dir ; \ fi ifeq ($(debug),y)
tools/firmware/Makefile +6 -8
@@ -20,11 +20,11 @@ SEABIOSLD ?= $(LD) SEABIOS_EXTRAVERSION ?= "-Xen" ovmf-dir: - GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh $(OVMF_UPSTREAM_URL) $(OVMF_UPSTREAM_REVISION) $(XEN_ROOT)/tools/firmware/ovmf-dir + GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh ovmf $(OVMF_UPSTREAM_URL) $(OVMF_UPSTREAM_REVISION) $(XEN_ROOT)/tools/firmware/ovmf-dir cp ovmf-makefile ovmf-dir/Makefile; seabios-dir: - GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh $(SEABIOS_UPSTREAM_URL) $(SEABIOS_UPSTREAM_REVISION) $(XEN_ROOT)/tools/firmware/seabios-dir + GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh seabios $(SEABIOS_UPSTREAM_URL) $(SEABIOS_UPSTREAM_REVISION) $(XEN_ROOT)/tools/firmware/seabios-dir cp seabios-config seabios-dir/.config; $(MAKE) -C seabios-dir olddefconfig CC=$(SEABIOSCC) LD=$(SEABIOSLD) rm -f seabios-dir/.version
@@ -95,9 +95,8 @@ subdir-distclean-seabios-dir: .phony ovmf-dir-force-update: ovmf-dir set -ex; \ if [ "$(OVMF_UPSTREAM_REVISION)" ]; then \ - cd ovmf-dir-remote; \ - $(GIT) fetch origin; \ - $(GIT) reset --hard $(OVMF_UPSTREAM_REVISION); \ + rm -rf ovmf-dir-remote; \ + GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh ovmf $(OVMF_UPSTREAM_URL) $(OVMF_UPSTREAM_REVISION) $(XEN_ROOT)/tools/firmware/ovmf-dir ; \ fi subdir-clean-ovmf-dir:
@@ -109,9 +108,8 @@ subdir-clean-ovmf-dir: seabios-dir-force-update: seabios-dir set -ex; \ if [ "$(SEABIOS_UPSTREAM_REVISION)" ]; then \ - cd seabios-dir-remote; \ - $(GIT) fetch origin; \ - $(GIT) reset --hard $(SEABIOS_UPSTREAM_REVISION); \ + rm -rf seabios-dir; \ + GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh seabios $(SEABIOS_UPSTREAM_URL) $(SEABIOS_UPSTREAM_REVISION) $(XEN_ROOT)/tools/firmware/seabios-dir ; \ fi subdir-clean-seabios-dir:
Signature · 1 line
2.47.3