From 94e0e999f206689b2732940436d4a9f312da2213 Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Wed, 27 Apr 2022 14:10:31 +0200 Subject: [PATCH] use relative layer dirs to make build relocatable This patch replaces the absolute paths that are injected into BBLAYERS by relative ones. These are relative to TOPDIR. By that, the whole build directory becomes relocatable. This is of value when using a shared sstate cache and build machines with varying build locations (e.g. gitlab-ci runners). Signed-off-by: Felix Moessbauer Signed-off-by: Jan Kiszka --- kas/libcmds.py | 13 ++++++++++++- tests/test_layers.py | 12 +++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/kas/libcmds.py b/kas/libcmds.py index 98507f7..0a148f4 100644 --- a/kas/libcmds.py +++ b/kas/libcmds.py @@ -260,6 +260,16 @@ class WriteBBConfig(Command): return 'write_bbconfig' def execute(self, ctx): + def _get_layer_path_under_topdir(ctx, layer): + """ + Returns a path relative to ${TOPDIR}. + TOPDIR is a BB variable pointing to the build directory. + It is not expanded by KAS, hence we avoid + absolute paths pointing into the build host. + """ + relpath = os.path.relpath(layer, ctx.build_dir) + return '${TOPDIR}/' + relpath + def _write_bblayers_conf(ctx): filename = ctx.build_dir + '/conf/bblayers.conf' if not os.path.isdir(os.path.dirname(filename)): @@ -268,7 +278,8 @@ class WriteBBConfig(Command): fds.write(ctx.config.get_bblayers_conf_header()) fds.write('BBLAYERS ?= " \\\n ') fds.write(' \\\n '.join( - sorted(layer for repo in ctx.config.get_repos() + sorted(_get_layer_path_under_topdir(ctx, layer) + for repo in ctx.config.get_repos() for layer in repo.layers))) fds.write('"\n') fds.write('BBPATH ?= "${TOPDIR}"\n') diff --git a/tests/test_layers.py b/tests/test_layers.py index 6981abc..4ccb208 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -26,6 +26,8 @@ from kas import kas import pytest +LAYERBASE = '${TOPDIR}/..' + @pytest.fixture def dokas(tmpdir): @@ -42,7 +44,7 @@ def test_layers_default(dokas): match = 0 with open('build/conf/bblayers.conf', 'r') as f: for line in f: - if 'test_layers/kas ' in line: + if '{}/kas '.format(LAYERBASE) in line: match += 1 assert(match == 1) @@ -51,7 +53,7 @@ def test_layers_include(dokas): match = 0 with open('build/conf/bblayers.conf', 'r') as f: for line in f: - if 'test_layers/kas1/meta-' in line: + if '{}/kas1/meta-'.format(LAYERBASE) in line: match += 1 assert(match == 2) @@ -59,11 +61,11 @@ def test_layers_include(dokas): def test_layers_exclude(dokas): with open('build/conf/bblayers.conf', 'r') as f: for line in f: - assert('test_layers/kas2' not in line) + assert('{}/kas2'.format(LAYERBASE) not in line) def test_layers_strip_dot(dokas): with open('build/conf/bblayers.conf', 'r') as f: lines = f.readlines() - assert(any('test_layers/kas3 ' in x for x in lines)) - assert(any('test_layers/kas3/meta-bar' in x for x in lines)) + assert(any('{}/kas3 '.format(LAYERBASE) in x for x in lines)) + assert(any('{}/kas3/meta-bar'.format(LAYERBASE) in x for x in lines))