def test_apple_arch_flag(): conanfile = ConanFileMock() conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"} conanfile.settings_build = MockSettings({ "build_type": "Debug", "os": "Macos", "arch": "x86_64" }) conanfile.settings = MockSettings({ "build_type": "Debug", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) expected = "-arch arm64" assert be.apple_arch_flag == expected env = be.vars() assert expected in env["CXXFLAGS"] assert expected in env["CFLAGS"] assert expected in env["LDFLAGS"] # Only set when crossbuilding conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Debug", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) assert be.apple_arch_flag is None
def test_apple_isysrootflag(): """Even when no cross building it is adjusted because it could target a Mac version""" conanfile = ConanFileMock() conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"} conanfile.settings_build = MockSettings({ "build_type": "Debug", "os": "Macos", "arch": "x86_64" }) conanfile.settings = MockSettings({ "build_type": "Debug", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) expected = "-isysroot /path/to/sdk" assert be.apple_isysroot_flag == expected env = be.vars() assert expected in env["CXXFLAGS"] assert expected in env["CFLAGS"] assert expected in env["LDFLAGS"] # Only set when crossbuilding conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Debug", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) assert be.apple_isysroot_flag is None
class AutotoolsGen: def __init__(self, conanfile): self.toolchain = AutotoolsToolchain(conanfile) self.deps = AutotoolsDeps(conanfile) self.env = VirtualEnv(conanfile) def build_environment(self): envtoolchain = self.toolchain.environment() envdeps = self.deps.environment() build_env = self.env.build_environment() build_env.compose(envtoolchain) build_env.compose(envdeps) return build_env def run_environment(self): run_env = self.env.run_environment() return run_env def generate(self): build_env = self.build_environment() run_env = self.run_environment() # FIXME: Use settings, not platform Not always defined :( # os_ = self._conanfile.settings_build.get_safe("os") if platform.system() == "Windows": build_env.save_bat("conanbuildenv.bat") run_env.save_bat("conanrunenv.bat") else: build_env.save_sh("conanbuildenv.sh") run_env.save_sh("conanrunenv.sh") self.toolchain.generate_args()
def generate(self): ad = AutotoolsDeps(self) # this can be removed if conan >= 1.44.0 due to https://github.com/conan-io/conan/pull/10192 for m in re.finditer("-Wl,-rpath,\"[^\"]+\"", ad.vars()["LDFLAGS"]): ad.environment.remove("LDFLAGS", m[0]) ad.generate() ac = AutotoolsToolchain(self) ac.default_configure_install_args = True ac.configure_args.extend( ["--with-system-zlib", "--with-system-readline"]) ac.generate()
def generate(self): td = AutotoolsDeps(self) # remove non-existing frameworks dirs, otherwise clang complains for m in re.finditer("-F (\S+)", td.vars().get("LDFLAGS")): if not os.path.exists(m[1]): td.environment.remove("LDFLAGS", f"-F {m[1]}") if self.settings.os == "Windows": if self._is_msvc: td.environment.append("LIBS", [f"{lib}.lib" for lib in self._windows_system_libs]) else: td.environment.append("LDFLAGS", [f"-l{lib}" for lib in self._windows_system_libs]) td.generate() tc = AutotoolsToolchain(self) tc.default_configure_install_args = True tc.configure_args = ["--disable-install-doc"] if self.options.shared and not self._is_msvc: tc.configure_args.append("--enable-shared") tc.fpic = True if cross_building(self) and is_apple_os(self.settings.os): apple_arch = to_apple_arch(self.settings.arch) if apple_arch: tc.configure_args.append(f"--with-arch={apple_arch}") if self._is_msvc: # this is marked as TODO in https://github.com/conan-io/conan/blob/01f4aecbfe1a49f71f00af8f1b96b9f0174c3aad/conan/tools/gnu/autotoolstoolchain.py#L23 tc.build_type_flags.append(f"-{msvc_runtime_flag(self)}") # https://github.com/conan-io/conan/issues/10338 # remove after conan 1.45 if self.settings.build_type in ["Debug", "RelWithDebInfo"]: tc.ldflags.append("-debug") tc.build_type_flags = [f if f != "-O2" else self._msvc_optflag for f in tc.build_type_flags] tc.generate()
def test_build_type_flag(compiler): """Architecture flag is set in CXXFLAGS, CFLAGS and LDFLAGS""" conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Debug", "os": "Windows", "compiler": compiler, "arch": "x86_64" }) be = AutotoolsToolchain(conanfile) assert be.build_type_flags == ["-Zi", "-Ob0", "-Od"] env = be.vars() assert "-Zi -Ob0 -Od" in env["CXXFLAGS"] assert "-Zi -Ob0 -Od" in env["CFLAGS"] assert "-Zi -Ob0 -Od" not in env["LDFLAGS"]
def test_custom_defines(): conanfile = ConanFileMock() conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"} conanfile.settings = MockSettings({ "build_type": "RelWithDebInfo", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) be.defines = ["MyDefine1", "MyDefine2"] env = be.vars() assert "-DMyDefine1" in env["CPPFLAGS"] assert "-DMyDefine2" in env["CPPFLAGS"] assert "-DNDEBUG" in env["CPPFLAGS"]
def test_libcxx(config): compiler, libcxx, expected_flag = config conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": compiler, "compiler.libcxx": libcxx, "compiler.version": "7.1", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) assert be.libcxx == expected_flag env = be.vars() if expected_flag: assert expected_flag in env["CXXFLAGS"]
def test_architecture_flag(config): """Architecture flag is set in CXXFLAGS, CFLAGS and LDFLAGS""" arch, expected = config conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Release", "os": "Macos", "compiler": "gcc", "arch": arch }) be = AutotoolsToolchain(conanfile) assert be.arch_flag == expected env = be.vars() assert expected in env["CXXFLAGS"] assert expected in env["CFLAGS"] assert expected in env["LDFLAGS"]
def test_apple_min_os_flag(): """Even when no cross building it is adjusted because it could target a Mac version""" conanfile = ConanFileMock() conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"} conanfile.settings = MockSettings({ "build_type": "Debug", "os": "Macos", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) expected = "-mmacosx-version-min=14" assert be.apple_min_version_flag == expected env = be.vars() assert expected in env["CXXFLAGS"] assert expected in env["CFLAGS"] assert expected in env["LDFLAGS"]
def test_target_triple(): f = temp_folder() chdir(f) conanfile = ConanFileMock() conanfile.settings = MockSettings({"os": "Linux", "arch": "x86_64"}) conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"}) conanfile.conf = Conf() conanfile.conf["tools.gnu:make_program"] = "my_make" conanfile.conf["tools.gnu.make:jobs"] = "23" be = AutotoolsToolchain(conanfile) be.make_args = ["foo", "var"] be.generate_args() obj = load_toolchain_args() assert "--host=x86_64-linux-gnu" in obj["configure_args"] assert "--build=i686-solaris" in obj["configure_args"] assert obj["make_args"].replace("'", "") == "foo var"
def test_invalid_target_triple(): conanfile = ConanFileMock() conanfile.settings = MockSettings({"os": "Linux", "arch": "UNKNOWN_ARCH"}) conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"}) with pytest.raises(ConanException) as excinfo: AutotoolsToolchain(conanfile) assert "Unknown 'UNKNOWN_ARCH' machine, Conan doesn't know how " \ "to translate it to the GNU triplet," in str(excinfo)
def test_modify_environment(): """We can alter the environment generated by the toolchain passing the env to the generate""" f = temp_folder() chdir(f) conanfile = ConanFileMock() conanfile.settings = MockSettings({"os": "Linux", "arch": "x86_64"}) conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"}) conanfile.folders.set_base_install(f) be = AutotoolsToolchain(conanfile) env = be.environment() env.define("foo", "var") # We can pass the env to the generate once we adjusted or injected anything be.generate(env) with open("conanautotoolstoolchain.sh") as f: content = f.read() assert "foo" in content
def test_modify_environment(): """We can alter the environment generated by the toolchain passing the env to the generate""" f = temp_folder() chdir(f) conanfile = ConanFileMock() conanfile.settings = MockSettings({"os": "Linux", "arch": "x86_64"}) conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"}) be = AutotoolsToolchain(conanfile) env = be.environment() env.define("foo", "var") # We can pass the env to the generate once we adjusted or injected anything be.generate(env) bat = "conanautotoolstoolchain.{}".format("bat" if platform.system() == "Windows" else "sh") with open(bat) as f: content = f.read() assert "foo" in content
def test_sysrootflag(): """Even when no cross building it is adjusted because it could target a Mac version""" conanfile = ConanFileMock() conanfile.conf.define("tools.build:sysroot", "/path/to/sysroot") conanfile.settings = MockSettings({ "build_type": "Debug", "os": { "Darwin": "Macos" }.get(platform.system(), platform.system()), "arch": "x86_64" }) be = AutotoolsToolchain(conanfile) expected = "--sysroot /path/to/sysroot" assert be.sysroot_flag == expected env = be.vars() assert expected in env["CXXFLAGS"] assert expected in env["CFLAGS"] assert expected in env["LDFLAGS"]
def test_custom_ldflags(): conanfile = ConanFileMock() conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"} conanfile.settings = MockSettings({ "build_type": "RelWithDebInfo", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) be.ldflags = ["MyFlag1", "MyFlag2"] env = be.vars() assert "MyFlag1" in env["LDFLAGS"] assert "MyFlag2" in env["LDFLAGS"] assert "-mios-version-min=14" in env["LDFLAGS"] assert "MyFlag" not in env["CXXFLAGS"] assert "MyFlag" not in env["CFLAGS"]
def test_visual_runtime(runtime): """ Testing AutotoolsToolchain with the msvc compiler adjust the runtime """ # Issue: https://github.com/conan-io/conan/issues/10139 settings = MockSettings({"build_type": "Release", "compiler": "Visual Studio", "compiler.runtime": runtime, "os": "Windows", "arch": "x86_64"}) conanfile = ConanFileMock() conanfile.settings = settings conanfile.settings_build = settings autotoolschain = AutotoolsToolchain(conanfile) expected_flag = "-{}".format(runtime) assert autotoolschain.msvc_runtime_flag == expected_flag env = autotoolschain.environment().vars(conanfile) assert expected_flag in env["CFLAGS"] assert expected_flag in env["CXXFLAGS"]
def test_extra_flags_via_conf(): conanfile = ConanFileMock() conanfile.conf.define("tools.build:cxxflags", ["--flag1", "--flag2"]) conanfile.conf.define("tools.build:cflags", ["--flag3", "--flag4"]) conanfile.conf.define("tools.build:sharedlinkflags", ["--flag5"]) conanfile.conf.define("tools.build:exelinkflags", ["--flag6"]) conanfile.conf.define("tools.build:defines", ["DEF1", "DEF2"]) conanfile.settings = MockSettings({ "build_type": "RelWithDebInfo", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) env = be.vars() assert '-DNDEBUG -DDEF1 -DDEF2' in env["CPPFLAGS"] assert '-mios-version-min=14 --flag1 --flag2' in env["CXXFLAGS"] assert '-mios-version-min=14 --flag3 --flag4' in env["CFLAGS"] assert '-mios-version-min=14 --flag5 --flag6' in env["LDFLAGS"]
def test_cxx11_abi_define(): conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++", "compiler.version": "7.1", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) assert be.gcc_cxx11_abi == "_GLIBCXX_USE_CXX11_ABI=0" env = be.environment() assert "-D_GLIBCXX_USE_CXX11_ABI=0" in env["CPPFLAGS"] conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++11", "compiler.version": "7.1", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.environment() assert be.gcc_cxx11_abi is None assert "-D_GLIBCXX_USE_CXX11_ABI=0" not in env["CPPFLAGS"]
def generate(self): yes_no = lambda v: "yes" if v else "no" tc = AutotoolsToolchain(self) tc.configure_args.append("--with-zstd=%s" % yes_no(self.options.with_zstd)) tc.configure_args.append("--with-xz=%s" % yes_no(self.options.with_xz)) tc.configure_args.append("--with-zlib=%s" % yes_no(self.options.with_zlib)) tc.configure_args.append("--with-openssl=%s" % yes_no(self.options.with_openssl)) tc.configure_args.append("--enable-experimental=%s" % yes_no(self.options.experimental)) tc.configure_args.append("--enable-logging=%s" % yes_no(self.options.logging)) tc.configure_args.append("--enable-debug=%s" % yes_no(self.settings.build_type == "Debug")) tc.configure_args.append("--enable-tools=no") tc.configure_args.append("--enable-manpages=no") tc.configure_args.append("--enable-test-modules=no") tc.configure_args.append("--enable-python=no") tc.configure_args.append("--enable-coverage=no") tc.generate() tc = PkgConfigDeps(self) tc.generate() tc = AutotoolsDeps(self) tc.generate() # inject tools_require env vars in build context ms = VirtualBuildEnv(self) ms.generate(scope="build")
def test_cppstd(): # Using "cppstd" is discarded conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++11", "compiler.version": "7.1", "cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.environment() assert not "-std=c++17" in env["CXXFLAGS"] # Using "compiler.cppstd" works conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++11", "compiler.version": "7.1", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.environment() assert "-std=c++17" in env["CXXFLAGS"] # With visual conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "Visual Studio", "compiler.version": "14", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.environment() assert "/std:c++latest" in env["CXXFLAGS"]
def test_get_gnu_triplet_for_cross_building(): """ Testing AutotoolsToolchain and _get_gnu_triplet() function in case of having os=Windows and cross compiling """ # Issue: https://github.com/conan-io/conan/issues/10139 settings = MockSettings({"build_type": "Release", "compiler": "gcc", "compiler.version": "10.2", "os": "Windows", "arch": "x86_64"}) conanfile = ConanFileMock() conanfile.settings = settings conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"}) autotoolschain = AutotoolsToolchain(conanfile) assert autotoolschain._host == "x86_64-w64-mingw32" assert autotoolschain._build == "i686-solaris"
def test_get_gnu_triplet_for_cross_building_raise_error(): """ Testing AutotoolsToolchain and _get_gnu_triplet() function raises an error in case of having os=Windows, cross compiling and not defined any compiler """ # Issue: https://github.com/conan-io/conan/issues/10139 settings = MockSettings({"build_type": "Release", "os": "Windows", "arch": "x86_64"}) conanfile = ConanFileMock() conanfile.settings = settings conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"}) with pytest.raises(ConanException) as conan_error: AutotoolsToolchain(conanfile) msg = "'compiler' parameter for 'get_gnu_triplet()' is not specified and " \ "needed for os=Windows" assert msg == str(conan_error.value)
def test_ndebug(): conanfile = ConanFileMock() for bt in ['Release', 'RelWithDebInfo', 'MinSizeRel']: conanfile.settings = MockSettings({"build_type": bt}) be = AutotoolsToolchain(conanfile) assert be.ndebug == "NDEBUG" env = be.vars() assert "-DNDEBUG" in env["CPPFLAGS"] for bt in ['Debug', 'DebWithDebInfo']: conanfile.settings = MockSettings({"build_type": bt}) be = AutotoolsToolchain(conanfile) assert be.ndebug is None env = be.vars() assert "-DNDEBUG" not in env["CPPFLAGS"]
def test_fpic(): conanfile = ConanFileMock() conanfile.settings = MockSettings({"os": "Linux"}) conanfile.options = MockOptions({"fPIC": True}) be = AutotoolsToolchain(conanfile) be.vars() assert be.fpic is True assert "-fPIC" in be.cxxflags conanfile.options = MockOptions({"fPIC": False}) be = AutotoolsToolchain(conanfile) be.vars() assert be.fpic is False assert "-fPIC" not in be.cxxflags conanfile.options = MockOptions({"shared": False}) be = AutotoolsToolchain(conanfile) be.vars() assert be.fpic is None assert "-fPIC" not in be.cxxflags
def generate(self): tc = AutotoolsToolchain(self) tc.default_configure_install_args = True tc.generate()
def __init__(self, conanfile): self.toolchain = AutotoolsToolchain(conanfile) self.deps = AutotoolsDeps(conanfile) self.env = VirtualEnv(conanfile)
def test_cxx11_abi_define(): conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++", "compiler.version": "7.1", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) assert be.gcc_cxx11_abi == "_GLIBCXX_USE_CXX11_ABI=0" env = be.vars() assert "-D_GLIBCXX_USE_CXX11_ABI=0" in env["CPPFLAGS"] conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++11", "compiler.version": "7.1", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.vars() assert be.gcc_cxx11_abi is None assert "GLIBCXX_USE_CXX11_ABI" not in env["CPPFLAGS"] # Force the GLIBCXX_USE_CXX11_ABI=1 for old distros is direct def f ``gcc_cxx11_abi`` be.gcc_cxx11_abi = "_GLIBCXX_USE_CXX11_ABI=1" env = be.vars() assert "-D_GLIBCXX_USE_CXX11_ABI=1" in env["CPPFLAGS"] # Also conf is possible conanfile.conf["tools.gnu:define_libcxx11_abi"] = True be = AutotoolsToolchain(conanfile) env = be.vars() assert "-D_GLIBCXX_USE_CXX11_ABI=1" in env["CPPFLAGS"]
def generate(self): yes_no = lambda v: "yes" if v else "no" tc = AutotoolsToolchain(self) tc.default_configure_install_args = True # FIXME: https://github.com/conan-io/conan/issues/10650 (should be default) tc.configure_args.append("--with-zstd=%s" % yes_no(self.options.with_zstd)) tc.configure_args.append("--with-xz=%s" % yes_no(self.options.with_xz)) tc.configure_args.append("--with-zlib=%s" % yes_no(self.options.with_zlib)) tc.configure_args.append("--with-openssl=%s" % yes_no(self.options.with_openssl)) tc.configure_args.append("--enable-experimental=%s" % yes_no(self.options.experimental)) tc.configure_args.append("--enable-logging=%s" % yes_no(self.options.logging)) tc.configure_args.append("--enable-debug=%s" % yes_no(self.settings.build_type == "Debug")) tc.configure_args.append("--enable-tools=no") tc.configure_args.append("--enable-manpages=no") tc.configure_args.append("--enable-test-modules=no") tc.configure_args.append("--enable-python=no") tc.configure_args.append("--enable-coverage=no") tc.generate() tc = PkgConfigDeps(self) tc.generate() tc = AutotoolsDeps(self) tc.environment.define( "PKG_CONFIG_PATH", self.source_folder ) # FIXME: https://github.com/conan-io/conan/issues/10639 (should work out of the box) tc.environment.define( "LIBS", "-lpthread" ) # FIXME: https://github.com/conan-io/conan/issues/10341 (regression in 1.45, soname arguments are "eaten") tc.environment.define( "libzstd_LIBS", "-lzstd" ) # FIXME: https://github.com/conan-io/conan/issues/10640 (zstd pkg-config includes itself) tc.environment.define( "zlib_LIBS", "-lz" ) # FIXME: https://github.com/conan-io/conan/issues/10651 (command line is polluted by framework arguments) tc.environment.define("libcrypto_LIBS", "-lcrypto -ldl -lrt -lpthread") tc.environment.define("liblzma_LIBS", "-llzma") tc.generate()