git.sh: allow finer control of git submodules

in each submodule configuration directory, a module.cfg
file can now be provided. in it, the user can specify
two repository links (main and backup) and a revision, like
so:

subrepo="repo link goes here"
subrepo_bkup="backup repo link goes here"
subrev="git revision id goes here"

additionally:

in the *main* project directory for the submodules,
a module.list file can be provided. example entries:

3rdparty/vboot
3rdparty/libgfxinit

if the module.list file is provided, only those submodules
will be downloaded. this can be combined with the module.cfg
files, if you wish, but it's optional. you can mix and match.

example locations:

multi-tree project:
config/submodule/coreboot/default/module.list
config/submodule/coreboot/default/vboot/module.cfg
single-tree project:
config/submodule/flashprog/module.list
config/submodule/flashprog/foo/module.cfg

*no* configuration files have been provided, in this commit,
which means that the current behaviour is maintained.

follow-up commits will absolutely configure the submodules.
this is being done to reduce the number of modules downloaded,
because we don't use most of the coreboot submodules that are
downloaded, thus wasting bandwidth and the releases are also
much bigger than necessary.

Signed-off-by: Leah Rowe <leah@libreboot.org>
audit2-merge1
Leah Rowe 2024-05-24 17:50:42 +01:00 committed by Leah Rowe
parent 9339c6f3fd
commit b5aa8b2d35
1 changed files with 48 additions and 5 deletions

View File

@ -2,7 +2,8 @@
# SPDX-FileCopyrightText: 2020,2021,2023,2024 Leah Rowe <leah@libreboot.org> # SPDX-FileCopyrightText: 2020,2021,2023,2024 Leah Rowe <leah@libreboot.org>
# SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com> # SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
eval "$(setvars "" _target rev _xm loc url bkup_url depend tree_depend xtree)" eval "$(setvars "" _target rev _xm loc url bkup_url depend tree_depend xtree \
mdir subrev subrepo subrepo_bkup)"
fetch_project_trees() fetch_project_trees()
{ {
@ -111,17 +112,59 @@ git_prep()
prep_submodules() prep_submodules()
{ {
[ -f "$tmpgit/.gitmodules" ] || return 0 [ -f "$tmpgit/.gitmodules" ] || return 0
git -C "$tmpgit" submodule update --init || $err "$1: !mod"
mdir="${PWD}/config/submodule/$project" mdir="${PWD}/config/submodule/$project"
[ -n "$tree" ] && mdir="$mdir/$tree" [ -n "$tree" ] && mdir="$mdir/$tree"
git -C "$tmpgit" submodule status | awk '{print $2}' > \ if [ -f "$mdir/module.list" ]; then
"$tmpdir/modules" || $err "$mdir: cannot list submodules" cat "$mdir/module.list" > "$tmpdir/modules" || \
$err "!cp $mdir/module.list $tmpdir/modules"
else
git -C "$tmpgit" submodule status | awk '{print $2}' > \
"$tmpdir/modules" || $err "$mdir: cannot list submodules"
fi
while read -r msrcdir; do while read -r msrcdir; do
git_am_patches "$tmpgit/$msrcdir" "$mdir/${msrcdir##*/}/patches" fetch_submodule "$msrcdir"
patch_submodule "$msrcdir"
done < "$tmpdir/modules" done < "$tmpdir/modules"
# some build systems may download more (we want to control it)
rm -f "$tmpgit/.gitmodules" || $err "!rm .gitmodules as per: $mdir"
}
fetch_submodule()
{
mcfgdir="$mdir/${1##*/}"
eval "$(setvars "" subrev subrepo subrepo_bkup)"
[ ! -f "$mcfgdir/module.cfg" ] || . "$mcfgdir/module.cfg" || \
$err "! . $mcfgdir/module.cfg"
if [ -n "$subrepo" ] || [ -n "$subrepo_bkup" ]; then
[ -n "$subrev" ] || \
$err "$1 as per $mdir: subrev not defined"
rm -Rf "$tmpgit/$1" || $err "!rm '$mdir' '$1'"
for mod in "$subrepo" "$subrepo_bkup"; do
[ -z "$mod" ] && continue
git clone "$mod" "$tmpgit/$1" || rm -Rf "$tmpgit/$1" \
|| $err "!rm $mod $project $cfgdir $1"
done
[ -d "$tmpgit/$1" ] || $err "!clone $mod $project $mcfgdir $1"
else
git -C "$tmpgit" submodule update --init -- "$1" || \
$err "$mdir: !update $1"
fi
}
patch_submodule()
{
[ -z "$subrev" ] || \
git -C "$tmpgit/$1" reset --hard "$subrev" || \
$err "$mdir $1: cannot reset git revision"
git_am_patches "$tmpgit/$1" "$mdir/${1##*/}/patches"
} }
git_am_patches() git_am_patches()