1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
import os
import pytest
from buildstream import Context, Project, BuildElement
from buildstream._pipeline import Pipeline
from buildstream._platform import Platform
from tests.testutils.site import HAVE_ROOT
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
)
def create_pipeline(tmpdir, basedir, target):
context = Context('x86_64')
project = Project(basedir, 'x86_64')
context.artifactdir = os.path.join(str(tmpdir), 'artifact')
context._platform = Platform.get_platform(context, project)
return Pipeline(context, project, target)
def assert_command(datafiles, tmpdir, target, command, expected):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
pipeline = create_pipeline(tmpdir, basedir, target)
assert(isinstance(pipeline.target, BuildElement))
commands = pipeline.target.commands
assert(commands.get(command) is not None)
assert(len(commands[command]) > 0)
print("Commands:\n%s" % commands[command][0])
print("Expected:\n%s" % expected)
assert(commands[command][0] == expected)
###############################################################
# Test proper loading of some default commands from plugins #
###############################################################
@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.parametrize("target,command,expected", [
('autotools.bst', 'install-commands', "make -j1 DESTDIR=\"/buildstream/install\" install"),
('cmake.bst', 'configure-commands',
"cmake -DCMAKE_INSTALL_PREFIX:PATH=\"/usr\" \\\n" +
"-DCMAKE_INSTALL_LIBDIR=lib"),
('distutils.bst', 'install-commands',
"python3 setup.py install --prefix \"/usr\" \\\n" +
"--root \"/buildstream/install\""),
('makemaker.bst', 'configure-commands', "perl Makefile.PL PREFIX=/buildstream/install/usr"),
('modulebuild.bst', 'configure-commands', "perl Build.PL --prefix \"/buildstream/install/usr\""),
('qmake.bst', 'install-commands', "make -j1 INSTALL_ROOT=\"/buildstream/install\" install"),
])
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'defaults'))
def test_defaults(datafiles, tmpdir, target, command, expected):
assert_command(datafiles, tmpdir, target, command, expected)
################################################################
# Test overriding of variables to produce different commands #
################################################################
@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.parametrize("target,command,expected", [
('autotools.bst', 'install-commands', "make -j1 DESTDIR=\"/custom/install/root\" install"),
('cmake.bst', 'configure-commands',
"cmake -DCMAKE_INSTALL_PREFIX:PATH=\"/opt\" \\\n" +
"-DCMAKE_INSTALL_LIBDIR=lib"),
('distutils.bst', 'install-commands',
"python3 setup.py install --prefix \"/opt\" \\\n" +
"--root \"/custom/install/root\""),
('makemaker.bst', 'configure-commands', "perl Makefile.PL PREFIX=/custom/install/root/opt"),
('modulebuild.bst', 'configure-commands', "perl Build.PL --prefix \"/custom/install/root/opt\""),
('qmake.bst', 'install-commands', "make -j1 INSTALL_ROOT=\"/custom/install/root\" install"),
])
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'overrides'))
def test_overrides(datafiles, tmpdir, target, command, expected):
assert_command(datafiles, tmpdir, target, command, expected)
|