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))