Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
def test_foo():
    dep1 = ConanFile(Mock(), None)
    dep1.cpp_info = get_cpp_info("dep1")
    dep1._conan_node = Mock()
    dep1._conan_node.ref = ConanFileReference.loads("dep1/1.0")
    dep1.package_folder = "/path/to/folder_dep1"

    dep2 = ConanFile(Mock(), None)
    dep2.cpp_info = get_cpp_info("dep2")
    dep2._conan_node = Mock()
    dep2._conan_node.ref = ConanFileReference.loads("dep2/1.0")
    dep2.package_folder = "/path/to/folder_dep2"

    with mock.patch('conans.ConanFile.dependencies',
                    new_callable=mock.PropertyMock) as mock_deps:
        req1 = Requirement(ConanFileReference.loads("dep1/1.0"))
        req2 = Requirement(ConanFileReference.loads("dep2/1.0"))
        deps = OrderedDict()
        deps[req1] = ConanFileInterface(dep1)
        deps[req2] = ConanFileInterface(dep2)
        mock_deps.return_value = ConanFileDependencies(deps)
        consumer = ConanFile(Mock(), None)
        consumer.settings = MockSettings({
            "build_type": "Release",
            "arch": "x86",
            "compiler": "gcc",
            "compiler.libcxx": "libstdc++11",
            "compiler.version": "7.1",
            "cppstd": "17"
        })
        deps = AutotoolsDeps(consumer)
        # deps.generate()
        env = deps.environment()
        assert env["LDFLAGS"] == ' dep1_shared_link_flag dep2_shared_link_flag ' \
                                 'dep1_exe_link_flag dep2_exe_link_flag ' \
                                 '-framework dep1_oneframework -framework dep1_twoframework ' \
                                 '-framework dep2_oneframework -framework dep2_twoframework ' \
                                 '-F /path/to/folder_dep1/one/framework/path/dep1 ' \
                                 '-F /path/to/folder_dep2/one/framework/path/dep2 ' \
                                 '-L/path/to/folder_dep1/one/lib/path/dep1 ' \
                                 '-L/path/to/folder_dep2/one/lib/path/dep2 ' \
                                 '-Wl,-rpath,"/path/to/folder_dep1/one/lib/path/dep1" ' \
                                 '-Wl,-rpath,"/path/to/folder_dep2/one/lib/path/dep2" ' \
                                 '--sysroot=/path/to/folder/dep1'

        assert env[
            "CXXFLAGS"] == ' dep1_a_cxx_flag dep2_a_cxx_flag --sysroot=/path/to/folder/dep1'
        assert env[
            "CFLAGS"] == ' dep1_a_c_flag dep2_a_c_flag --sysroot=/path/to/folder/dep1'
Ejemplo n.º 5
0
 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()
Ejemplo n.º 6
0
 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")
Ejemplo n.º 7
0
 def __init__(self, conanfile):
     self.toolchain = AutotoolsToolchain(conanfile)
     self.deps = AutotoolsDeps(conanfile)
     self.env = VirtualEnv(conanfile)
Ejemplo n.º 8
0
def test_foo():
    dep1 = ConanFile(Mock(), None)
    dep1.cpp_info = get_cpp_info("dep1")
    dep1._conan_node = Mock()
    dep1._conan_node.ref = ConanFileReference.loads("dep1/1.0")
    dep1.package_folder = "/path/to/folder_dep1"

    dep2 = ConanFile(Mock(), None)
    dep2.cpp_info = get_cpp_info("dep2")
    dep2._conan_node = Mock()
    dep2._conan_node.ref = ConanFileReference.loads("dep2/1.0")
    dep2.package_folder = "/path/to/folder_dep2"

    with mock.patch('conans.ConanFile.dependencies',
                    new_callable=mock.PropertyMock) as mock_deps:
        req1 = Requirement(ConanFileReference.loads("dep1/1.0"))
        req2 = Requirement(ConanFileReference.loads("dep2/1.0"))
        deps = OrderedDict()
        deps[req1] = ConanFileInterface(dep1)
        deps[req2] = ConanFileInterface(dep2)
        mock_deps.return_value = ConanFileDependencies(deps)
        consumer = ConanFile(Mock(), None)
        consumer.settings = MockSettings({
            "build_type": "Release",
            "arch": "x86",
            "compiler": "gcc",
            "compiler.libcxx": "libstdc++11",
            "compiler.version": "7.1",
            "cppstd": "17"
        })
        deps = AutotoolsDeps(consumer)

        env = deps.environment

        # Customize the environment
        env.remove("LDFLAGS", "dep2_shared_link_flag")
        env.remove("LDFLAGS",
                   "-F /path/to/folder_dep1/one/framework/path/dep1")
        env.append("LDFLAGS", "OtherSuperStuff")

        # The contents are of course modified
        assert env["LDFLAGS"] == 'dep1_shared_link_flag ' \
                                 'dep1_exe_link_flag dep2_exe_link_flag ' \
                                 '-framework dep1_oneframework -framework dep1_twoframework ' \
                                 '-framework dep2_oneframework -framework dep2_twoframework ' \
                                 '-F /path/to/folder_dep2/one/framework/path/dep2 ' \
                                 '-L/path/to/folder_dep1/one/lib/path/dep1 ' \
                                 '-L/path/to/folder_dep2/one/lib/path/dep2 ' \
                                 '-Wl,-rpath,"/path/to/folder_dep1/one/lib/path/dep1" ' \
                                 '-Wl,-rpath,"/path/to/folder_dep2/one/lib/path/dep2" ' \
                                 '--sysroot=/path/to/folder/dep1 OtherSuperStuff'

        assert env[
            "CXXFLAGS"] == 'dep1_a_cxx_flag dep2_a_cxx_flag --sysroot=/path/to/folder/dep1'
        assert env[
            "CFLAGS"] == 'dep1_a_c_flag dep2_a_c_flag --sysroot=/path/to/folder/dep1'
        folder = temp_folder()
        consumer.folders.set_base_install(folder)
        deps.generate()
        extension = ".bat" if platform.system() == "Windows" else ".sh"

        # The generated file also contains the changes
        with open(
                os.path.join(folder,
                             "conanautotoolsdeps{}".format(extension))) as _f:
            contents = _f.read()
            assert "path/to/folder_dep1/one/framework/path/dep1" not in contents
            assert "OtherSuperStuff" in contents