aboutsummaryrefslogtreecommitdiff
blob: 10f2eb36e25db1368b856852fdf03aca6bf40dbe (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Copyright 2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

import shutil
import subprocess
import os

import portage
from portage.tests import TestCase
from portage.tests.resolver.ResolverPlayground import (
    ResolverPlayground,
    ResolverPlaygroundTestCase,
)


class CrossDepPriorityTestCase(TestCase):
    def testCrossDepPriority(self):
        """
        Test bug 919174, where cross-root merge to an empty root
        failed due to circular dependencies.
        """
        ebuilds = {
            "dev-lang/python-3.11.6": {
                "EAPI": "8",
                "DEPEND": "sys-apps/util-linux:=",
                "RDEPEND": "sys-apps/util-linux:=",
            },
            "sys-apps/util-linux-2.38.1-r2": {
                "EAPI": "8",
                "DEPEND": "selinux? ( >=sys-libs/libselinux-2.2.2-r4 )",
                "RDEPEND": "selinux? ( >=sys-libs/libselinux-2.2.2-r4 )",
                "IUSE": "selinux",
            },
            "sys-libs/libselinux-3.5-r1": {
                "EAPI": "8",
                "DEPEND": "python? ( dev-lang/python )",
                "RDEPEND": "python? ( dev-lang/python )",
                "IUSE": "python",
            },
            "dev-libs/gmp-6.3.0": {
                "EAPI": "8",
                "SLOT": "0/10.4",
                "DEPEND": "cxx? ( sys-devel/gcc )",
                "RDEPEND": "cxx? ( sys-devel/gcc )",
                "IUSE": "cxx",
            },
            "sys-devel/gcc-13.2.1_p20230826": {
                "EAPI": "8",
                "DEPEND": ">=dev-libs/gmp-4.3.2:0=",
                "RDEPEND": ">=dev-libs/gmp-4.3.2:0=",
            },
        }

        installed = {
            "dev-lang/python-3.11.6": {
                "EAPI": "8",
                "KEYWORDS": "x86",
                "DEPEND": "sys-apps/util-linux:0/0=",
                "RDEPEND": "sys-apps/util-linux:0/0=",
            },
            "sys-apps/util-linux-2.38.1-r2": {
                "EAPI": "8",
                "KEYWORDS": "x86",
                "DEPEND": "selinux? ( >=sys-libs/libselinux-2.2.2-r4 )",
                "RDEPEND": "selinux? ( >=sys-libs/libselinux-2.2.2-r4 )",
                "IUSE": "selinux",
                "USE": "selinux",
            },
            "sys-libs/libselinux-3.5-r1": {
                "EAPI": "8",
                "KEYWORDS": "x86",
                "DEPEND": "python? ( dev-lang/python )",
                "RDEPEND": "python? ( dev-lang/python )",
                "IUSE": "python",
                "USE": "python",
            },
            "dev-libs/gmp-6.3.0": {
                "EAPI": "8",
                "KEYWORDS": "x86",
                "SLOT": "0/10.4",
                "DEPEND": "cxx? ( sys-devel/gcc )",
                "RDEPEND": "cxx? ( sys-devel/gcc )",
                "IUSE": "cxx",
                "USE": "cxx",
            },
            "sys-devel/gcc-13.2.1_p20230826": {
                "EAPI": "8",
                "KEYWORDS": "x86",
                "DEPEND": ">=dev-libs/gmp-4.3.2:0/10.4=",
                "RDEPEND": ">=dev-libs/gmp-4.3.2:0/10.4=",
            },
        }

        world = [
            "sys-apps/util-linux",
            "sys-devel/gcc",
        ]

        user_config = {
            "make.conf": ('USE="cxx python selinux"',),
        }

        test_cases = (
            ResolverPlaygroundTestCase(
                ["@world"],
                options={"--emptytree": True},
                success=True,
                mergelist=[
                    "dev-libs/gmp-6.3.0",
                    "sys-devel/gcc-13.2.1_p20230826",
                    "sys-apps/util-linux-2.38.1-r2",
                    "dev-lang/python-3.11.6",
                    "sys-libs/libselinux-3.5-r1",
                ],
            ),
        )

        playground = ResolverPlayground(
            ebuilds=ebuilds,
            installed=installed,
            world=world,
            user_config=user_config,
        )
        try:
            for test_case in test_cases:
                playground.run_TestCase(test_case)
                self.assertEqual(test_case.test_success, True, test_case.fail_msg)

            # Since ResolverPlayground does not internally support
            # cross-root, test with emerge.
            cross_root = os.path.join(playground.settings["EPREFIX"], "cross_root")
            world_file = os.path.join(
                cross_root,
                playground.settings["EPREFIX"].lstrip(os.sep),
                portage.const.WORLD_FILE,
            )
            os.makedirs(os.path.dirname(world_file))
            shutil.copy(
                os.path.join(playground.settings["EPREFIX"], portage.const.WORLD_FILE),
                world_file,
            )
            result = subprocess.run(
                [
                    "emerge",
                    f"--root={cross_root}",
                    "--pretend",
                    "--verbose",
                    "--usepkgonly",
                    "--quickpkg-direct=y",
                    "@world",
                ],
                env=playground.settings.environ(),
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
            )
            output = result.stdout.decode(errors="replace")
            try:
                self.assertTrue("5 packages (5 new, 5 binaries)" in output)
                self.assertEqual(result.returncode, os.EX_OK)
            except Exception:
                print(output)
                raise
        finally:
            playground.cleanup()