summaryrefslogtreecommitdiff
path: root/tests/integration/manual.py
blob: d3acf7dfac5de9d7a3de67c2d229b6b44e972223 (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
import pytest

from buildstream import _yaml

from tests.testutils import cli_integration as cli
from tests.testutils.site import IS_LINUX, NO_FUSE

pytestmark = pytest.mark.integration
pytestmark = pytest.mark.skipif(IS_LINUX and NO_FUSE, reason='FUSE not supported on this system')


DATA_DIR = os.path.join(
    os.path.dirname(os.path.realpath(__file__)),
    "project"
)


def create_manual_element(name, path, config, variables, environment):
    element = {
        'kind': 'manual',
        'depends': [{
            'filename': 'base.bst',
            'type': 'build'
        }],
        'config': config,
        'variables': variables,
        'environment': environment
    }
    os.makedirs(os.path.dirname(os.path.join(path, name)), exist_ok=True)
    _yaml.dump(element, os.path.join(path, name))


@pytest.mark.datafiles(DATA_DIR)
def test_manual_element(cli, tmpdir, datafiles):
    project = os.path.join(datafiles.dirname, datafiles.basename)
    checkout = os.path.join(cli.directory, 'checkout')
    element_path = os.path.join(project, 'elements')
    element_name = 'import/import.bst'

    create_manual_element(element_name, element_path, {
        'configure-commands': ["echo './configure' >> test"],
        'build-commands': ["echo 'make' >> test"],
        'install-commands': [
            "echo 'make install' >> test",
            "cp test %{install-root}"
        ],
        'strip-commands': ["echo 'strip' >> %{install-root}/test"]
    }, {}, {})

    res = cli.run(project=project, args=['build', element_name])
    assert res.exit_code == 0

    cli.run(project=project, args=['checkout', element_name, checkout])
    assert res.exit_code == 0

    with open(os.path.join(checkout, 'test')) as f:
        text = f.read()

    assert text == """./configure
make
make install
strip
"""


@pytest.mark.datafiles(DATA_DIR)
def test_manual_element_noparallel(cli, tmpdir, datafiles):
    project = os.path.join(datafiles.dirname, datafiles.basename)
    checkout = os.path.join(cli.directory, 'checkout')
    element_path = os.path.join(project, 'elements')
    element_name = 'import/import.bst'

    create_manual_element(element_name, element_path, {
        'install-commands': [
            "echo $MAKEFLAGS >> test",
            "echo $V >> test",
            "cp test %{install-root}"
        ]
    }, {
        'max-jobs': 2,
        'notparallel': True
    }, {
        'MAKEFLAGS': '-j%{max-jobs} -Wall',
        'V': 2
    })

    res = cli.run(project=project, args=['build', element_name])
    assert res.exit_code == 0

    cli.run(project=project, args=['checkout', element_name, checkout])
    assert res.exit_code == 0

    with open(os.path.join(checkout, 'test')) as f:
        text = f.read()

    assert text == """-j1 -Wall
2
"""


@pytest.mark.datafiles(DATA_DIR)
def test_manual_element_environment(cli, tmpdir, datafiles):
    project = os.path.join(datafiles.dirname, datafiles.basename)
    checkout = os.path.join(cli.directory, 'checkout')
    element_path = os.path.join(project, 'elements')
    element_name = 'import/import.bst'

    create_manual_element(element_name, element_path, {
        'install-commands': [
            "echo $MAKEFLAGS >> test",
            "echo $V >> test",
            "cp test %{install-root}"
        ]
    }, {
        'max-jobs': 2
    }, {
        'MAKEFLAGS': '-j%{max-jobs} -Wall',
        'V': 2
    })

    res = cli.run(project=project, args=['build', element_name])
    assert res.exit_code == 0

    cli.run(project=project, args=['checkout', element_name, checkout])
    assert res.exit_code == 0

    with open(os.path.join(checkout, 'test')) as f:
        text = f.read()

    assert text == """-j2 -Wall
2
"""