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 VirtualRunEnv" ) conanfile = ConanFileMock() command = environment_wrap_command(conanfile, "conanrun", "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_msbuild_generator(self): client = TestClient() client.save(pkg_cmake("Hello0", "1.0")) client.run("create . ") client.save(pkg_cmake("Hello3", "1.0"), clean_first=True) client.run("create . ") client.save(pkg_cmake("Hello1", "1.0", ["Hello0/1.0"]), 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=["Hello1"], calls=["Hello1"]) myproject_cpp = gen_function_cpp(name="main", msg="MyProject", includes=["Hello3"], calls=["Hello3"]) 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("Hello3: Release!", client.out) client.run_command(r"x64\Release\MyApp.exe") self.assertIn("MyApp: Release!", client.out) self.assertIn("Hello0: Release!", client.out) self.assertIn("Hello1: Release!", client.out)
def test_shared_cmake_toolchain_test_package(): client = TestClient() files = pkg_cmake("hello", "0.1") files.update(pkg_cmake_test("hello")) client.save(files) client.run("create . -o hello:shared=True") assert "hello: Release!" in client.out
def editable_cmake(generator, build_folder=None): c = TestClient() if generator is not None: c.save( { "global.conf": "tools.cmake.cmaketoolchain:generator={}".format(generator) }, path=os.path.join(c.cache.cache_folder)) c.save(pkg_cmake("dep", "0.1"), path=os.path.join(c.current_folder, "dep")) c.save(pkg_cmake_app("pkg", "0.1", requires=["dep/0.1"]), path=os.path.join(c.current_folder, "pkg")) output_folder = '--output-folder="{}"'.format( build_folder) if build_folder else "" build_folder = '--build-folder="{}"'.format( build_folder) if build_folder else "" def build_dep(): c.run("install . -if=install_release {}".format(output_folder)) c.run("build . -if=install_release {}".format(build_folder)) c.run("install . -s build_type=Debug -if=install_debug {}".format( output_folder)) c.run("build . -if=install_debug {}".format(build_folder)) with c.chdir("dep"): c.run("editable add . dep/0.1@ {}".format(output_folder)) build_dep() def build_pkg(msg): c.run("build . -if=install_release") folder = os.path.join("build", "Release") c.run_command(os.sep.join([".", folder, "pkg"])) assert "main: Release!" in c.out assert "{}: Release!".format(msg) in c.out c.run("build . -if=install_debug") folder = os.path.join("build", "Debug") c.run_command(os.sep.join([".", folder, "pkg"])) assert "main: Debug!" in c.out assert "{}: Debug!".format(msg) in c.out with c.chdir("pkg"): c.run("install . -if=install_release") c.run("install . -if=install_debug -s build_type=Debug") build_pkg("dep") # Do a source change in the editable! with c.chdir("dep"): c.save({"src/dep.cpp": gen_function_cpp(name="dep", msg="SUPERDEP")}) build_dep() with c.chdir("pkg"): build_pkg("SUPERDEP") # Check that create is still possible c.run("editable remove dep/0.1@") c.run("create dep") c.run("create pkg") # print(c.out) assert "pkg/0.1: Created package" in c.out
def test_intel_oneapi_and_dpcpp(self): self.client = TestClient() # Let's create a default hello/0.1 example files = pkg_cmake("hello", "0.1") self.client.save(files) intel_profile = textwrap.dedent(""" [settings] os=Linux arch=x86_64 arch_build=x86_64 compiler=intel-cc compiler.mode=dpcpp compiler.version=2021.3 compiler.libcxx=libstdc++ build_type=Release [env] CC=dpcpp CXX=dpcpp """) self.client.save({"intel_profile": intel_profile}) # Build in the cache self.client.run('create . --profile:build=intel_profile --profile:host=intel_profile') assert ":: initializing oneAPI environment ..." in self.client.out assert ":: oneAPI environment initialized ::" in self.client.out assert "Check for working CXX compiler: /opt/intel/oneapi/compiler/2021.3.0" \ "/linux/bin/dpcpp -- works" in self.client.out assert "hello/0.1: Package " \ "'5d42bcd2e9be3378ed0c2f2928fe6dc9ea1b0922' created" in self.client.out
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 editable_cmake(generator): multi = (generator is None and platform.system() == "Windows") or \ generator in ("Ninja Multi-Config", "Xcode") c = TestClient() if generator is not None: c.save( { "global.conf": "tools.cmake.cmaketoolchain:generator={}".format(generator) }, path=os.path.join(c.cache.cache_folder)) c.save(pkg_cmake("dep", "0.1"), path=os.path.join(c.current_folder, "dep")) c.save(pkg_cmake_app("pkg", "0.1", requires=["dep/0.1"]), path=os.path.join(c.current_folder, "pkg")) with c.chdir("dep"): c.run("editable add . dep/0.1@") c.run("install .") c.run("build .") c.run("install . -s build_type=Debug") c.run("build .") def build_pkg(msg): c.run("build . -if=install_release") folder = os.path.join("build", "Release") if multi else "cmake-build-release" c.run_command(os.sep.join([".", folder, "pkg"])) assert "main: Release!" in c.out assert "{}: Release!".format(msg) in c.out c.run("build . -if=install_debug") folder = os.path.join("build", "Debug") if multi else "cmake-build-debug" c.run_command(os.sep.join([".", folder, "pkg"])) assert "main: Debug!" in c.out assert "{}: Debug!".format(msg) in c.out with c.chdir("pkg"): c.run("install . -if=install_release") c.run("install . -if=install_debug -s build_type=Debug") build_pkg("dep") # Do a source change in the editable! with c.chdir("dep"): c.save({"src/dep.cpp": gen_function_cpp(name="dep", msg="SUPERDEP")}) c.run("install .") c.run("build .") c.run("install . -s build_type=Debug") c.run("build .") with c.chdir("pkg"): build_pkg("SUPERDEP") # Check that create is still possible c.run("editable remove dep/0.1@") c.run("create dep") c.run("create pkg") # print(c.out) assert "pkg/0.1: Created package" in c.out
def editable_cmake_exe(generator): # This test works because it is not multi-config or single config, but explicit in # --install folder c = TestClient() if generator is not None: c.save( { "global.conf": "tools.cmake.cmaketoolchain:generator={}".format(generator) }, path=os.path.join(c.cache.cache_folder)) c.save(pkg_cmake("dep", "0.1", exe=True), path=os.path.join(c.current_folder, "dep")) def build_dep(): c.run("install . -o dep:shared=True -if=install_release") c.run("build . -if=install_release") c.run( "install . -s build_type=Debug -o dep:shared=True -if=install_debug" ) c.run("build . -if=install_debug") with c.chdir("dep"): c.run("editable add . dep/0.1@") build_dep() def run_pkg(msg): # FIXME: This only works with ``--install-folder``, layout() will break this cmd_release = environment_wrap_command( "conanrunenv-release-x86_64", c.current_folder, "dep_app", ) c.run_command(cmd_release) assert "{}: Release!".format(msg) in c.out cmd_release = environment_wrap_command( "conanrunenv-debug-x86_64", c.current_folder, "dep_app", ) c.run_command(cmd_release) assert "{}: Debug!".format(msg) in c.out with c.chdir("pkg"): c.run("install dep/0.1@ -o dep:shared=True -g VirtualRunEnv") c.run( "install dep/0.1@ -o dep:shared=True -s build_type=Debug -g VirtualRunEnv" ) run_pkg("dep") # Do a source change in the editable! with c.chdir("dep"): c.save({"src/dep.cpp": gen_function_cpp(name="dep", msg="SUPERDEP")}) build_dep() with c.chdir("pkg"): run_pkg("SUPERDEP")
def test_start_dir_failure(): c = TestClient() c.save(pkg_cmake("dep", "0.1")) c.run("install .") expected_path = os.path.join(c.current_folder, "build", "generators", "conan_toolchain.cmake") assert os.path.exists(expected_path) os.unlink(expected_path) with c.chdir("build"): c.run("install ..") assert os.path.exists(expected_path)
def test_start_dir_failure(): c = TestClient() c.save(pkg_cmake("dep", "0.1")) c.run("install .") build = "build" if platform.system( ) == "Windows" else "cmake-build-release" expected_path = os.path.join(c.current_folder, build, "conan", "conan_toolchain.cmake") assert os.path.exists(expected_path) os.unlink(expected_path) with c.chdir("build"): c.run("install ..") assert os.path.exists(expected_path)
def test_cmake_find_package_multi(client_weird_lib_name): c = client_weird_lib_name files = pkg_cmake("chat", "0.1", requires=["hello/0.1"]) conanfile = textwrap.dedent(""" import os, platform from conans import ConanFile, CMake class Pkg(ConanFile): exports_sources = "CMakeLists.txt", "src/*", "include/*" settings = "os", "compiler", "arch", "build_type" generators = "cmake_find_package_multi" requires = "hello/0.1" def build(self): cmake = CMake(self) cmake.configure() cmake.build() """) files["conanfile.py"] = conanfile c.save(files, clean_first=True) c.run("create . chat/0.1@") assert "chat/0.1: Created package" in c.out
def test_cmakedeps(client_weird_lib_name): c = client_weird_lib_name c.save(pkg_cmake("chat", "0.1", requires=["hello/0.1"]), clean_first=True) c.run("create . chat/0.1@") assert "chat/0.1: Created package" in c.out