forked from conan-io/conan
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_test.py
382 lines (325 loc) · 14.5 KB
/
build_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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
import os
import textwrap
import unittest
import pytest
from conans.model.ref import PackageReference
from conans.paths import BUILD_INFO, CONANFILE
from conans.test.utils.tools import NO_SETTINGS_PACKAGE_ID, TestClient
from conans.util.files import mkdir
conanfile_scope_env = """
from conans import ConanFile
class AConan(ConanFile):
requires = "Hello/0.1@lasote/testing"
generators = "cmake"
def build(self):
self.output.info("INCLUDE PATH: %s" %
self.deps_cpp_info.include_paths[0].replace('\\\\', '/'))
self.output.info("HELLO ROOT PATH: %s" % self.deps_cpp_info["Hello"].rootpath)
self.output.info("HELLO INCLUDE PATHS: %s" %
self.deps_cpp_info["Hello"].include_paths[0].replace('\\\\', '/'))
"""
conanfile_dep = """
import os
from conans import ConanFile
from conans.tools import mkdir
class AConan(ConanFile):
name = "Hello"
version = "0.1"
def package(self):
mkdir(os.path.join(self.package_folder, "include"))
"""
class ConanBuildTest(unittest.TestCase):
def test_partial_build(self):
client = TestClient()
conanfile = """from conans import ConanFile
class Conan(ConanFile):
def build(self):
self.output.info("CONFIGURE=%s!" % self.should_configure)
self.output.info("BUILD=%s!" % self.should_build)
self.output.info("INSTALL=%s!" % self.should_install)
self.output.info("TEST=%s!" % self.should_test)
"""
client.save({CONANFILE: conanfile})
client.run("install .")
client.run("build .")
self.assertIn("CONFIGURE=True!", client.out)
self.assertIn("BUILD=True!", client.out)
self.assertIn("INSTALL=True!", client.out)
self.assertIn("TEST=True!", client.out)
client.run("build . -c")
self.assertIn("CONFIGURE=True!", client.out)
self.assertIn("BUILD=False!", client.out)
self.assertIn("INSTALL=False!", client.out)
self.assertIn("TEST=False!", client.out)
client.run("build . -b")
self.assertIn("CONFIGURE=False!", client.out)
self.assertIn("BUILD=True!", client.out)
self.assertIn("INSTALL=False!", client.out)
self.assertIn("TEST=False!", client.out)
client.run("build . -i")
self.assertIn("CONFIGURE=False!", client.out)
self.assertIn("BUILD=False!", client.out)
self.assertIn("INSTALL=True!", client.out)
self.assertIn("TEST=False!", client.out)
client.run("build . -t")
self.assertIn("CONFIGURE=False!", client.out)
self.assertIn("BUILD=False!", client.out)
self.assertIn("INSTALL=False!", client.out)
self.assertIn("TEST=True!", client.out)
client.run("create . Pkg/0.1@user/testing")
self.assertIn("CONFIGURE=True!", client.out)
self.assertIn("BUILD=True!", client.out)
self.assertIn("INSTALL=True!", client.out)
self.assertIn("TEST=True!", client.out)
def test_build_error(self):
""" If not using -g txt generator, and build() requires self.deps_cpp_info,
or self.deps_user_info it wont fail because now it's automatic
"""
client = TestClient()
client.save({CONANFILE: conanfile_dep})
client.run("export . lasote/testing")
client.save({CONANFILE: conanfile_scope_env}, clean_first=True)
client.run("install . --build=missing")
client.run("build .") # We do not need to specify -g txt anymore
self.assertTrue(os.path.exists(os.path.join(client.current_folder, BUILD_INFO)))
conanfile_user_info = """
import os
from conans import ConanFile
class AConan(ConanFile):
requires = "Hello/0.1@lasote/testing"
generators = "cmake"
def build(self):
self.deps_user_info
self.deps_env_info
assert(self.build_folder == os.getcwd())
assert(hasattr(self, "package_folder"))
"""
client.save({CONANFILE: conanfile_user_info}, clean_first=True)
client.run("install . --build=missing")
client.run("build ./conanfile.py")
def test_build(self):
""" Try to reuse variables loaded from txt generator => deps_cpp_info
"""
client = TestClient()
client.save({CONANFILE: conanfile_dep})
client.run("export . lasote/testing")
client.save({CONANFILE: conanfile_scope_env}, clean_first=True)
client.run("install . --build=missing")
client.save({"my_conanfile.py": conanfile_scope_env})
client.run("build ./my_conanfile.py")
pref = PackageReference.loads("Hello/0.1@lasote/testing:%s" % NO_SETTINGS_PACKAGE_ID)
package_folder = client.cache.package_layout(pref.ref).package(pref).replace("\\", "/")
self.assertIn("my_conanfile.py: INCLUDE PATH: %s/include" % package_folder, client.out)
self.assertIn("my_conanfile.py: HELLO ROOT PATH: %s" % package_folder, client.out)
self.assertIn("my_conanfile.py: HELLO INCLUDE PATHS: %s/include"
% package_folder, client.out)
def test_build_different_folders(self):
conanfile = """
import os
from conans import ConanFile
class AConan(ConanFile):
generators = "cmake"
def build(self):
self.output.warn("Build folder=>%s" % self.build_folder)
self.output.warn("Src folder=>%s" % self.source_folder)
self.output.warn("Package folder=>%s" % self.package_folder)
assert(os.path.exists(self.build_folder))
assert(os.path.exists(self.source_folder))
# package_folder will be created manually or by the CMake helper when local invocation
assert(not os.path.exists(self.package_folder))
"""
client = TestClient()
client.save({CONANFILE: conanfile})
with client.chdir("build1"):
client.run("install ..")
# Try relative to cwd
client.run("build . --build-folder build2 --install-folder build1 "
"--package-folder build1/pkg")
self.assertIn("Build folder=>%s" % os.path.join(client.current_folder, "build2"),
client.out)
self.assertIn("Package folder=>%s" % os.path.join(client.current_folder, "build1", "pkg"),
client.out)
self.assertIn("Src folder=>%s" % client.current_folder, client.out)
# Try default package folder
client.run("build conanfile.py --build-folder build1 --package-folder package1")
self.assertIn("Build folder=>%s" % os.path.join(client.current_folder, "build1"),
client.out)
self.assertIn("Package folder=>%s" % os.path.join(client.current_folder, "package"),
client.out)
self.assertIn("Src folder=>%s" % client.current_folder, client.out)
# Try absolute package folder
client.run("build . --build-folder build1 --package-folder '%s'" %
os.path.join(client.current_folder, "mypackage"))
self.assertIn("Build folder=>%s" % os.path.join(client.current_folder, "build1"),
client.out)
self.assertIn("Package folder=>%s" % os.path.join(client.current_folder, "mypackage"),
client.out)
self.assertIn("Src folder=>%s" % client.current_folder, client.out)
# Try absolute build and relative package
conanfile_dir = client.current_folder
bdir = os.path.join(client.current_folder, "other/mybuild")
with client.chdir(bdir):
client.run("install '%s'" % conanfile_dir)
client.run("build ./conanfile.py --build-folder '%s' --package-folder relpackage" % bdir)
self.assertIn("Build folder=>%s" % os.path.join(client.current_folder, "other/mybuild"),
client.out)
self.assertIn("Package folder=>%s" % os.path.join(client.current_folder, "relpackage"),
client.out)
self.assertIn("Src folder=>%s" % client.current_folder, client.out)
# Try different source
with client.chdir("other/build"):
client.run("install ../..")
# src is not created automatically, it makes no sense
client.run("build . --source-folder '%s' --build-folder other/build" %
os.path.join(client.current_folder, "mysrc"), assert_error=True)
mkdir(os.path.join(client.current_folder, "mysrc"))
client.run("build . --source-folder '%s' --build-folder other/build"
% os.path.join(client.current_folder, "mysrc"))
self.assertIn("Build folder=>%s" % os.path.join(client.current_folder, "other", "build"),
client.out)
self.assertIn("Package folder=>%s" % os.path.join(client.current_folder, "other", "build"),
client.out)
self.assertIn("Src folder=>%s" % os.path.join(client.current_folder, "mysrc"), client.out)
def test_build_dots_names(self):
""" Try to reuse variables loaded from txt generator => deps_cpp_info
"""
client = TestClient()
conanfile_dep = """
from conans import ConanFile
class AConan(ConanFile):
pass
"""
client.save({CONANFILE: conanfile_dep})
client.run("create . Hello.Pkg/0.1@lasote/testing")
client.run("create . Hello-Tools/0.1@lasote/testing")
conanfile_scope_env = """
from conans import ConanFile
class AConan(ConanFile):
requires = "Hello.Pkg/0.1@lasote/testing", "Hello-Tools/0.1@lasote/testing"
def build(self):
self.output.info("HELLO ROOT PATH: %s" % self.deps_cpp_info["Hello.Pkg"].rootpath)
self.output.info("HELLO ROOT PATH: %s" % self.deps_cpp_info["Hello-Tools"].rootpath)
"""
client.save({CONANFILE: conanfile_scope_env}, clean_first=True)
client.run("install conanfile.py --build=missing")
client.run("build .")
self.assertIn("Hello.Pkg/0.1/lasote/testing", client.out)
self.assertIn("Hello-Tools/0.1/lasote/testing", client.out)
@pytest.mark.tool_cmake
def test_build_cmake_install(self):
client = TestClient()
conanfile = """
from conans import ConanFile, CMake
class AConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.install()
"""
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: conanfile,
"CMakeLists.txt": cmake,
"header.h": "my header h!!"})
client.run("install .")
client.run("build .") # Won't fail, by default the package_folder is build_folder/package
header = client.load("package/include/header.h")
self.assertEqual(header, "my header h!!")
client.save({CONANFILE: conanfile,
"CMakeLists.txt": cmake,
"header.h": "my header3 h!!"}, clean_first=True)
client.run("install .")
client.run("build -pf=mypkg ./conanfile.py")
header = client.load("mypkg/include/header.h")
self.assertEqual(header, "my header3 h!!")
client.save({CONANFILE: conanfile,
"CMakeLists.txt": cmake,
"header.h": "my header2 h!!"}, clean_first=True)
with client.chdir("build"):
client.run("install ..")
client.run("build . -pf=mypkg -bf=build")
header = client.load("mypkg/include/header.h")
self.assertEqual(header, "my header2 h!!")
def test_build_with_deps_env_info(self):
client = TestClient()
conanfile = """
from conans import ConanFile, CMake
class AConan(ConanFile):
name = "lib"
version = "1.0"
def package_info(self):
self.env_info.MYVAR = "23"
"""
client.save({CONANFILE: conanfile})
client.run("export . lasote/stable")
conanfile = """
from conans import ConanFile
class AConan(ConanFile):
requires = "lib/1.0@lasote/stable"
def build(self):
assert(self.deps_env_info["lib"].MYVAR == "23")
"""
client.save({CONANFILE: conanfile}, clean_first=True)
client.run("install . --build missing")
client.run("build .")
def test_build_single_full_reference(self):
client = TestClient()
conanfile = """
from conans import ConanFile, CMake
class FooConan(ConanFile):
name = "foo"
version = "1.0"
"""
client.save({CONANFILE: conanfile})
client.run("create --build foo/1.0@user/stable . user/stable")
self.assertIn("foo/1.0@user/stable: Forced build from source", client.out)
def test_build_multiple_full_reference(self):
client = TestClient()
conanfile = """
from conans import ConanFile, CMake
class FooConan(ConanFile):
name = "foo"
version = "1.0"
"""
client.save({CONANFILE: conanfile})
client.run("create . user/stable")
conanfile = """
from conans import ConanFile
class BarConan(ConanFile):
name = "bar"
version = "1.0"
requires = "foo/1.0@user/stable"
"""
client.save({CONANFILE: conanfile}, clean_first=True)
client.run("create --build foo/1.0@user/stable --build bar/1.0@user/testing . user/testing")
self.assertIn("foo/1.0@user/stable: Forced build from source", client.out)
self.assertIn("bar/1.0@user/testing: Forced build from source", client.out)
def test_debug_build_release_deps(self):
# https://github.com/conan-io/conan/issues/2899
client = TestClient()
conanfile = textwrap.dedent("""
from conans import ConanFile
class Conan(ConanFile):
name = "{name}"
{requires}
settings = "build_type"
def build(self):
self.output.info("BUILD: %s BuildType=%s!"
% (self.name, self.settings.build_type))
def package_info(self):
self.output.info("PACKAGE_INFO: %s BuildType=%s!"
% (self.name, self.settings.build_type))
""")
client.save({CONANFILE: conanfile.format(name="Dep", requires="")})
client.run("create . Dep/0.1@user/testing -s build_type=Release")
client.save({CONANFILE: conanfile.format(name="MyPkg",
requires="requires = 'Dep/0.1@user/testing'")})
client.run("install . -s MyPkg:build_type=Debug -s build_type=Release")
self.assertIn("Dep/0.1@user/testing: PACKAGE_INFO: Dep BuildType=Release!", client.out)
client.run("build .")
self.assertIn("conanfile.py (MyPkg/None): BUILD: MyPkg BuildType=Debug!",
client.out)