|
1 | | -# FIXME: uncomment and fix once the Conan API is refactored in Conan 2.21 |
2 | | - |
3 | | -# import os |
4 | | - |
5 | | -# from test.examples_tools import run, tmp_dir |
6 | | - |
7 | | - |
8 | | -# non_deterministic_conanfile = """\ |
9 | | -# from datetime import datetime |
10 | | - |
11 | | -# from conan import ConanFile |
12 | | -# from conan.tools.files import copy |
13 | | - |
14 | | - |
15 | | -# class HelloConan(ConanFile): |
16 | | -# name = "{name}" |
17 | | -# version = "1.0" |
18 | | -# {comment} |
19 | | - |
20 | | -# def build(self): |
21 | | -# with open("random.txt", "w") as f: |
22 | | -# f.write(str(datetime.now())) |
23 | | - |
24 | | -# def package(self): |
25 | | -# # Packaging a random content, the package revision will be different every time |
26 | | -# copy(self, "random.txt", self.source_folder, self.package_folder) |
27 | | -# """ |
28 | | - |
29 | | - |
30 | | -# def install_clean_command(): |
31 | | -# clean_command = os.path.join(os.path.dirname(os.path.realpath(__file__)), "clean") |
32 | | -# commands_folder = os.path.join("extensions", "commands") |
33 | | -# run(f"conan config install {clean_command} -tf {commands_folder}") |
34 | | - |
35 | | - |
36 | | -# # At first, copy the commands into the ${CONAN_HOME}/extensions/commands folder |
37 | | -# install_clean_command() |
38 | | - |
39 | | -# # 1. Check the custom command is appearing in conan help |
40 | | -# output = run("conan -h") |
41 | | -# assert "commands\nclean" in output.replace("\r\n", "\n") |
42 | | -# # 2. Create several packages |
43 | | -# with tmp_dir("clean_hello"): |
44 | | -# # Library (changing PREV each time) |
45 | | -# with open(os.path.join("conanfile.py"), "w") as f: |
46 | | -# f.write(non_deterministic_conanfile.format(name="clean_hello", comment="")) |
47 | | -# run("conan create .") |
48 | | -# run("conan create .") # different PREV (this is the latest one) |
49 | | - |
50 | | -# with tmp_dir("clean_other"): |
51 | | -# with open(os.path.join("conanfile.py"), "w") as f: |
52 | | -# f.write(non_deterministic_conanfile.format(name="clean_other", comment="")) |
53 | | -# run("conan create .") |
54 | | -# # Changing RREV |
55 | | -# with open(os.path.join("conanfile.py"), "w") as f: |
56 | | -# f.write(non_deterministic_conanfile.format(name="clean_other", comment="# Changing RREV")) |
57 | | -# run("conan create .") # different RREV (this is the latest one) |
58 | | - |
59 | | -# # 3. Run "conan clean" command: Cleaning all the non-latest RREVs (and its packages) and PREVs |
60 | | -# output = run("conan clean --force") |
61 | | -# assert "Removed package revision: clean_hello/1.0#" in output # removing earlier PREV from clean_hello |
62 | | -# assert "Removed recipe revision: clean_other/1.0#" in output # removing earlier RREV from clean_other |
63 | | -# # Now, it should have removed nothing |
64 | | -# output = run("conan clean --force") |
65 | | -# assert "Removed recipe revision: clean_other/1.0#" not in output |
66 | | -# assert "Removed package revision: clean_hello/1.0#" not in output |
| 1 | +import os |
| 2 | +import warnings |
| 3 | +import json |
| 4 | + |
| 5 | +from test.examples_tools import run, tmp_dir |
| 6 | +from conan import conan_version |
| 7 | + |
| 8 | +non_deterministic_conanfile = """\ |
| 9 | +from datetime import datetime |
| 10 | +
|
| 11 | +from conan import ConanFile |
| 12 | +from conan.tools.files import copy |
| 13 | +
|
| 14 | +
|
| 15 | +class HelloConan(ConanFile): |
| 16 | + name = "{name}" |
| 17 | + version = "1.0" |
| 18 | + {comment} |
| 19 | +
|
| 20 | + def build(self): |
| 21 | + with open("random.txt", "w") as f: |
| 22 | + f.write(str(datetime.now())) |
| 23 | +
|
| 24 | + def package(self): |
| 25 | + # Packaging a random content, the package revision will be different every time |
| 26 | + copy(self, "random.txt", self.source_folder, self.package_folder) |
| 27 | +""" |
| 28 | + |
| 29 | + |
| 30 | +def install_clean_command(): |
| 31 | + clean_command = os.path.join(os.path.dirname(os.path.realpath(__file__)), "clean") |
| 32 | + commands_folder = os.path.join("extensions", "commands") |
| 33 | + run(f"conan config install {clean_command} -tf {commands_folder}") |
| 34 | + |
| 35 | + |
| 36 | +# At first, copy the commands into the ${CONAN_HOME}/extensions/commands folder |
| 37 | +install_clean_command() |
| 38 | + |
| 39 | +# 1. Check the custom command is appearing in conan help |
| 40 | +output = run("conan -h") |
| 41 | +assert "commands\nclean" in output.replace("\r\n", "\n") |
| 42 | +# 2. Create several packages |
| 43 | +with tmp_dir("clean_hello"): |
| 44 | + # Library (changing PREV each time) |
| 45 | + with open(os.path.join("conanfile.py"), "w") as f: |
| 46 | + f.write(non_deterministic_conanfile.format(name="clean_hello", comment="")) |
| 47 | + run("conan create .") |
| 48 | + run("conan create .") # different PREV (this is the latest one) |
| 49 | + |
| 50 | +with tmp_dir("clean_other"): |
| 51 | + with open(os.path.join("conanfile.py"), "w") as f: |
| 52 | + f.write(non_deterministic_conanfile.format(name="clean_other", comment="")) |
| 53 | + run("conan create .") |
| 54 | + # Changing RREV |
| 55 | + with open(os.path.join("conanfile.py"), "w") as f: |
| 56 | + f.write(non_deterministic_conanfile.format(name="clean_other", comment="# Changing RREV")) |
| 57 | + run("conan create .") # different RREV (this is the latest one) |
| 58 | + |
| 59 | +if conan_version >= "2.21.0-dev": |
| 60 | + output = run("conan list '*/*#*:*#*' --format=json ") |
| 61 | + all_packages = json.loads("\n".join(output.splitlines()[1:])) |
| 62 | + output = run("conan list '*/*#latest:*#latest' --format=json") |
| 63 | + latest_packages = json.loads("\n".join(output.splitlines()[1:])) |
| 64 | + if all_packages == latest_packages: |
| 65 | + warnings.warn("Skipping 'conan clean' test because there are no old revisions to clean.") |
| 66 | + # 3. Run "conan clean" command: Cleaning all the non-latest RREVs (and its packages) and PREVs |
| 67 | + output = run("conan clean --force") |
| 68 | + assert "Removed package revision: clean_hello/1.0#" in output # removing earlier PREV from clean_hello |
| 69 | + assert "Removed recipe revision: clean_other/1.0#" in output # removing earlier RREV from clean_other |
| 70 | + # Now, it should have removed nothing |
| 71 | + output = run("conan clean --force") |
| 72 | + assert "Removed recipe revision: clean_other/1.0#" not in output |
| 73 | + assert "Removed package revision: clean_hello/1.0#" not in output |
| 74 | + # Make sure latest revisions are still there |
| 75 | + output = run("conan list '*/*#*:*#*' --format=json") |
| 76 | + listed_after = json.loads("\n".join(output.splitlines()[1:])) |
| 77 | + assert latest_packages == listed_after |
| 78 | +else: |
| 79 | + warnings.warn("Skipping 'conan clean' test because it requires Conan 2.21 due new API list.") |
0 commit comments