def check_build_vs_project_with_test_requires(vs_version): client = TestClient() client.save(pkg_cmake("updep.pkg.team", "0.1")) client.run("create . -s compiler.version={vs_version}".format( vs_version=vs_version)) client.save(pkg_cmake("mydep.pkg.team", "0.1", requires=["updep.pkg.team/0.1"]), clean_first=True) client.run("create . -s compiler.version={vs_version}".format( vs_version=vs_version)) consumer = textwrap.dedent(""" from conans import ConanFile from conan.tools.microsoft import MSBuild class HelloConan(ConanFile): settings = "os", "build_type", "compiler", "arch" generators = "MSBuildDeps", "MSBuildToolchain" def build_requirements(self): self.build_requires("mydep.pkg.team/0.1", force_host_context=True) def build(self): msbuild = MSBuild(self) msbuild.build("MyProject.sln") """) files = get_vs_project_files() main_cpp = gen_function_cpp(name="main", includes=["mydep_pkg_team"], calls=["mydep_pkg_team"]) files["MyProject/main.cpp"] = main_cpp files["conanfile.py"] = consumer props = os.path.join(client.current_folder, "conandeps.props") old = r'<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />' new = old + '<Import Project="{props}" />'.format(props=props) files["MyProject/MyProject.vcxproj"] = files[ "MyProject/MyProject.vcxproj"].replace(old, new) client.save(files, clean_first=True) client.run('install . -s compiler.version={vs_version}'.format( vs_version=vs_version)) client.run("build .") client.run_command(r"x64\Release\MyProject.exe") assert "mydep_pkg_team: Release!" in client.out assert "updep_pkg_team: Release!" in client.out
def test_m1(op_system): os_version = "os.version=12.0" if op_system == "iOS" else "" profile = textwrap.dedent(""" include(default) [settings] os={} {} arch=armv8 """.format(op_system, os_version)) client = TestClient(path_with_spaces=False) client.save({"m1": profile}, clean_first=True) client.run("new hello/0.1 --template=cmake_lib") client.run("create . --profile:build=default --profile:host=m1 -tf None") main = gen_function_cpp(name="main", includes=["hello"], calls=["hello"]) cmakelists = gen_cmakelists(find_package=["hello"], appname="main", appsources=["main.cpp"]) conanfile = textwrap.dedent(""" from conans import ConanFile from conan.tools.cmake import CMake class TestConan(ConanFile): requires = "hello/0.1" settings = "os", "compiler", "arch", "build_type" exports_sources = "CMakeLists.txt", "main.cpp" generators = "CMakeDeps", "CMakeToolchain" def build(self): cmake = CMake(self) cmake.configure() cmake.build() """) client.save({"conanfile.py": conanfile, "CMakeLists.txt": cmakelists, "main.cpp": main, "m1": profile}, clean_first=True) client.run("install . --profile:build=default --profile:host=m1") client.run("build .") main_path = "./main.app/main" if op_system == "iOS" else "./main" client.run_command(main_path, assert_error=True) assert "Bad CPU type in executable" in client.out client.run_command("lipo -info {}".format(main_path)) assert "Non-fat file" in client.out assert "is architecture: arm64" in client.out
def test_flags(self): client = TestClient() client.save({"conanfile.py": conanfile_py}) client.run("export . lasote/testing") client.save({"conanfile.txt": conanfile, "CMakeLists.txt": cmake}, clean_first=True) client.run('install . -g cmake') generator = '-G "Visual Studio 15 Win64"' if platform.system() == "Windows" else "" client.run_command("cmake . %s" % generator) cmake_cxx_flags = self._get_line(client.out, "CMAKE_CXX_FLAGS") self.assertTrue(cmake_cxx_flags.endswith("MyFlag1 MyFlag2")) self.assertIn("CONAN_CXX_FLAGS=MyFlag1 MyFlag2", client.out) self.assertIn("CMAKE_C_FLAGS= -load C:\some\path", client.out) self.assertIn("CONAN_C_FLAGS=-load C:\some\path ", client.out) self.assertIn('CONAN_DEFINES_HELLO=-DMY_DEF=My" \string;-DMY_DEF2=My${} other \string', client.out)
def reuse_scm_test(self): client = TestClient() conanfile = """from conans import ConanFile scm = {"type" : "git", "url" : "somerepo", "revision" : "auto"} class MyConanfileBase(ConanFile): scm = scm """ create_local_git_repo({"conanfile.py": conanfile}, branch="my_release", folder=client.current_folder) client.run("export . MyConanfileBase/1.1@lasote/testing") client.run("get MyConanfileBase/1.1@lasote/testing") # The global scm is left as-is self.assertIn( """scm = {"type" : "git", "url" : "somerepo", "revision" : "auto"}""", client.out) # but the class one is replaced self.assertNotIn("scm = scm", client.out) self.assertIn(' scm = {"revision":', client.out) self.assertIn('"type": "git",', client.out) self.assertIn('"url": "somerepo"', client.out) reuse = """from conans import python_requires base = python_requires("MyConanfileBase/1.1@lasote/testing") class PkgTest(base.MyConanfileBase): scm = base.scm other = 123 def _my_method(self): pass """ client.save({"conanfile.py": reuse}) # Commit changes so it replaces and exports the scm data client.run_command('git add .') client.run_command('git commit -m "Modified conanfile"') client.run("export . Pkg/0.1@lasote/testing") client.run("get Pkg/0.1@lasote/testing") self.assertNotIn("scm = base.scm", client.out) self.assertIn('scm = {"revision":', client.out) self.assertIn('"type": "git",', client.out) self.assertIn('"url": "somerepo"', client.out)
def test_pkg_config_definitions_escape(): client = TestClient(path_with_spaces=False) conanfile = textwrap.dedent(r''' from conans import ConanFile class HelloLib(ConanFile): def package_info(self): self.cpp_info.defines.append("USER_CONFIG=\"user_config.h\"") self.cpp_info.defines.append('OTHER="other.h"') self.cpp_info.cflags.append("flag1=\"my flag1\"") self.cpp_info.cxxflags.append('flag2="my flag2"') ''') client.save({"conanfile.py": conanfile}) client.run("export . hello/1.0@") client.save({"conanfile.txt": "[requires]\nhello/1.0\n"}, clean_first=True) client.run("install . --build=missing -g pkg_config") client.run_command("PKG_CONFIG_PATH=$(pwd) pkg-config --cflags hello") assert r'flag2=\"my flag2\" flag1=\"my flag1\" -DUSER_CONFIG=\"user_config.h\" -DOTHER=\"other.h\"' in client.out
def test_uploaded_chain(self): self._export_upload("Hello0", "0.1") self._export_upload("Hello1", "0.1", ["Hello0/0.1@lasote/stable"]) client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) files = cpp_hello_conan_files("Hello2", "0.1", ["Hello1/0.1@lasote/stable"], static=True) client.save(files) client.run("install .") client.run("build .") command = os.sep.join([".", "bin", "say_hello"]) client.run_command(command) self.assertEqual(['Hello Hello2', 'Hello Hello1', 'Hello Hello0'], str(client.out).splitlines()[-3:])
def test_export(self): # Check the shallow value is substituted with the proper value client = TestClient() files = {'conanfile.py': self.conanfile.format(shallow_attrib=self._shallow_attrib_str(), url='auto', rev='auto')} url, _ = create_local_git_repo(files=files) client.run_command('git clone "{}" .'.format(url)) client.run("export . {}".format(self.ref)) content = load(client.cache.package_layout(self.ref).conanfile()) if self.shallow in [None, True, "None"]: self.assertNotIn("shallow", content) else: self.assertIn('"shallow": False', content) client.run("inspect {} -a scm".format(self.ref)) # Check we get a loadable conanfile.py
def test_toolchain_win_debug(self): client = TestClient(path_with_spaces=False) settings = { "compiler": "Visual Studio", "compiler.version": "15", "compiler.toolset": "v140", "compiler.runtime": "MDd", "build_type": "Debug", "arch": "x86_64" } # Build the profile according to the settings provided settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items() if v) client.run("new hello/0.1 -s") client.run("create . hello/0.1@ %s" % (settings, )) # Prepare the actual consumer package client.save( { "conanfile.py": self.conanfile, "MyProject.sln": sln_file, "MyApp/MyApp.vcxproj": myapp_vcxproj, "MyApp/MyApp.cpp": self.app }, clean_first=True) # Run the configure corresponding to this test case client.run("install . %s -if=conan" % (settings, )) self.assertIn( "conanfile.py: MSBuildToolchain created conan_toolchain_debug_x64.props", client.out) client.run("build . -if=conan") self.assertIn("Visual Studio 2017", client.out) self.assertIn("[vcvarsall.bat] Environment initialized for: 'x64'", client.out) self._run_app(client, "x64", "Debug") self.assertIn("main _MSC_VER1900", client.out) self.assertIn("main _MSVC_LANG2014", client.out) vcvars = vcvars_command(version="15", architecture="amd64") cmd = ('%s && dumpbin /dependents "x64\\Debug\\MyApp.exe"' % vcvars) client.run_command(cmd) self.assertIn("MSVCP140D.dll", client.out) self.assertIn("VCRUNTIME140D.dll", client.out)
def test_build_vs_project(self, generator, props): client = TestClient() client.save({"conanfile.py": hello_conanfile_py, "hello.h": hello_h}) client.run("create . lasote/testing") files = get_vs_project_files() files["MyProject/main.cpp"] = main_cpp files["conanfile.txt"] = conanfile_txt.format(generator=generator) props = os.path.join(client.current_folder, props) old = r'<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />' new = old + '<Import Project="{props}" />'.format(props=props) files["MyProject/MyProject.vcxproj"] = files[ "MyProject/MyProject.vcxproj"].replace(old, new) client.save(files, clean_first=True) for build_type in ["Debug", "Release"]: arch = "x86" runner = ConanRunner(print_commands_to_output=True, generate_run_log_file=False, log_run_to_output=True, output=TestBufferConanOutput()) settings = MockSettings({ "os": "Windows", "build_type": build_type, "arch": arch, "compiler": "Visual Studio", "compiler.version": "15", "compiler.toolset": "v141" }) conanfile = MockConanfile(settings, runner=runner) settings = " -s os=Windows " \ " -s build_type={build_type} " \ " -s arch={arch}" \ " -s compiler=\"Visual Studio\"" \ " -s compiler.toolset=v141" \ " -s compiler.version=15".format(build_type=build_type, arch=arch) client.run("install . %s" % settings) with tools.chdir(client.current_folder): msbuild = MSBuild(conanfile) msbuild.build(project_file="MyProject.sln", build_type=build_type, arch=arch) output = TestBufferConanOutput() client.run_command(r"%s\MyProject.exe" % build_type) self.assertIn("Hello %s!!!" % build_type, client.out)
class PremakeGeneratorTest(unittest.TestCase): def setUp(self): self.client = TestClient() conanfile = textwrap.dedent(""" [generators] premake """) premake = textwrap.dedent(""" include("conanbuildinfo.premake.lua") workspace("example") conan_basic_setup() project("example") kind "ConsoleApp" language "C++" targetdir = "bin/%{cfg.buildcfg}" filter "configurations:Debug" defines { "DEBUG" } symbols "On" filter "configurations:Release" defines { "NDEBUG" } optimize "On" """) self.client.save({"conanfile.txt": conanfile, "premake5.lua": premake}, clean_first=True) def test_generate_basic_setup_release(self): self.client.run("install . -s build_type=Release -s arch=x86_64 --build missing") self.client.run_command("premake5 vs2017") sln_content = self.client.load("example.sln") self.assertIn("Release|x64", sln_content) self.assertNotIn("Debug|Win32", sln_content) self.assertNotIn("Debug|x64", sln_content) def test_generate_basic_setup_debug_32bit(self): self.client.run("install . -s build_type=Debug -s arch=x86 --build missing") self.client.run_command("premake5 vs2017") sln_content = self.client.load("example.sln") self.assertIn("Debug|Win32", sln_content) self.assertNotIn("Release|Win32", sln_content) self.assertNotIn("Release|x64", sln_content)
def test_toolchain_win_debug(self): client = TestClient(path_with_spaces=False) settings = {"compiler": "Visual Studio", "compiler.version": "15", "compiler.toolset": "v140", "compiler.runtime": "MDd", "build_type": "Debug", "arch": "x86_64"} # Build the profile according to the settings provided settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items() if v) client.run("new hello/0.1 -s") client.run("create . hello/0.1@ %s" % (settings,)) # Prepare the actual consumer package client.save({"conanfile.py": self.conanfile, "MyProject.sln": sln_file, "MyApp/MyApp.vcxproj": myapp_vcxproj, "MyApp/MyApp.cpp": self.app}, clean_first=True) # Run the configure corresponding to this test case client.run("install . %s -if=conan" % (settings, )) self.assertIn("conanfile.py: MSBuildToolchain created conan_toolchain_debug_x64_v140.props", client.out) vs_path = vs_installation_path("15") vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat") cmd = ('set "VSCMD_START_DIR=%%CD%%" && ' '"%s" x64 && ' 'msbuild "MyProject.sln" /p:Configuration=Debug /p:PlatformToolset="v140"' % vcvars_path) client.run_command(cmd) self.assertIn("Visual Studio 2017", client.out) self.assertIn("[vcvarsall.bat] Environment initialized for: 'x64'", client.out) self._run_app(client, "x64", "Debug") self.assertIn("AppMSCVER 15!!", client.out) self.assertIn("AppCppStd 14!!!", client.out) cmd = ('set "VSCMD_START_DIR=%%CD%%" && ' '"%s" x64 && dumpbin /dependents "x64\\Debug\\MyApp.exe"' % vcvars_path) client.run_command(cmd) self.assertIn("MSVCP140D.dll", client.out) self.assertIn("VCRUNTIME140D.dll", client.out)
def test_cross_x86(): conanfile_py = textwrap.dedent(""" from conans import ConanFile, tools from conan.tools.meson import Meson, MesonToolchain class App(ConanFile): settings = "os", "arch", "compiler", "build_type" options = {"shared": [True, False], "fPIC": [True, False]} default_options = {"shared": False, "fPIC": True} def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def generate(self): tc = MesonToolchain(self, backend='vs') tc.generate() def build(self): meson = Meson(self) meson.configure() meson.build() """) meson_build = textwrap.dedent(""" project('tutorial', 'cpp') executable('demo', 'main.cpp') """) main_cpp = gen_function_cpp(name="main") client = TestClient() client.save({ "conanfile.py": conanfile_py, "meson.build": meson_build, "main.cpp": main_cpp }) client.run("install .") content = client.load("conan_meson_native.ini") assert "backend = 'vs'" in content client.run("build .") assert "Auto detected Visual Studio backend" in client.out client.run_command(os.path.join("build", "demo")) assert "main _M_X64 defined" in client.out assert "main _MSC_VER19" in client.out assert "main _MSVC_LANG2014" in client.out
def test_cmake_toolchain_runtime_types_cmake_older_than_3_15(): client = TestClient(path_with_spaces=False) # Setting an older cmake_minimum_required in the CMakeLists fails, will link # against the default debug runtime (MDd->MSVCRTD), not against MTd->LIBCMTD client.run("new hello/0.1 --template=cmake_lib") replace_in_file(os.path.join(client.current_folder, "CMakeLists.txt"), 'cmake_minimum_required(VERSION 3.15)', 'cmake_minimum_required(VERSION 3.1)' , output=client.out) client.run("install . -s compiler.runtime=MTd -s build_type=Debug") client.run("build .") vcvars = vcvars_command(version="15", architecture="x64") lib = os.path.join(client.current_folder, "build", "Debug", "hello.lib") dumpbind_cmd = '{} && dumpbin /directives "{}"'.format(vcvars, lib) client.run_command(dumpbind_cmd) assert "LIBCMTD" in client.out
def test_toolchain_win(self): client = TestClient(path_with_spaces=False) settings = {"compiler": "Visual Studio", "compiler.version": "15", "compiler.cppstd": "17", "compiler.runtime": "MT", "build_type": "Release", "arch": "x86"} # Build the profile according to the settings provided settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items() if v) client.run("new hello/0.1 -s") client.run("create . hello/0.1@ %s" % (settings, )) # Prepare the actual consumer package client.save({"conanfile.py": self.conanfile, "MyProject.sln": sln_file, "MyApp/MyApp.vcxproj": myapp_vcxproj, "MyApp/MyApp.cpp": self.app}, clean_first=True) # Run the configure corresponding to this test case client.run("install . %s -if=conan" % (settings, )) self.assertIn("conanfile.py: MSBuildToolchain created " "conan_toolchain_release_win32_v141.props", client.out) vs_path = vs_installation_path("15") vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat") cmd = ('set "VSCMD_START_DIR=%%CD%%" && ' '"%s" x86 && msbuild "MyProject.sln" /p:Configuration=Release' % vcvars_path) client.run_command(cmd) self.assertIn("Visual Studio 2017", client.out) self.assertIn("[vcvarsall.bat] Environment initialized for: 'x86'", client.out) self._run_app(client, "x86", "Release") self.assertIn("AppMSCVER 17!!", client.out) self.assertIn("AppCppStd 17!!!", client.out) cmd = ('set "VSCMD_START_DIR=%%CD%%" && ' '"%s" x86 && dumpbin /dependents "Release\\MyApp.exe"' % vcvars_path) client.run_command(cmd) # No other DLLs dependencies rather than kernel, it was MT, statically linked self.assertIn("KERNEL32.dll", client.out) self.assertEqual(1, str(client.out).count(".dll"))
def msbuild_generator_test(self): client = TestClient() # Upload to alternative server Hello0 but Hello1 to the default files = cpp_hello_conan_files("Hello0", "1.0") client.save(files) client.run("create . ") files = cpp_hello_conan_files("Hello3", "1.0") client.save(files, clean_first=True) client.run("create . ") files = cpp_hello_conan_files("Hello1", "1.0", deps=["Hello0/1.0"]) client.save(files, clean_first=True) client.run("create . ") conanfile = textwrap.dedent(""" from conans import ConanFile, MSBuild class HelloConan(ConanFile): settings = "os", "build_type", "compiler", "arch" requires = "Hello1/1.0", "Hello3/1.0" generators = "msbuild" def build(self): msbuild = MSBuild(self) msbuild.build("MyProject.sln") """) files = { "MyProject.sln": sln_file, "MyProject/MyProject.vcxproj": myproject_vcxproj, "MyProject/MyProject.cpp": myproject_cpp, "MyApp/MyApp.vcxproj": myapp_vcxproj, "MyApp/MyApp.cpp": myapp_cpp, "conanfile.py": conanfile } client.save(files, clean_first=True) client.run("install .") # Need to test also with bare SLN, because the helper is doing too much client.run("build .") client.run_command(r"x64\Release\MyProject.exe") self.assertIn("Hello World!", client.out) self.assertIn("Hello Hello3", client.out) client.run_command(r"x64\Release\MyApp.exe") self.assertIn("Hello App!", client.out) self.assertIn("Hello Hello1", client.out) self.assertIn("Hello Hello0", client.out)
def test_msbuild_generator(self): client = TestClient() files = cpp_hello_conan_files("Hello0", "1.0") client.save(files) client.run("create . ") files = cpp_hello_conan_files("Hello3", "1.0") client.save(files, clean_first=True) client.run("create . ") files = cpp_hello_conan_files("Hello1", "1.0", deps=["Hello0/1.0"]) client.save(files, clean_first=True) client.run("create . ") conanfile = textwrap.dedent(""" from conans import ConanFile, MSBuild class HelloConan(ConanFile): settings = "os", "build_type", "compiler", "arch" requires = "Hello1/1.0", "Hello3/1.0" generators = "MSBuildDeps" def build(self): msbuild = MSBuild(self) msbuild.build("MyProject.sln") """) myapp_cpp = gen_function_cpp(name="main", msg="MyApp", includes=["helloHello1"], calls=["helloHello1"]) myproject_cpp = gen_function_cpp(name="main", msg="MyProject", includes=["helloHello3"], calls=["helloHello3"]) files = {"MyProject.sln": sln_file, "MyProject/MyProject.vcxproj": myproject_vcxproj, "MyProject/MyProject.cpp": myproject_cpp, "MyApp/MyApp.vcxproj": myapp_vcxproj, "MyApp/MyApp.cpp": myapp_cpp, "conanfile.py": conanfile} client.save(files, clean_first=True) client.run("install .") client.run("build .") self.assertNotIn("warning MSB4011", client.out) client.run_command(r"x64\Release\MyProject.exe") self.assertIn("MyProject: Release!", client.out) self.assertIn("Hello Hello3", client.out) client.run_command(r"x64\Release\MyApp.exe") self.assertIn("MyApp: Release!", client.out) self.assertIn("Hello Hello1", client.out) self.assertIn("Hello Hello0", client.out)
def test_shared_cmake_toolchain(): client = TestClient(default_server_user=True) client.save(pkg_cmake("hello", "0.1")) client.run("create . -o hello:shared=True") client.save(pkg_cmake("chat", "0.1", requires=["hello/0.1"]), clean_first=True) client.run("create . -o chat:shared=True -o hello:shared=True") client.save(pkg_cmake_app("app", "0.1", requires=["chat/0.1"]), clean_first=True) client.run("create . -o chat:shared=True -o hello:shared=True") client.run("upload * --all -c") client.run("remove * -f") client = TestClient(servers=client.servers, users=client.users) client.run("install app/0.1@ -o chat:shared=True -o hello:shared=True -g VirtualEnv") command = environment_wrap_command("conanrunenv", "app", cwd=client.current_folder) client.run_command(command) assert "main: Release!" in client.out assert "chat: Release!" in client.out assert "hello: Release!" in client.out
def test_config_fails_git_folder(self): # https://github.com/conan-io/conan/issues/8594 folder = os.path.join(temp_folder(), ".gitlab-conan", ".conan") client = TestClient(cache_folder=folder) with client.chdir(self.folder): client.run_command('git init .') client.run_command('git add .') client.run_command('git config user.name myname') client.run_command('git config user.email [email protected]') client.run_command('git commit -m "mymsg"') assert ".gitlab-conan" in client.cache_folder assert os.path.basename(client.cache_folder) == ".conan" conf = load(client.cache.conan_conf_path) assert "config_install_interval = 5m" not in conf client.run('config install "%s/.git" --type git' % self.folder) conf = load(client.cache.conan_conf_path) assert "config_install_interval = 5m" in conf dirs = os.listdir(client.cache.cache_folder) assert ".git" not in dirs
class PythonDiamondTest(unittest.TestCase): def setUp(self): self.client = TestClient() def _export_upload(self, name, version=None, deps=None): files = py_hello_conan_files(name, version, deps) self.client.save(files, clean_first=True) self.client.run("export . lasote/stable") def test_reuse(self): self._export_upload("Hello0", "0.1") self._export_upload("Hello1", "0.1", ["Hello0/0.1@lasote/stable"]) self._export_upload("Hello2", "0.1", ["Hello0/0.1@lasote/stable"]) self._export_upload("Hello3", "0.1", ["Hello1/0.1@lasote/stable", "Hello2/0.1@lasote/stable"]) files3 = py_hello_conan_files("Hello4", "0.1", ["Hello3/0.1@lasote/stable"]) self.client.save(files3, clean_first=True) self.client.run("install .") self.assertIn("Hello1/0.1@lasote/stable: Build stuff Hello0", self.client.out) self.assertIn("Hello2/0.1@lasote/stable: Build stuff Hello0", self.client.out) self.assertIn(" ".join(["Hello3/0.1@lasote/stable: Build stuff Hello1", "Hello3/0.1@lasote/stable: Build stuff Hello0", "Hello3/0.1@lasote/stable: Build stuff Hello2", "Hello3/0.1@lasote/stable: Build stuff Hello0"]), " ".join(str(self.client.out).splitlines())) self.assertNotIn("Project: Build stuff Hello3", self.client.out) self.client.run("build .") self.assertIn("conanfile.py (Hello4/0.1): Build stuff Hello3", self.client.out) if platform.system() == "Windows": command = "activate && python main.py" else: command = 'bash -c "source activate.sh && python main.py"' self.client.run_command(command) self.assertEqual(['Hello Hello4', 'Hello Hello3', 'Hello Hello1', 'Hello Hello0', 'Hello Hello2', 'Hello Hello0'], str(self.client.out).splitlines()[-6:])
def test_xcodedeps_dashes_names_and_arch(): # https://github.com/conan-io/conan/issues/9949 client = TestClient(path_with_spaces=False) client.save({ "conanfile.py": GenConanfile().with_name("hello-dashes").with_version("0.1") }) client.run("export .") client.save({"conanfile.txt": "[requires]\nhello-dashes/0.1\n"}, clean_first=True) main = "int main(int argc, char *argv[]) { return 0; }" create_xcode_project(client, "app", main) client.run("install . -s arch=armv8 --build=missing -g XcodeDeps") assert os.path.exists( os.path.join(client.current_folder, "conan_hello_dashes_vars_release_arm64.xcconfig")) client.run_command( "xcodebuild -project app.xcodeproj -xcconfig conandeps.xcconfig -arch arm64" )
def test_export_scm_to_conandata(self): # Check the shallow value is stored and propagated with the proper value client = TestClient() client.run("config set general.scm_to_conandata=1") files = {'conanfile.py': self.conanfile.format(shallow_attrib=self._shallow_attrib_str(), url='auto', rev='auto')} url, _ = create_local_git_repo(files=files) client.run_command('git clone "{}" .'.format(url)) client.run("export . {}".format(self.ref)) content = load(os.path.join(client.cache.package_layout(self.ref).export(), DATA_YML)) if self.shallow in [None, True]: self.assertNotIn('shallow', content) elif self.shallow in ['None']: self.assertIn('shallow: null', content) else: self.assertIn('shallow: false', content) self._check_info_values(client)
def test_toolchain_win_multi(self): client = TestClient(path_with_spaces=False) settings = {"compiler": "Visual Studio", "compiler.version": "15", "compiler.cppstd": "17"} settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items() if v) client.run("new hello/0.1 -s") configs = [("Release", "x86"), ("Release", "x86_64"), ("Debug", "x86"), ("Debug", "x86_64")] for build_type, arch in configs: # Build the profile according to the settings provided runtime = "MT" if build_type == "Release" else "MTd" client.run("create . hello/0.1@ %s -s build_type=%s -s arch=%s -s compiler.runtime=%s" % (settings, build_type, arch, runtime)) # Prepare the actual consumer package client.save({"conanfile.py": self.conanfile, "MyProject.sln": sln_file, "MyApp/MyApp.vcxproj": myapp_vcxproj, "MyApp/MyApp.cpp": self.app}, clean_first=True) # Run the configure corresponding to this test case for build_type, arch in configs: runtime = "MT" if build_type == "Release" else "MTd" client.run("install . %s -s build_type=%s -s arch=%s -s compiler.runtime=%s -if=conan" % (settings, build_type, arch, runtime)) vs_path = vs_installation_path("15") vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat") for build_type, arch in configs: platform_arch = "x86" if arch == "x86" else "x64" cmd = ('set "VSCMD_START_DIR=%%CD%%" && ' '"%s" x64 && msbuild "MyProject.sln" /p:Configuration=%s ' '/p:Platform=%s ' % (vcvars_path, build_type, platform_arch)) client.run_command(cmd) self.assertIn("Visual Studio 2017", client.out) self.assertIn("[vcvarsall.bat] Environment initialized for: 'x64'", client.out) self._run_app(client, arch, build_type) version = re.search("main _MSC_VER19([0-9]*)", str(client.out)).group(1) version = int(version) self.assertTrue(10 <= version < 20) self.assertIn("main _MSVC_LANG2017", client.out)
def test_cmaketoolchain_path_find_program(settings, find_root_path_modes): """Test that executables in bindirs of build_requires can be found with find_program() in consumer CMakeLists. """ client = TestClient() conanfile = textwrap.dedent(""" from conans import ConanFile class TestConan(ConanFile): settings = "os", "arch", "compiler", "build_type" exports_sources = "*" def layout(self): pass def package(self): self.copy(pattern="*", dst="bin") """) client.save({"conanfile.py": conanfile, "hello": "", "hello.exe": ""}) client.run("create . hello_host/0.1@ -pr:b default {}".format(settings)) client.run("create . hello_build/0.1@") conanfile = textwrap.dedent(""" from conans import ConanFile class PkgConan(ConanFile): settings = "os", "arch", "compiler", "build_type" requires = "hello_host/0.1" build_requires = "hello_build/0.1" """) consumer = textwrap.dedent(""" cmake_minimum_required(VERSION 3.15) project(MyHello) find_program(HELLOPROG hello) if(HELLOPROG) message("Found hello prog: ${HELLOPROG}") endif() """) client.save({"conanfile.py": conanfile, "CMakeLists.txt": consumer}, clean_first=True) client.run("install . pkg/0.1@ -g CMakeToolchain -pr:b default {}".format(settings)) with client.chdir("build"): client.run_command(_cmake_command_toolchain(find_root_path_modes)) assert "Found hello prog" in client.out assert "hello_host/0.1/" not in client.out assert "hello_build/0.1/" in client.out
def test_xcodedeps_build_configurations(): client = TestClient(path_with_spaces=False) client.run("new hello/0.1 -m=cmake_lib") client.run("export .") client.run("new bye/0.1 -m=cmake_lib") client.run("export .") main = textwrap.dedent(""" #include <iostream> #include "hello.h" #include "bye.h" int main(int argc, char *argv[]) { hello(); bye(); #ifndef DEBUG std::cout << "App Release!" << std::endl; #else std::cout << "App Debug!" << std::endl; #endif } """) project_name = "app" client.save({"conanfile.txt": "[requires]\nhello/0.1\nbye/0.1\n"}, clean_first=True) create_xcode_project(client, project_name, main) for config in ["Release", "Debug"]: client.run( "install . -s build_type={} -s arch=x86_64 --build=missing -g XcodeDeps" .format(config)) for config in ["Release", "Debug"]: client.run_command( "xcodebuild -project {}.xcodeproj -xcconfig conandeps.xcconfig " "-configuration {} -arch x86_64".format(project_name, config)) client.run_command("./build/{}/{}".format(config, project_name)) assert "App {}!".format(config) in client.out assert "hello/0.1: Hello World {}!".format(config).format( config) in client.out
def test_toolchain_win(self): client = TestClient(path_with_spaces=False) settings = {"compiler": "Visual Studio", "compiler.version": "15", "compiler.cppstd": "17", "compiler.runtime": "MT", "build_type": "Release", "arch": "x86"} # Build the profile according to the settings provided settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items() if v) client.run("new hello/0.1 -s") client.run("create . hello/0.1@ %s" % (settings, )) # Prepare the actual consumer package client.save({"conanfile.py": self.conanfile, "MyProject.sln": sln_file, "MyApp/MyApp.vcxproj": myapp_vcxproj, "MyApp/MyApp.cpp": self.app}, clean_first=True) # Run the configure corresponding to this test case client.run("install . %s -if=conan" % (settings, )) self.assertIn("conanfile.py: MSBuildToolchain created conantoolchain_release_win32.props", client.out) client.run("build . -if=conan") self.assertIn("Visual Studio 2017", client.out) self.assertIn("[vcvarsall.bat] Environment initialized for: 'x86'", client.out) self._run_app(client, "x86", "Release") version = re.search("main _MSC_VER19([0-9]*)", str(client.out)).group(1) version = int(version) self.assertTrue(10 <= version < 20) self.assertIn("main _MSVC_LANG2017", client.out) vcvars = vcvars_command(version="15", architecture="x86") cmd = ('%s && dumpbin /dependents "Release\\MyApp.exe"' % vcvars) client.run_command(cmd) # No other DLLs dependencies rather than kernel, it was MT, statically linked self.assertIn("KERNEL32.dll", client.out) self.assertEqual(1, str(client.out).count(".dll"))
def test_transitive_targets_flags(self): client = TestClient() client.save({"conanfile.py": conanfile_py}) client.run("export . lasote/testing") client.save({"conanfile.py": chatconanfile_py}, clean_first=True) client.run("export . lasote/testing") cmake_targets = cmake.replace( "conan_basic_setup()", "conan_basic_setup(TARGETS)\n" "get_target_property(HELLO_FLAGS CONAN_PKG::Hello" " INTERFACE_COMPILE_OPTIONS)\n" "get_target_property(CHAT_FLAGS CONAN_PKG::Chat" " INTERFACE_COMPILE_OPTIONS)\n" "get_target_property(HELLO_DEFINES CONAN_PKG::Hello" " INTERFACE_COMPILE_DEFINITIONS)") client.save( { "conanfile.txt": conanfile.replace("Hello", "Chat"), "CMakeLists.txt": cmake_targets }, clean_first=True) client.run('install . -g cmake') generator = '-G "Visual Studio 15 Win64"' if platform.system( ) == "Windows" else "" client.run_command("cmake . %s" % generator) cmake_cxx_flags = self._get_line(client.out, "CMAKE_CXX_FLAGS") self.assertNotIn("My", cmake_cxx_flags) self.assertIn( "CONAN_CXX_FLAGS=MyFlag1 MyFlag2 MyChatFlag1 MyChatFlag2", client.out) self.assertIn( "HELLO_CXX_FLAGS=-load;C:\some\path;MyFlag1;MyFlag2;" "$<$<CONFIG:Release>:;>;$<$<CONFIG:RelWithDebInfo>:;>;" "$<$<CONFIG:MinSizeRel>:;>;$<$<CONFIG:Debug>:;>", client.out) self.assertIn( "CHAT_CXX_FLAGS=MyChatFlag1;MyChatFlag2;" "$<$<CONFIG:Release>:;>;$<$<CONFIG:RelWithDebInfo>:;>;" "$<$<CONFIG:MinSizeRel>:;>;$<$<CONFIG:Debug>:;>", client.out) self.assertIn( 'HELLO_DEFINES=MY_DEF=My" \string;MY_DEF2=My${} other \string;', client.out)
def test_cmake_multi(self): client = TestClient() deps = None for name in ["Hello0", "Hello1", "Hello2"]: files = multi_config_files(name, test=False, deps=deps) client.save(files, clean_first=True) deps = [name] if name != "Hello2": client.run("export . lasote/stable") client.run('install . --build missing') client.run("build .") cmd = os.sep.join([".", "bin", "say_hello"]) client.run_command(cmd) self.assertIn("Hello Release Hello2 Hello Release Hello1 Hello Release Hello0", " ".join(str(client.out).splitlines())) client.run_command(cmd + "_d") self.assertIn("Hello Debug Hello2 Hello Debug Hello1 Hello Debug Hello0", " ".join(str(client.out).splitlines()))
def test_auto_tag(self): t = TestClient() ref = ConanFileReference.loads("lib/version@issue/testing") # Clone the tag to local folder url = os.path.join(self.project_url, "tags/release-1.0/level1").replace('\\', '/') t.run_command('svn co "{url}" "{path}"'.format(url=url, path=t.current_folder)) # Export the recipe (be sure sources are retrieved from the repository) t.run("export . {ref}".format(ref=ref)) package_layout = t.cache.package_layout(ref) exported_conanfile = load(package_layout.conanfile()) self.assertNotIn("auto", exported_conanfile) self.assertIn('"revision": "3",', exported_conanfile) self.assertIn('tags/release-1.0/level1@3', exported_conanfile) os.remove(package_layout.scm_folder()) # Just in case, avoid scm_folder optimization # Compile (it will clone the repo) t.run("install {ref} --build=lib".format(ref=ref)) self.assertIn("lib/version@issue/testing: Getting sources from url:", t.out)
def test_use_build_virtualenv_windows(self): files = cpp_hello_conan_files("hello", "0.1", use_cmake=False, with_exe=False) client = TestClient(path_with_spaces=False) client.save(files) client.run("create . user/testing") files = cpp_hello_conan_files("hello2", "0.1", deps=["hello/0.1@user/testing"], use_cmake=False, with_exe=False) client.save(files, clean_first=True) client.run("create . user/testing") reuse_conanfile = dedent(''' from conans import ConanFile class ConanReuseLib(ConanFile): requires = "hello2/0.1@user/testing" generators = "virtualbuildenv" settings = "os", "compiler", "build_type", "arch" def build(self): self.run('activate_build.bat && cl /c /EHsc hello.cpp') self.run('activate_build.bat && lib hello.obj -OUT:helloapp.lib') self.run('activate_build.bat && cl /EHsc main.cpp helloapp.lib') ''') reuse = cpp_hello_conan_files("app", "0.1", deps=["hello2/0.1@user/testing"], use_cmake=False) reuse["conanfile.py"] = reuse_conanfile client.save(reuse, clean_first=True) client.run("install .") client.run("build .") client.run_command("main.exe") self.assertIn("Hello app;Hello hello2;Hello hello", ";".join(str(client.out).splitlines()))
def test_makefile_arch(config): arch, os_, os_version = config profile = textwrap.dedent(""" include(default) [settings] os = {os} os.version = {os_version} arch = {arch} """).format(os=os_, arch=arch, os_version=os_version) t = TestClient() hello_h = gen_function_h(name="hello") hello_cpp = gen_function_cpp(name="hello") main_cpp = gen_function_cpp(name="main", includes=["hello"], calls=["hello"]) t.save({ "Makefile": makefile, "hello.h": hello_h, "hello.cpp": hello_cpp, "app.cpp": main_cpp, "conanfile.py": conanfile_py, "profile": profile }) t.run("install . --profile:host=profile --profile:build=default") t.run("build .") libhello = os.path.join(t.current_folder, "libhello.a") app = os.path.join(t.current_folder, "app") assert os.path.isfile(libhello) assert os.path.isfile(app) expected_arch = to_apple_arch(arch) t.run_command('lipo -info "%s"' % libhello) assert "architecture: %s" % expected_arch in t.out t.run_command('lipo -info "%s"' % app) assert "architecture: %s" % expected_arch in t.out