示例#1
0
def build_windows_subsystem(profile, make_program):
    """ The AutotoolsDeps can be used also in pure Makefiles, if the makefiles follow
    the Autotools conventions
    """
    # FIXME: cygwin in CI (my local machine works) seems broken for path with spaces
    client = TestClient(path_with_spaces=False)
    client.run("new hello/0.1 --template=cmake_lib")
    # TODO: Test Windows subsystems in CMake, at least msys is broken
    os.rename(os.path.join(client.current_folder, "test_package"),
              os.path.join(client.current_folder, "test_package2"))
    client.save({"profile": profile})
    client.run("create . --profile=profile")

    main = gen_function_cpp(name="main", includes=["hello"], calls=["hello"])
    makefile = gen_makefile(apps=["app"])

    conanfile = textwrap.dedent("""
        from conans import ConanFile
        from conan.tools.gnu import AutotoolsToolchain, Autotools, AutotoolsDeps

        class TestConan(ConanFile):
            requires = "hello/0.1"
            settings = "os", "compiler", "arch", "build_type"
            exports_sources = "Makefile"
            generators = "AutotoolsDeps", "AutotoolsToolchain"

            def build(self):
                autotools = Autotools(self)
                autotools.make()
        """)
    client.save({"app.cpp": main,
                 "Makefile": makefile,
                 "conanfile.py": conanfile,
                 "profile": profile}, clean_first=True)

    client.run("install . --profile=profile")
    cmd = environment_wrap_command(["conanbuildenv",
                                    "conanautotoolstoolchain",
                                    "conanautotoolsdeps"], client.current_folder, make_program)
    client.run_command(cmd)
    client.run_command("app")
    # TODO: fill compiler version when ready
    check_exe_run(client.out, "main", "gcc", None, "Release", "x86_64", None)
    assert "hello/0.1: Hello World Release!" in client.out

    client.save({"app.cpp": gen_function_cpp(name="main", msg="main2",
                                             includes=["hello"], calls=["hello"])})
    # Make sure it is newer
    t = time.time() + 1
    touch(os.path.join(client.current_folder, "app.cpp"), (t, t))

    client.run("build .")
    client.run_command("app")
    # TODO: fill compiler version when ready
    check_exe_run(client.out, "main2", "gcc", None, "Release", "x86_64", None, cxx11_abi=0)
    assert "hello/0.1: Hello World Release!" in client.out
    return client.out
示例#2
0
 def _build(client):
     makefile = gen_makefile(apps=["app"])
     main_cpp = gen_function_cpp(name="main")
     client.save({"Makefile": makefile, "app.cpp": main_cpp})
     client.run_command("make")
     client.run_command("app")
import os
import textwrap
import platform

import pytest

from conan.tools.apple.apple import to_apple_arch
from conans.test.assets.autotools import gen_makefile
from conans.test.assets.sources import gen_function_h, gen_function_cpp
from conans.test.utils.tools import TestClient

makefile = gen_makefile(apps=["app"], libs=["hello"])

conanfile_py = textwrap.dedent("""
    from conans import ConanFile, tools
    from conan.tools.gnu import Autotools

    class App(ConanFile):
        settings = "os", "arch", "compiler", "build_type"
        options = {"shared": [True, False], "fPIC": [True, False]}
        default_options = {"shared": False, "fPIC": True}
        generators = "AutotoolsToolchain"

        def config_options(self):
            if self.settings.os == "Windows":
                del self.options.fPIC

        def build(self):
            env_build = Autotools(self)
            env_build.make()
    """)
示例#4
0
class AutoToolsAppleTest(unittest.TestCase):
    makefile = gen_makefile(apps=["app"], libs=["hello"])

    conanfile_py = textwrap.dedent("""
        from conans import ConanFile, tools, AutoToolsBuildEnvironment

        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 build(self):
                env_build = AutoToolsBuildEnvironment(self)
                env_build.make()
        """)

    @parameterized.expand([("x86_64", "Macos", "10.14"),
                           ("armv8", "iOS", "10.0"),
                           ("armv7", "iOS", "10.0"),
                           ("x86", "iOS", "10.0"),
                           ("x86_64", "iOS", "10.0")
                           ])
    def test_makefile_arch(self, arch, os_, os_version):
        self.arch = arch
        self.os = os_
        self.os_version = os_version

        profile = textwrap.dedent("""
            include(default)
            [settings]
            os = {os}
            os.version = {os_version}
            arch = {arch}
            """).format(os=self.os, arch=self.arch, os_version=self.os_version)

        self.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"])

        self.t.save({"Makefile": self.makefile,
                     "hello.h": hello_h,
                     "hello.cpp": hello_cpp,
                     "app.cpp": main_cpp,
                     "conanfile.py": self.conanfile_py,
                     "profile": profile})

        self.t.run("install . --profile:host=profile")
        self.t.run("build .")

        libhello = os.path.join(self.t.current_folder, "libhello.a")
        app = os.path.join(self.t.current_folder, "app")
        self.assertTrue(os.path.isfile(libhello))
        self.assertTrue(os.path.isfile(app))

        expected_arch = to_apple_arch(self.arch)

        self.t.run_command('lipo -info "%s"' % libhello)
        self.assertIn("architecture: %s" % expected_arch, self.t.out)

        self.t.run_command('lipo -info "%s"' % app)
        self.assertIn("architecture: %s" % expected_arch, self.t.out)

    def test_catalyst(self):
        profile = textwrap.dedent("""
            include(default)
            [settings]
            os = Macos
            os.version = 13.0
            os.sdk = macosx
            os.subsystem = catalyst
            arch = x86_64
            """)

        self.t = TestClient()
        hello_h = gen_function_h(name="hello")
        hello_cpp = gen_function_cpp(name="hello")
        main_cpp = textwrap.dedent("""
            #include "hello.h"
            #include <TargetConditionals.h>
            #include <iostream>

            int main()
            {
            #if TARGET_OS_MACCATALYST
                std::cout << "running catalyst " << __IPHONE_OS_VERSION_MIN_REQUIRED << std::endl;
            #else
                #error "not building for Apple Catalyst"
            #endif
            }
            """)

        self.t.save({"Makefile": self.makefile,
                     "hello.h": hello_h,
                     "hello.cpp": hello_cpp,
                     "app.cpp": main_cpp,
                     "conanfile.py": self.conanfile_py,
                     "profile": profile})

        self.t.run("install . --profile:host=profile")
        self.t.run("build .")

        libhello = os.path.join(self.t.current_folder, "libhello.a")
        app = os.path.join(self.t.current_folder, "app")
        self.assertTrue(os.path.isfile(libhello))
        self.assertTrue(os.path.isfile(app))

        self.t.run_command('lipo -info "%s"' % libhello)
        self.assertIn("architecture: x86_64", self.t.out)

        self.t.run_command('lipo -info "%s"' % app)
        self.assertIn("architecture: x86_64", self.t.out)

        self.t.run_command('"%s"' % app)
        self.assertIn("running catalyst 130000", self.t.out)