Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 66 additions & 64 deletions examples/extensions/commands/ci_test_example.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,66 @@
import os

from test.examples_tools import run, tmp_dir


non_deterministic_conanfile = """\
from datetime import datetime

from conan import ConanFile
from conan.tools.files import copy


class HelloConan(ConanFile):
name = "{name}"
version = "1.0"
{comment}

def build(self):
with open("random.txt", "w") as f:
f.write(str(datetime.now()))

def package(self):
# Packaging a random content, the package revision will be different every time
copy(self, "random.txt", self.source_folder, self.package_folder)
"""


def install_clean_command():
clean_command = os.path.join(os.path.dirname(os.path.realpath(__file__)), "clean")
commands_folder = os.path.join("extensions", "commands")
run(f"conan config install {clean_command} -tf {commands_folder}")


# At first, copy the commands into the ${CONAN_HOME}/extensions/commands folder
install_clean_command()

# 1. Check the custom command is appearing in conan help
output = run("conan -h")
assert "commands\nclean" in output.replace("\r\n", "\n")
# 2. Create several packages
with tmp_dir("clean_hello"):
# Library (changing PREV each time)
with open(os.path.join("conanfile.py"), "w") as f:
f.write(non_deterministic_conanfile.format(name="clean_hello", comment=""))
run("conan create .")
run("conan create .") # different PREV (this is the latest one)

with tmp_dir("clean_other"):
with open(os.path.join("conanfile.py"), "w") as f:
f.write(non_deterministic_conanfile.format(name="clean_other", comment=""))
run("conan create .")
# Changing RREV
with open(os.path.join("conanfile.py"), "w") as f:
f.write(non_deterministic_conanfile.format(name="clean_other", comment="# Changing RREV"))
run("conan create .") # different RREV (this is the latest one)

# 3. Run "conan clean" command: Cleaning all the non-latest RREVs (and its packages) and PREVs
output = run("conan clean --force")
assert "Removed package revision: clean_hello/1.0#" in output # removing earlier PREV from clean_hello
assert "Removed recipe revision: clean_other/1.0#" in output # removing earlier RREV from clean_other
# Now, it should have removed nothing
output = run("conan clean --force")
assert "Removed recipe revision: clean_other/1.0#" not in output
assert "Removed package revision: clean_hello/1.0#" not in output
# FIXME: uncomment and fix once the Conan API is refactored in Conan 2.21

# import os

# from test.examples_tools import run, tmp_dir


# non_deterministic_conanfile = """\
# from datetime import datetime

# from conan import ConanFile
# from conan.tools.files import copy


# class HelloConan(ConanFile):
# name = "{name}"
# version = "1.0"
# {comment}

# def build(self):
# with open("random.txt", "w") as f:
# f.write(str(datetime.now()))

# def package(self):
# # Packaging a random content, the package revision will be different every time
# copy(self, "random.txt", self.source_folder, self.package_folder)
# """


# def install_clean_command():
# clean_command = os.path.join(os.path.dirname(os.path.realpath(__file__)), "clean")
# commands_folder = os.path.join("extensions", "commands")
# run(f"conan config install {clean_command} -tf {commands_folder}")


# # At first, copy the commands into the ${CONAN_HOME}/extensions/commands folder
# install_clean_command()

# # 1. Check the custom command is appearing in conan help
# output = run("conan -h")
# assert "commands\nclean" in output.replace("\r\n", "\n")
# # 2. Create several packages
# with tmp_dir("clean_hello"):
# # Library (changing PREV each time)
# with open(os.path.join("conanfile.py"), "w") as f:
# f.write(non_deterministic_conanfile.format(name="clean_hello", comment=""))
# run("conan create .")
# run("conan create .") # different PREV (this is the latest one)

# with tmp_dir("clean_other"):
# with open(os.path.join("conanfile.py"), "w") as f:
# f.write(non_deterministic_conanfile.format(name="clean_other", comment=""))
# run("conan create .")
# # Changing RREV
# with open(os.path.join("conanfile.py"), "w") as f:
# f.write(non_deterministic_conanfile.format(name="clean_other", comment="# Changing RREV"))
# run("conan create .") # different RREV (this is the latest one)

# # 3. Run "conan clean" command: Cleaning all the non-latest RREVs (and its packages) and PREVs
# output = run("conan clean --force")
# assert "Removed package revision: clean_hello/1.0#" in output # removing earlier PREV from clean_hello
# assert "Removed recipe revision: clean_other/1.0#" in output # removing earlier RREV from clean_other
# # Now, it should have removed nothing
# output = run("conan clean --force")
# assert "Removed recipe revision: clean_other/1.0#" not in output
# assert "Removed package revision: clean_hello/1.0#" not in output
2 changes: 1 addition & 1 deletion tutorial/creating_packages/build_method/ci_test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

print("- Building and running tests in the build() method -")

out = run(f"conan create . --build=missing --build=hello*")
out = run(f"conan create . -s compiler.cppstd=17 --build=missing --build=hello*")

assert "Running 1 test from 1 test suite." in out

Expand Down
4 changes: 3 additions & 1 deletion tutorial/creating_packages/build_method/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def source(self):
def requirements(self):
if self.options.with_fmt:
self.requires("fmt/8.1.1")
self.test_requires("gtest/1.11.0")

def build_requirements(self):
self.test_requires("gtest/1.17.0")

def layout(self):
cmake_layout(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class SumConan(ConanFile):
def validate(self):
check_min_cppstd(self, 11)

def requirements(self):
self.test_requires("gtest/1.11.0")
def build_requirements(self):
self.test_requires("gtest/1.17.0")

def layout(self):
cmake_layout(self)
Expand Down
4 changes: 3 additions & 1 deletion tutorial/creating_packages/package_information/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def source(self):
def requirements(self):
if self.options.with_fmt:
self.requires("fmt/8.1.1")
self.test_requires("gtest/1.11.0")

def build_requirements(self):
self.test_requires("gtest/1.17.0")

def layout(self):
cmake_layout(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def source(self):
def requirements(self):
if self.options.with_fmt:
self.requires("fmt/8.1.1")
self.test_requires("gtest/1.11.0")

def build_requirements(self):
self.test_requires("gtest/1.17.0")

def layout(self):
cmake_layout(self)
Expand Down
4 changes: 3 additions & 1 deletion tutorial/creating_packages/package_method/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def source(self):
def requirements(self):
if self.options.with_fmt:
self.requires("fmt/8.1.1")
self.test_requires("gtest/1.11.0")

def build_requirements(self):
self.test_requires("gtest/1.17.0")

def layout(self):
cmake_layout(self)
Expand Down
4 changes: 3 additions & 1 deletion tutorial/creating_packages/package_method/manual_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def source(self):
def requirements(self):
if self.options.with_fmt:
self.requires("fmt/8.1.1")
self.test_requires("gtest/1.11.0")

def build_requirements(self):
self.test_requires("gtest/1.17.0")

def layout(self):
cmake_layout(self)
Expand Down
4 changes: 3 additions & 1 deletion tutorial/creating_packages/testing_packages/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def source(self):
def requirements(self):
if self.options.with_fmt:
self.requires("fmt/8.1.1")
self.test_requires("gtest/1.11.0")

def build_requirements(self):
self.test_requires("gtest/1.17.0")

def layout(self):
cmake_layout(self)
Expand Down