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 <felix.moessbauer@siemens.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
parent
b3405be5e8
commit
94e0e999f2
@ -260,6 +260,16 @@ class WriteBBConfig(Command):
|
|||||||
return 'write_bbconfig'
|
return 'write_bbconfig'
|
||||||
|
|
||||||
def execute(self, ctx):
|
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):
|
def _write_bblayers_conf(ctx):
|
||||||
filename = ctx.build_dir + '/conf/bblayers.conf'
|
filename = ctx.build_dir + '/conf/bblayers.conf'
|
||||||
if not os.path.isdir(os.path.dirname(filename)):
|
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(ctx.config.get_bblayers_conf_header())
|
||||||
fds.write('BBLAYERS ?= " \\\n ')
|
fds.write('BBLAYERS ?= " \\\n ')
|
||||||
fds.write(' \\\n '.join(
|
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)))
|
for layer in repo.layers)))
|
||||||
fds.write('"\n')
|
fds.write('"\n')
|
||||||
fds.write('BBPATH ?= "${TOPDIR}"\n')
|
fds.write('BBPATH ?= "${TOPDIR}"\n')
|
||||||
|
@ -26,6 +26,8 @@ from kas import kas
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
LAYERBASE = '${TOPDIR}/..'
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def dokas(tmpdir):
|
def dokas(tmpdir):
|
||||||
@ -42,7 +44,7 @@ def test_layers_default(dokas):
|
|||||||
match = 0
|
match = 0
|
||||||
with open('build/conf/bblayers.conf', 'r') as f:
|
with open('build/conf/bblayers.conf', 'r') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
if 'test_layers/kas ' in line:
|
if '{}/kas '.format(LAYERBASE) in line:
|
||||||
match += 1
|
match += 1
|
||||||
assert(match == 1)
|
assert(match == 1)
|
||||||
|
|
||||||
@ -51,7 +53,7 @@ def test_layers_include(dokas):
|
|||||||
match = 0
|
match = 0
|
||||||
with open('build/conf/bblayers.conf', 'r') as f:
|
with open('build/conf/bblayers.conf', 'r') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
if 'test_layers/kas1/meta-' in line:
|
if '{}/kas1/meta-'.format(LAYERBASE) in line:
|
||||||
match += 1
|
match += 1
|
||||||
assert(match == 2)
|
assert(match == 2)
|
||||||
|
|
||||||
@ -59,11 +61,11 @@ def test_layers_include(dokas):
|
|||||||
def test_layers_exclude(dokas):
|
def test_layers_exclude(dokas):
|
||||||
with open('build/conf/bblayers.conf', 'r') as f:
|
with open('build/conf/bblayers.conf', 'r') as f:
|
||||||
for line in 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):
|
def test_layers_strip_dot(dokas):
|
||||||
with open('build/conf/bblayers.conf', 'r') as f:
|
with open('build/conf/bblayers.conf', 'r') as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
assert(any('test_layers/kas3 ' in x for x in lines))
|
assert(any('{}/kas3 '.format(LAYERBASE) in x for x in lines))
|
||||||
assert(any('test_layers/kas3/meta-bar' in x for x in lines))
|
assert(any('{}/kas3/meta-bar'.format(LAYERBASE) in x for x in lines))
|
||||||
|
Loading…
Reference in New Issue
Block a user