osmith submitted this change.
gen_makefile: {make,src}_dir: use absolute paths
Fix generating wrong relative paths when the make dir (-m) is in the
same directory as gen_makefile.py.
This was too easy to get wrong with relative paths as shown in the
previous patches. I've added tests to mitigate this and switched to
absolute paths to make the logic easier to follow.
Fix for:
$ ./gen_makefile.py -m build
$ make -C build libosmocore
…
cd build/../src/libosmocore; autoreconf -fi
/bin/sh: 1: cd: can't cd to build/../src/libosmocore
Fixes: 8ea5c0ce ("gen_makefile: fix building open5gs")
Change-Id: I8bb2af7ffb902fd690e83e36739c2b4415b9ab80
---
A contrib/jenkins.sh
M gen_makefile.py
A pytest.ini
A tests/test_gen_makefile.py
4 files changed, 78 insertions(+), 5 deletions(-)
diff --git a/contrib/jenkins.sh b/contrib/jenkins.sh
new file mode 100755
index 0000000..07c23a5
--- /dev/null
+++ b/contrib/jenkins.sh
@@ -0,0 +1,3 @@
+#!/bin/sh -ex
+
+pytest -v
diff --git a/gen_makefile.py b/gen_makefile.py
index c6e4a0b..44c257d 100755
--- a/gen_makefile.py
+++ b/gen_makefile.py
@@ -437,7 +437,7 @@
def gen_src_proj_copy(src_proj, make_dir, proj):
if not is_src_copy_needed(proj):
- return os.path.join(make_dir, src_proj)
+ return src_proj
return os.path.join(make_dir, "src_copy", proj)
def gen_make(proj, deps, configure_opts, jobs, make_dir, src_dir, build_dir, url, push_url, sudo_make_install, no_ldconfig, ldconfig_without_sudo, make_check):
@@ -445,8 +445,6 @@
if proj == 'openbsc':
src_proj = os.path.join(src_proj, 'openbsc')
- src = os.path.relpath(src_dir, make_dir)
- src_proj = os.path.relpath(src_proj, make_dir)
src_proj_copy = gen_src_proj_copy(src_proj, make_dir, proj)
build_proj = os.path.join(build_dir, proj)
@@ -491,7 +489,7 @@
-and -not -name "config.h" 2>/dev/null)
{gen_makefile_clone(proj,
- src,
+ src_dir,
src_proj,
url,
push_url,
@@ -559,6 +557,9 @@
opts_names = '+'.join([f.replace('.opts', '') for f in configure_opts_files])
make_dir = 'make-%s' % opts_names
+make_dir = os.path.abspath(make_dir)
+src_dir = os.path.abspath(args.src_dir)
+
if not os.path.isdir(make_dir):
os.makedirs(make_dir)
@@ -693,7 +694,7 @@
all_config_opts.extend(configure_opts.get('ALL') or [])
all_config_opts.extend(configure_opts.get(proj) or [])
content += gen_make(proj, deps, all_config_opts, args.jobs,
- make_dir, args.src_dir, build_dir, args.url, args.push_url,
+ make_dir, src_dir, build_dir, args.url, args.push_url,
args.sudo_make_install, args.no_ldconfig,
args.ldconfig_without_sudo, args.make_check)
diff --git a/pytest.ini b/pytest.ini
new file mode 100644
index 0000000..15f83b0
--- /dev/null
+++ b/pytest.ini
@@ -0,0 +1,3 @@
+[pytest]
+testpaths = tests
+addopts = --tb=short
diff --git a/tests/test_gen_makefile.py b/tests/test_gen_makefile.py
new file mode 100644
index 0000000..2ae0667
--- /dev/null
+++ b/tests/test_gen_makefile.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python3
+# Copyright 2025 sysmocom - s.f.m.c. GmbH
+# SPDX-License-Identifier: GPL-3.0-or-later
+import os
+import shlex
+import subprocess
+
+osmo_dev_path = os.path.realpath(os.path.join(__file__, "../../"))
+
+
+def run_cmd(cmd, *args, **kwargs):
+ print(f"+ {cmd}")
+ return subprocess.run(cmd, check=True, *args, **kwargs)
+
+
+def run_make_regen_2x(cwd):
+ """The "make regen" command regenerates the Makefile. Ensure that this
+ works twice in a row."""
+ run_cmd(["make", "regen"], cwd=cwd)
+ run_cmd(["make", "regen"], cwd=cwd)
+
+
+def put_gen_makefile_into_tmp_path(tmp_path):
+ """Ensure running gen_makefile.py -m=<relative path> works as expected."""
+ run_cmd(f"cp -v *.* {shlex.quote(str(tmp_path))}", cwd=osmo_dev_path, shell=True)
+ run_cmd(["ln", "-s", os.path.join(osmo_dev_path, "src"), os.path.join(tmp_path, "src")])
+
+
+def test_make_libosmocore_autoconf(tmp_path):
+ run_cmd(["./gen_makefile.py", "default.opts", "iu.opts", "no_dahdi.opts", "-m", tmp_path], cwd=osmo_dev_path)
+ run_cmd(["make", ".make.libosmocore.autoconf"], cwd=tmp_path)
+ run_make_regen_2x(tmp_path)
+
+
+def test_make_libosmocore_autoconf_src_copy(tmp_path):
+ run_cmd(["./gen_makefile.py", "-m", tmp_path, "--autoreconf-in-src-copy"], cwd=osmo_dev_path)
+ run_cmd(["make", ".make.libosmocore.autoconf"], cwd=tmp_path)
+ run_make_regen_2x(tmp_path)
+
+
+def test_make_libosmocore_autoconf_relative_makedir(tmp_path):
+ put_gen_makefile_into_tmp_path(tmp_path)
+ run_cmd(["./gen_makefile.py", "-m", "make"], cwd=tmp_path)
+ make_path = os.path.join(tmp_path, "make")
+ run_cmd(["make", ".make.libosmocore.autoconf"], cwd=make_path)
+ run_make_regen_2x(make_path)
+
+
+def test_make_libosmocore_autoconf_relative_makedir_src_copy(tmp_path):
+ put_gen_makefile_into_tmp_path(tmp_path)
+ run_cmd(["./gen_makefile.py", "-m", "make", "--autoreconf-in-src-copy"], cwd=tmp_path)
+ make_path = os.path.join(tmp_path, "make")
+ run_cmd(["make", ".make.libosmocore.autoconf"], cwd=make_path)
+ run_make_regen_2x(make_path)
+
+
+def test_make_open5gs_configure(tmp_path):
+ run_cmd(["./gen_makefile.py", "-m", tmp_path], cwd=osmo_dev_path)
+ run_cmd(["make", ".make.open5gs.configure"], cwd=tmp_path)
+ run_make_regen_2x(tmp_path)
+
+
+def test_make_open5gs_configure_src_copy(tmp_path):
+ run_cmd(["./gen_makefile.py", "-m", tmp_path, "--autoreconf-in-src-copy"], cwd=osmo_dev_path)
+ run_cmd(["make", ".make.open5gs.configure"], cwd=tmp_path)
+ run_make_regen_2x(tmp_path)
To view, visit change 40347. To unsubscribe, or for help writing mail filters, visit settings.