-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathci_test_example.py
62 lines (48 loc) · 2.44 KB
/
ci_test_example.py
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
import platform
import os
import shutil
from test.examples_tools import chdir, run
def run_example(output_folder=""):
if os.path.exists("build"):
shutil.rmtree("build")
run(f"conan install . {output_folder} --build missing")
if platform.system() == "Windows":
gen_folder = "" if output_folder else "generators\\"
with chdir("build"):
command = []
command.append(f"cmake .. -G \"Visual Studio 17 2022\" -DCMAKE_TOOLCHAIN_FILE={gen_folder}conan_toolchain.cmake")
command.append("cmake --build . --config Release")
run(" && ".join(command))
cmd_out = run("Release\\compressor.exe")
else:
build_path = "build" if output_folder else "build/Release"
gen_folder = "" if output_folder else "generators/"
cmakelists_path = ".." if output_folder else "../.."
with chdir(build_path):
command = []
# in the conanfile.py we only add CMake as tool_require in Linux
command.append(f". ./{gen_folder}conanbuild.sh")
command.append(f"cmake {cmakelists_path} -DCMAKE_TOOLCHAIN_FILE={gen_folder}conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release")
command.append("cmake --build .")
command.append(f". ./{gen_folder}deactivate_conanbuild.sh")
run(" && ".join(command))
cmd_out = run("./compressor")
assert "ZLIB VERSION: 1.2.11" in cmd_out
print("- Understanding the flexibility of using conanfile.py vs conanfile.txt -")
# first run the basic example without layout and conditionals
run_example(output_folder="--output-folder=build")
# switch the conanfile's and code and run the more advanced example
os.rename("conanfile.py", "basic_conanfile.py")
os.rename(os.path.join("src", "main.c"), os.path.join("src", "basic_main.c"))
os.rename("CMakeLists.txt", "basic_CMakeLists.txt")
os.rename("complete_conanfile.py", "conanfile.py")
os.rename(os.path.join("src", "complete_main.c"), os.path.join("src", "main.c"))
os.rename("complete_CMakeLists.txt", "CMakeLists.txt")
run_example()
# restore original state
os.rename("conanfile.py", "complete_conanfile.py")
os.rename(os.path.join("src", "main.c"), os.path.join("src", "complete_main.c"))
os.rename("CMakeLists.txt", "complete_CMakeLists.txt")
os.rename("basic_conanfile.py", "conanfile.py")
os.rename(os.path.join("src", "basic_main.c"), os.path.join("src", "main.c"))
os.rename("basic_CMakeLists.txt", "CMakeLists.txt")