forked from conan-io/conan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_xcodedeps_components.py
225 lines (186 loc) · 8.42 KB
/
test_xcodedeps_components.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import os
import platform
import textwrap
import pytest
from conans.test.utils.tools import TestClient
@pytest.mark.skipif(platform.system() != "Darwin", reason="Only for MacOS")
def test_xcodedeps_components():
"""
tcp/1.0 is a lib without components
network/1.0 lib that requires tcp/1.0 and has three components:
- core
- client -> requires core component and tcp::tcp
- server -> requires core component and tcp::tcp
chat/1.0 -> lib that requires network::client component
We create an application called ChatApp that uses XcodeDeps for chat/1.0 dependency
And check that we are not requiring more than the needed components,
nothing from network::server for example
"""
client = TestClient(path_with_spaces=False)
client.run("new tcp/1.0 -m=cmake_lib")
client.run("create . -tf=None")
header = textwrap.dedent("""
#pragma once
void {name}();
""")
source = textwrap.dedent("""
#include <iostream>
#include "{name}.h"
{include}
void {name}(){{
{call}
#ifdef NDEBUG
std::cout << "{name}/1.0: Hello World Release!" << std::endl;
#else
std::cout << "{name}/1.0: Hello World Debug!" << std::endl;
#endif
}}
""")
cmakelists = textwrap.dedent("""
cmake_minimum_required(VERSION 3.15)
project(myproject CXX)
find_package(tcp REQUIRED CONFIG)
add_library(core src/core.cpp include/core.h)
add_library(client src/client.cpp include/client.h)
add_library(server src/server.cpp include/server.h)
target_include_directories(core PUBLIC include)
target_include_directories(client PUBLIC include)
target_include_directories(server PUBLIC include)
set_target_properties(core PROPERTIES PUBLIC_HEADER "include/core.h")
set_target_properties(client PROPERTIES PUBLIC_HEADER "include/client.h")
set_target_properties(server PROPERTIES PUBLIC_HEADER "include/server.h")
target_link_libraries(client core tcp::tcp)
target_link_libraries(server core tcp::tcp)
install(TARGETS core client server)
""")
conanfile_py = textwrap.dedent("""
import os
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
class LibConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
exports_sources = "CMakeLists.txt", "src/*", "include/*"
{requires}
generators = "CMakeToolchain", "CMakeDeps"
def layout(self):
cmake_layout(self)
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
cmake = CMake(self)
cmake.install()
{package_info}
""")
network_pi = """
def package_info(self):
self.cpp_info.components["core"].libs = ["core"]
self.cpp_info.components["core"].includedirs.append("include")
self.cpp_info.components["core"].libdirs.append("lib")
self.cpp_info.components["client"].libs = ["client"]
self.cpp_info.components["client"].includedirs.append("include")
self.cpp_info.components["client"].libdirs.append("lib")
self.cpp_info.components["client"].requires.extend(["core", "tcp::tcp"])
self.cpp_info.components["server"].libs = ["server"]
self.cpp_info.components["server"].includedirs.append("include")
self.cpp_info.components["server"].libdirs.append("lib")
self.cpp_info.components["server"].requires.extend(["core", "tcp::tcp"])
"""
client.save({
"include/core.h": header.format(name="core"),
"include/server.h": header.format(name="server"),
"include/client.h": header.format(name="client"),
"src/core.cpp": source.format(name="core", include="", call=""),
"src/server.cpp": source.format(name="server", include='#include "core.h"\n#include "tcp.h"',
call="core(); tcp();"),
"src/client.cpp": source.format(name="client", include='#include "core.h"\n#include "tcp.h"',
call="core(); tcp();"),
"conanfile.py": conanfile_py.format(requires='requires= "tcp/1.0"', package_info=network_pi),
"CMakeLists.txt": cmakelists,
}, clean_first=True)
client.run("create . network/1.0@")
chat_pi = """
def package_info(self):
self.cpp_info.libs = ["chat"]
self.cpp_info.includedirs.append("include")
self.cpp_info.libdirs.append("lib")
self.cpp_info.requires.append("network::client")
"""
cmakelists_chat = textwrap.dedent("""
cmake_minimum_required(VERSION 3.15)
project(chat CXX)
find_package(network REQUIRED CONFIG)
add_library(chat src/chat.cpp include/chat.h)
target_include_directories(chat PUBLIC include)
set_target_properties(chat PROPERTIES PUBLIC_HEADER "include/chat.h")
target_link_libraries(chat network::client)
install(TARGETS chat)
""")
client.save({
"include/chat.h": header.format(name="chat"),
"src/chat.cpp": source.format(name="chat", include='#include "client.h"', call="client();"),
"conanfile.py": conanfile_py.format(requires='requires= "network/1.0"',
package_info=chat_pi),
"CMakeLists.txt": cmakelists_chat,
}, clean_first=True)
client.run("create . chat/1.0@")
xcode_project = textwrap.dedent("""
name: ChatApp
fileGroups:
- conan
targets:
chat:
type: tool
platform: macOS
sources:
- src
configFiles:
Debug: conan/conan_config.xcconfig
Release: conan/conan_config.xcconfig
""")
client.save({
"src/main.cpp": '#include "chat.h"\nint main(){chat();return 0;}',
"project.yml": xcode_project
}, clean_first=True)
client.run("install chat/1.0@ -g XcodeDeps --install-folder=conan")
client.run("install chat/1.0@ -g XcodeDeps --install-folder=conan -s build_type=Debug "
"--build=missing")
chat_xcconfig = client.load(os.path.join("conan", "conan_chat_chat.xcconfig"))
assert '#include "conan_network_client.xcconfig"' in chat_xcconfig
assert '#include "conan_network_server.xcconfig"' not in chat_xcconfig
assert '#include "conan_network_network.xcconfig"' not in chat_xcconfig
client.run_command("xcodegen generate")
client.run_command("xcodebuild -project ChatApp.xcodeproj -configuration Release -arch x86_64")
client.run_command("xcodebuild -project ChatApp.xcodeproj -configuration Debug -arch x86_64")
client.run_command("build/Debug/chat")
assert "core/1.0: Hello World Debug!" in client.out
assert "tcp/1.0: Hello World Debug!" in client.out
assert "client/1.0: Hello World Debug!" in client.out
assert "chat/1.0: Hello World Debug!" in client.out
client.run_command("build/Release/chat")
assert "core/1.0: Hello World Release!" in client.out
assert "tcp/1.0: Hello World Release!" in client.out
assert "client/1.0: Hello World Release!" in client.out
assert "chat/1.0: Hello World Release!" in client.out
@pytest.mark.skipif(platform.system() != "Darwin", reason="Only for MacOS")
@pytest.mark.tool_cmake
def test_xcodedeps_test_require():
client = TestClient()
client.run("new gtest/1.0 -m cmake_lib")
# client.run("new cmake_lib -d name=app -d version=1.0")
client.run("create . -tf=None")
# Create library having build and test requires
conanfile = textwrap.dedent(r'''
from conan import ConanFile
class HelloLib(ConanFile):
settings = "os", "compiler", "build_type", "arch"
def build_requirements(self):
self.test_requires('gtest/1.0')
''')
client.save({"conanfile.py": conanfile}, clean_first=True)
client.run("install . -g XcodeDeps")
assert os.path.isfile(os.path.join(client.current_folder, "conan_gtest.xcconfig"))
assert os.path.isfile(os.path.join(client.current_folder, "conan_gtest_gtest.xcconfig"))
assert os.path.isfile(os.path.join(client.current_folder, "conan_gtest_gtest_release_x86_64.xcconfig"))
assert '#include "conan_gtest.xcconfig"' in client.load("conandeps.xcconfig")