|
| 1 | +import re |
1 | 2 | import textwrap |
2 | 3 |
|
3 | 4 | from conan.test.assets.genconanfile import GenConanfile |
@@ -186,3 +187,93 @@ def build(self): |
186 | 187 | lock = c.load("wine/conan.lock") |
187 | 188 | # Testing it doesn't crash or anything like that |
188 | 189 | assert "gcc/1.0#616ce3babcecef39a27806c1a5f4b4ff" in lock |
| 190 | + |
| 191 | + |
| 192 | +def test_require_different_versions_transitive(): |
| 193 | + """ |
| 194 | + https://github.com/conan-io/conan/issues/18086 |
| 195 | + """ |
| 196 | + c = TestClient(default_server_user=True, path_with_spaces=False) |
| 197 | + qemu = textwrap.dedent(r""" |
| 198 | + import os |
| 199 | + from conan import ConanFile |
| 200 | + from conan.tools.files import save |
| 201 | + class Pkg(ConanFile): |
| 202 | + name = "myqemu" |
| 203 | + package_type = "application" |
| 204 | +
|
| 205 | + def package(self): |
| 206 | + echo = f"@echo off\necho RUNNING {self.name}/{self.version}!!" |
| 207 | + save(self, os.path.join(self.package_folder, "bin", f"{self.name}.bat"), echo) |
| 208 | + save(self, os.path.join(self.package_folder, "bin", f"{self.name}.sh"), echo) |
| 209 | + os.chmod(os.path.join(self.package_folder, "bin", f"{self.name}.sh"), 0o777) |
| 210 | + """) |
| 211 | + mytool = textwrap.dedent(r""" |
| 212 | + import os, platform |
| 213 | + from conan import ConanFile |
| 214 | + from conan.tools.files import save, chdir |
| 215 | + class Pkg(ConanFile): |
| 216 | + version = "1.0" |
| 217 | + package_type = "application" |
| 218 | +
|
| 219 | + def requirements(self): |
| 220 | + version = "1.0" if self.name == "snippy" else "2.0" |
| 221 | + self.requires(f"myqemu/{version}", visible=False, no_skip=True) |
| 222 | +
|
| 223 | + def package(self): |
| 224 | + c = f'call "%1/myqemu.bat"' if platform.system() == "Windows" else f'"$1/myqemu.sh"' |
| 225 | + echo = f"@echo off\necho RUNNING {self.name}/{self.version}!!\n{c}" |
| 226 | + save(self, os.path.join(self.package_folder, "bin", f"{self.name}.bat"), echo) |
| 227 | + save(self, os.path.join(self.package_folder, "bin", f"{self.name}"), echo) |
| 228 | + os.chmod(os.path.join(self.package_folder, "bin", f"{self.name}"), 0o777) |
| 229 | +
|
| 230 | + def package_info(self): |
| 231 | + pf = self.dependencies["myqemu"].cpp_info.bindir.replace("\\", "/") |
| 232 | + self.conf_info.define_path(f"user.myorg:{self.name}_qemu", pf) |
| 233 | + """) |
| 234 | + consumer = textwrap.dedent(""" |
| 235 | + from conan import ConanFile |
| 236 | +
|
| 237 | + class Pkg(ConanFile): |
| 238 | + name = "consumer" |
| 239 | + version = "1.0" |
| 240 | + def build_requirements(self): |
| 241 | + self.tool_requires("snippy/1.0") |
| 242 | + self.tool_requires("valgrind/1.0") |
| 243 | + def build(self): |
| 244 | + qemu_snippy = self.conf.get("user.myorg:snippy_qemu") |
| 245 | + qemu_valgrind = self.conf.get("user.myorg:valgrind_qemu") |
| 246 | + self.run(f"valgrind {qemu_valgrind}") |
| 247 | + self.run(f'snippy {qemu_snippy}') |
| 248 | + """) |
| 249 | + |
| 250 | + c.save({"qemu/conanfile.py": qemu, |
| 251 | + "tool/conanfile.py": mytool, |
| 252 | + "consumer/conanfile.py": consumer}) |
| 253 | + |
| 254 | + c.run("create qemu --version=1.0") |
| 255 | + c.run("create qemu --version=2.0") |
| 256 | + c.run("create tool --name=snippy") |
| 257 | + c.run("create tool --name=valgrind") |
| 258 | + c.run("build consumer") |
| 259 | + assert "RUNNING valgrind/1.0!!" in c.out |
| 260 | + assert "RUNNING myqemu/2.0!!" in c.out |
| 261 | + assert "RUNNING snippy/1.0!!" in c.out |
| 262 | + assert "RUNNING myqemu/1.0!!" in c.out |
| 263 | + |
| 264 | + c.run("upload * -r=default -c") |
| 265 | + # The "tools.graph:skip_binaries" shouldn't affect the result, it is never skipped |
| 266 | + for skip in ("-c tools.graph:skip_binaries=True", "-c tools.graph:skip_binaries=False", ""): |
| 267 | + c.run("remove * -c") |
| 268 | + # Re-downloads and it works |
| 269 | + c.run(f"build consumer {skip}") |
| 270 | + assert "RUNNING valgrind/1.0!!" in c.out |
| 271 | + assert "RUNNING myqemu/2.0!!" in c.out |
| 272 | + assert "RUNNING snippy/1.0!!" in c.out |
| 273 | + assert "RUNNING myqemu/1.0!!" in c.out |
| 274 | + |
| 275 | + c.run("create consumer") |
| 276 | + c.run("upload consumer/1.0 -r=default -c") |
| 277 | + c.run("remove * -c") |
| 278 | + c.run("install --requires=consumer/1.0") |
| 279 | + assert re.search(r"Skipped binaries(\s*)myqemu/1.0, myqemu/2.0, snippy/1.0, valgrind/1.0", c.out) |
0 commit comments