lynxis lazus has uploaded this change for review.

View Change

RFC: add support to create a shallow copy

Change-Id: I0f1ac8852218f158ece14c176f05574f60d9d1f7
---
A _testenv/data/scripts/create_shallow.sh
M _testenv/testenv/osmo_dev.py
2 files changed, 74 insertions(+), 3 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/34/39234/1
diff --git a/_testenv/data/scripts/create_shallow.sh b/_testenv/data/scripts/create_shallow.sh
new file mode 100755
index 0000000..f74e0c1
--- /dev/null
+++ b/_testenv/data/scripts/create_shallow.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+#
+# Copyright 2025 Alexander Couzens <lynxis@fe80.eu>
+# Under GPLv2
+#
+# Create a shallow copy of all git repos if they match a pattern
+
+set -e
+
+SRC_DIR=$1
+SHALLOW_DIR=$2
+REPOS=""
+
+if [ $# -ne 2 ]; then
+ echo "Not enough argument given"
+ exit 1
+fi
+
+if [ ! -d "$SRC_DIR" ]; then
+ echo "Error: SRC_DIR $SRC_DIR doesn't exist"
+fi
+
+cd "$SRC_DIR"
+for i in *osmo* ; do
+ echo "Checking $i for .git"
+ if [ -d "$i/.git" ]; then
+ REPOS="$REPOS $i"
+ fi
+done
+
+ADDITIONALS="libasn1c libsmpp34"
+for i in $ADDITIONALS ; do
+ echo "Checking $i for .git"
+ if [ -d "$i/.git" ]; then
+ REPOS="$REPOS $i"
+ fi
+done
+
+mkdir -p "$SHALLOW_DIR"
+cd "$SHALLOW_DIR"
+echo "All repos are $REPOS"
+for repo in $REPOS; do
+ echo "checking out $repo"
+ if [ ! -d "$repo" ]; then
+ mkdir "$repo"
+ ln -s "${SRC_DIR}/$repo/.git" "$repo/.git"
+ fi
+
+ cd "$repo"
+ git checkout -- .
+ cd ..
+done
+
+echo "All git repos cloned"
diff --git a/_testenv/testenv/osmo_dev.py b/_testenv/testenv/osmo_dev.py
index 51d07a7..f6ae3ee 100644
--- a/_testenv/testenv/osmo_dev.py
+++ b/_testenv/testenv/osmo_dev.py
@@ -52,7 +52,11 @@
sys.exit(1)


-def init():
+def init(shallow=False):
+ """ Initialize the podman container by compiling projects
+
+ :param shallow: create a shallow git copy by checkout out the last git commit into a seperate directory
+ """
global init_done
global make_dir

@@ -73,6 +77,20 @@
os.path.join(testenv.args.cache, "host/usr"),
]

+ cwd = get_osmo_dev_dir()
+ # switch paths and do a mkdir $foo ; cd $foo; ln -s $src_dir/$foo $foo/.git ; cd ..
+ src_dir = testenv.src_dir
+ if shallow:
+ tmp_dir = '/tmp/shallow'
+ os.makedirs(tmp_dir, exist_ok=True)
+ cmd = [os.path.join(testenv.data_dir, "scripts/create_shallow.sh"), src_dir, tmp_dir]
+ returncode = testenv.cmd.run(cmd, cwd=cwd, check=False).returncode
+ if returncode:
+ raise RuntimeError(f"Return code {returncode}. Ran {cmd}.")
+ logging.warning("created a shallow copy")
+
+ src_dir = '/tmp/shallow'
+
cmd = [
"./gen_makefile.py",
"--build-debug",
@@ -81,7 +99,7 @@
make_dir,
"--no-ldconfig",
"--src-dir",
- testenv.src_dir,
+ src_dir,
"default.opts",
"ccache.opts",
"gtp_linux.opts",
@@ -96,7 +114,6 @@
os.path.join(testenv.data_dir, "osmo-dev/osmo-bts-trx.opts"),
] + extra_opts

- cwd = get_osmo_dev_dir()
if testenv.cmd.run(cmd, cwd=cwd, check=False).returncode:
logging.critical("gen_makefile.py from osmo-dev failed!")
logging.critical("Your osmo-dev.git clone might be outdated, try:")

To view, visit change 39234. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: I0f1ac8852218f158ece14c176f05574f60d9d1f7
Gerrit-Change-Number: 39234
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis@fe80.eu>