def test_autotools_bash_complete(): client = TestClient(path_with_spaces=False) bash_path = tools_locations["msys2"]["system"]["path"][ "Windows"] + "/bash.exe" save( client.cache.new_config_path, textwrap.dedent(""" tools.microsoft.bash:subsystem=msys2 tools.microsoft.bash:path={} """.format(bash_path))) main = gen_function_cpp(name="main") # The autotools support for "cl" compiler (VS) is very limited, linking with deps doesn't # work but building a simple app do makefile_am = gen_makefile_am(main="main", main_srcs="main.cpp") configure_ac = gen_configure_ac() conanfile = textwrap.dedent(""" from conans import ConanFile from conan.tools.gnu import Autotools from conan.tools.env import Environment class TestConan(ConanFile): settings = "os", "compiler", "arch", "build_type" exports_sources = "configure.ac", "Makefile.am", "main.cpp" generators = "AutotoolsToolchain" win_bash = True def build(self): # These commands will run in bash activating first the vcvars and # then inside the bash activating the self.run("aclocal") self.run("autoconf") self.run("automake --add-missing --foreign") autotools = Autotools(self) autotools.configure() autotools.make() """) client.save({ "conanfile.py": conanfile, "configure.ac": configure_ac, "Makefile.am": makefile_am, "main.cpp": main }) client.run("install . -s:b os=Windows -s:h os=Windows") client.run("build .") client.run_command("main.exe") check_exe_run(client.out, "main", "msvc", None, "Release", "x86_64", None) bat_contents = client.load("conanbuild.bat") assert "conanvcvars.bat" in bat_contents
def test_autotools(): client = TestClient(path_with_spaces=False) client.run("new hello/0.1 --template=cmake_lib") client.run("create .") main = gen_function_cpp(name="main", includes=["hello"], calls=["hello"]) makefile_am = gen_makefile_am(main="main", main_srcs="main.cpp") configure_ac = gen_configure_ac() conanfile = textwrap.dedent(""" from conans import ConanFile from conan.tools.gnu import Autotools class TestConan(ConanFile): requires = "hello/0.1" settings = "os", "compiler", "arch", "build_type" exports_sources = "configure.ac", "Makefile.am", "main.cpp" generators = "AutotoolsDeps", "AutotoolsToolchain" def build(self): self.run("aclocal") self.run("autoconf") self.run("automake --add-missing --foreign") autotools = Autotools(self) autotools.configure() autotools.make() """) client.save( { "conanfile.py": conanfile, "configure.ac": configure_ac, "Makefile.am": makefile_am, "main.cpp": main }, clean_first=True) client.run("install .") client.run("build .") client.run_command("./main") cxx11_abi = 0 if platform.system() == "Linux" else None check_exe_run(client.out, "main", "gcc", None, "Release", "x86_64", None, cxx11_abi=cxx11_abi) assert "hello/0.1: Hello World Release!" in client.out
def test_install_output_directories(): """ If we change the libdirs of the cpp.package, as we are doing cmake.install, the output directory for the libraries is changed """ client = TurboTestClient(path_with_spaces=False) client.run("new hello/1.0 --template cmake_lib") client.run("create .") consumer_conanfile = textwrap.dedent(""" from conan import ConanFile from conan.tools.gnu import Autotools class TestConan(ConanFile): requires = "hello/1.0" settings = "os", "compiler", "arch", "build_type" exports_sources = "configure.ac", "Makefile.am", "main.cpp", "consumer.h" generators = "AutotoolsDeps", "AutotoolsToolchain" def layout(self): self.folders.build = "." self.cpp.package.bindirs = ["mybin"] def build(self): self.run("aclocal") self.run("autoconf") self.run("automake --add-missing --foreign") autotools = Autotools(self) autotools.configure() autotools.make() autotools.install() """) main = gen_function_cpp(name="main", includes=["hello"], calls=["hello"]) makefile_am = gen_makefile_am(main="main", main_srcs="main.cpp") configure_ac = gen_configure_ac() client.save( { "conanfile.py": consumer_conanfile, "configure.ac": configure_ac, "Makefile.am": makefile_am, "main.cpp": main }, clean_first=True) ref = ConanFileReference.loads("zlib/1.2.11") pref = client.create(ref, conanfile=consumer_conanfile) p_folder = client.cache.package_layout(pref.ref).package(pref) assert os.path.exists(os.path.join(p_folder, "mybin", "main")) assert not os.path.exists(os.path.join(p_folder, "bin"))
def test_use_build_virtualenv(self): client = TestClient(path_with_spaces=False) client.save({ CONANFILE: conanfile, "mean.cpp": mylib, "mean.h": mylibh }) client.run("export . lasote/stable") makefile_am = gen_makefile_am(main="main", main_srcs="main.cpp") configure_ac = gen_configure_ac() reuse_conanfile = textwrap.dedent(''' import platform from conans import ConanFile class ConanReuseLib(ConanFile): requires = "Mean/0.1@lasote/stable" generators = "virtualbuildenv" settings = "os", "compiler", "build_type", "arch" exports_sources = "*" def build(self): self.run("aclocal") self.run("autoconf") self.run("automake --add-missing --foreign") self.run("ls") self.run("bash -c 'source activate_build.sh && ./configure'") self.run("bash -c 'source activate_build.sh && make'") self.run("./main") ''') client.save({ CONANFILE: reuse_conanfile, "Makefile.am": makefile_am, "configure.ac": configure_ac, "main.cpp": example }) client.run("install . --build missing") client.run("build .") self.assertIn("15", client.out)
def test_ios(): xcrun = XCRun(None, sdk='iphoneos') cflags = "" cflags += " -isysroot " + xcrun.sdk_path cflags += " -arch " + to_apple_arch('armv8') cxxflags = cflags ldflags = cflags profile = textwrap.dedent(""" include(default) [settings] os=iOS os.version=12.0 arch=armv8 [env] CC={cc} CXX={cxx} CFLAGS={cflags} CXXFLAGS={cxxflags} LDFLAGS={ldflags} """).format(cc=xcrun.cc, cxx=xcrun.cxx, cflags=cflags, cxxflags=cxxflags, ldflags=ldflags) client = TestClient(path_with_spaces=False) client.save({"m1": profile}, clean_first=True) client.run("new hello/0.1 --template=v2_cmake") client.run("create . --profile:build=default --profile:host=m1 -tf None") main = gen_function_cpp(name="main", includes=["hello"], calls=["hello"]) makefile_am = gen_makefile_am(main="main", main_srcs="main.cpp") configure_ac = gen_configure_ac() conanfile = textwrap.dedent(""" from conans import ConanFile from conan.tools.gnu import Autotools class TestConan(ConanFile): requires = "hello/0.1" settings = "os", "compiler", "arch", "build_type" exports_sources = "configure.ac", "Makefile.am", "main.cpp" generators = "AutotoolsGen" def build(self): self.run("aclocal") self.run("autoconf") self.run("automake --add-missing --foreign") autotools = Autotools(self) autotools.configure() autotools.make() """) client.save({"conanfile.py": conanfile, "configure.ac": configure_ac, "Makefile.am": makefile_am, "main.cpp": main, "m1": profile}, clean_first=True) client.run("install . --profile:build=default --profile:host=m1") client.run("build .") client.run_command("./main", assert_error=True) assert "Bad CPU type in executable" in client.out client.run_command("lipo -info main") assert "Non-fat file: main is architecture: arm64" in client.out js = client.load("conanbuild.json") assert '"build": "x86_64-apple-darwin"' in js assert '"host": "aarch64-apple-ios"' in js
def test_autotools_real_install_dirs(self): body = gen_function_cpp(name="hello", msg="Hola Mundo!") header = gen_function_h(name="hello") main = gen_function_cpp(name="main", includes=["hello"], calls=["hello"]) makefile_am = gen_makefile_am(main="main", main_srcs="main.cpp", lib="libhello.a", lib_srcs="hello.cpp") configure_ac = gen_configure_ac() conanfile = textwrap.dedent(""" from conans import ConanFile, AutoToolsBuildEnvironment class TestConan(ConanFile): name = "test" version = "1.0" settings = "os", "compiler", "arch", "build_type" exports_sources = "*" def build(self): self.run("aclocal") self.run("autoconf") self.run("automake --add-missing --foreign") autotools = AutoToolsBuildEnvironment(self) autotools.configure() autotools.make() autotools.install() def package_id(self): # easier to have same package_id for the test self.info.header_only() """) client = TestClient() client.save({ "conanfile.py": conanfile, "configure.ac": configure_ac, "Makefile.am": makefile_am, "main.cpp": main, "hello.h": header, "hello.cpp": body }) client.run("create . danimtb/testing") pref = PackageReference.loads("test/1.0@danimtb/testing:%s" % NO_SETTINGS_PACKAGE_ID) pkg_path = client.cache.package_layout(pref.ref).package(pref) [ self.assertIn(folder, os.listdir(pkg_path)) for folder in ["lib", "bin"] ] new_conanfile = conanfile.replace( "autotools.configure()", "autotools.configure(args=['--bindir=${prefix}/superbindir', '--libdir=${prefix}/superlibdir'])" ) client.save({"conanfile.py": new_conanfile}) client.run("create . danimtb/testing") [ self.assertIn(folder, os.listdir(pkg_path)) for folder in ["superlibdir", "superbindir"] ] [ self.assertNotIn(folder, os.listdir(pkg_path)) for folder in ["lib", "bin"] ]
def test_ios(): xcrun = XCRun(None, sdk='iphoneos') cflags = "" cflags += " -isysroot " + xcrun.sdk_path cflags += " -arch " + to_apple_arch('armv8') cxxflags = cflags ldflags = cflags profile = textwrap.dedent(""" include(default) [settings] os=iOS os.sdk=iphoneos os.version=12.0 arch=armv8 [env] CC={cc} CXX={cxx} CFLAGS={cflags} CXXFLAGS={cxxflags} LDFLAGS={ldflags} """).format(cc=xcrun.cc, cxx=xcrun.cxx, cflags=cflags, cxxflags=cxxflags, ldflags=ldflags) 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"]) makefile_am = gen_makefile_am(main="main", main_srcs="main.cpp") configure_ac = gen_configure_ac() conanfile = textwrap.dedent(""" from conans import ConanFile from conan.tools.gnu import Autotools class TestConan(ConanFile): requires = "hello/0.1" settings = "os", "compiler", "arch", "build_type" exports_sources = "configure.ac", "Makefile.am", "main.cpp" generators = "AutotoolsToolchain", "AutotoolsDeps" def build(self): autotools = Autotools(self) autotools.autoreconf() autotools.configure() autotools.make() """) client.save( { "conanfile.py": conanfile, "configure.ac": configure_ac, "Makefile.am": makefile_am, "main.cpp": main, "m1": profile }, clean_first=True) client.run("install . --profile:build=default --profile:host=m1") client.run("build .") client.run_command("./main", assert_error=True) assert "Bad CPU type in executable" in client.out client.run_command("lipo -info main") assert "Non-fat file: main is architecture: arm64" in client.out conanbuild = load_toolchain_args(client.current_folder) configure_args = conanbuild["configure_args"] make_args = conanbuild["make_args"] autoreconf_args = conanbuild["autoreconf_args"] assert configure_args == "'--prefix=/' '--bindir=${prefix}/bin' '--sbindir=${prefix}/bin' " \ "'--libdir=${prefix}/lib' '--includedir=${prefix}/include' " \ "'--oldincludedir=${prefix}/include' '--datarootdir=${prefix}/res' " \ "'--host=aarch64-apple-ios' '--build=x86_64-apple-darwin'" assert make_args == "" assert autoreconf_args == "'--force' '--install'"