-
Notifications
You must be signed in to change notification settings - Fork 989
/
cmake_install_package_test.py
125 lines (106 loc) · 4.51 KB
/
cmake_install_package_test.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
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
import textwrap
import unittest
import pytest
from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.tools import TestClient
class CMakeInstallPackageTest(unittest.TestCase):
def test_patch_config(self):
client = TestClient()
conanfile = """from conans import ConanFile, CMake
from conans.tools import save, load
import os
import platform
def _mess_with_path(pathstr):
if platform.system() == "Windows":
drive, path = os.path.splitdrive(pathstr)
return drive.upper() + path.replace(os.path.sep,"/")
return pathstr
class AConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
def build(self):
cmake = CMake(self)
pth = _mess_with_path(self.package_folder)
self.output.info("output path: %s" % pth)
save("file1.cmake", "FOLDER " + pth)
save("sub/file1.cmake", "FOLDER " + pth)
cmake.patch_config_paths()
def package(self):
self.copy("*")
self.output.info("RESULT: " + load(os.path.join(self.package_folder, "file1.cmake")))
self.output.info("RESULT2: " + load(os.path.join(self.package_folder, "sub/file1.cmake")))
"""
client.save({"conanfile.py": conanfile})
client.run("create . Pkg/0.1@user/channel")
self.assertIn("Pkg/0.1@user/channel: RESULT: FOLDER ${CONAN_PKG_ROOT}", client.out)
self.assertIn("Pkg/0.1@user/channel: RESULT2: FOLDER ${CONAN_PKG_ROOT}", client.out)
client.run("install .")
client.run("build .", assert_error=True)
self.assertIn("ConanException: cmake.patch_config_paths() can't work without package name",
client.out)
@pytest.mark.tool_cmake
def test_install_package(self):
client = TestClient()
conanfile = """from conans import ConanFile, CMake
class AConan(ConanFile):
name = "Test"
version = "0.1"
settings = "os", "compiler", "build_type", "arch"
exports_sources = "CMakeLists.txt", "*.h"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.install()
"""
test_conanfile = """from conans import ConanFile, load
class TestConan(ConanFile):
requires = "Test/0.1@user/channel"
def imports(self):
self.copy("*.h", "myimports")
def test(self):
self.output.info("Content: %s" % load("myimports/include/header.h"))
"""
cmake = """set(CMAKE_CXX_COMPILER_WORKS 1)
project(Chat NONE)
cmake_minimum_required(VERSION 2.8.12)
install(FILES header.h DESTINATION include)
"""
client.save({"conanfile.py": conanfile,
"test/conanfile.py": test_conanfile,
"CMakeLists.txt": cmake,
"header.h": "my header h!!"})
client.run("create . user/channel")
self.assertIn("Test/0.1@user/channel (test package): Content: my header h!!",
client.out)
# Test also recipe without settings
new_conanfile =\
conanfile.replace("settings = \"os\", \"compiler\", \"build_type\", \"arch\"", "")
self.assertNotIn("settings = \"os\", \"compiler\", \"build_type\", \"arch\"", new_conanfile)
client.save({"conanfile.py": new_conanfile})
client.run("remove * --force")
client.run("create . user/channel")
self.assertIn("Test/0.1@user/channel (test package): Content: my header h!!", client.out)
@pytest.mark.tool_cmake
def test_cmake_install_test_package(self):
client = TestClient()
test_conanfile = textwrap.dedent("""
from conans import ConanFile, CMake, load
class TestConan(ConanFile):
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.install()
def test(self):
self.output.info("Content: %s" % load("package/include/header.h"))
""")
cmake = textwrap.dedent("""set(CMAKE_CXX_COMPILER_WORKS 1)
project(Chat NONE)
cmake_minimum_required(VERSION 2.8.12)
install(FILES header.h DESTINATION include)
""")
client.save({"conanfile.py": GenConanfile(),
"test/conanfile.py": test_conanfile,
"test/CMakeLists.txt": cmake,
"test/header.h": "my header h!!"})
client.run("create . pkg/0.1@")
self.assertIn("pkg/0.1 (test package): Running test()", client.out)
self.assertIn("pkg/0.1 (test package): Content: my header h!!", client.out)