コード例 #1
0
def test_apple_meson_toolchain_cross_compiling(arch, os_, os_version, sdk):
    profile = textwrap.dedent("""
    include(default)

    [settings]
    os = {os}
    os.version = {os_version}
    os.sdk = {os_sdk}
    arch = {arch}
    compiler = apple-clang
    compiler.version = 12.0
    compiler.libcxx = libc++

    [conf]
    tools.apple:sdk_path={sdk_path}
    """)

    xcrun = XCRun(None, sdk)
    sdk_path = xcrun.sdk_path

    hello_h = gen_function_h(name="hello")
    hello_cpp = gen_function_cpp(name="hello",
                                 preprocessor=["STRING_DEFINITION"])
    app = gen_function_cpp(name="main", includes=["hello"], calls=["hello"])
    profile = profile.format(os=os_,
                             os_version=os_version,
                             os_sdk=sdk,
                             arch=arch,
                             sdk_path=sdk_path)

    t = TestClient()
    t.save({
        "conanfile.py": _conanfile_py,
        "meson.build": _meson_build,
        "meson_options.txt": _meson_options_txt,
        "hello.h": hello_h,
        "hello.cpp": hello_cpp,
        "main.cpp": app,
        "profile_host": profile
    })

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

    libhello = os.path.join(t.current_folder, "build", "libhello.a")
    assert os.path.isfile(libhello) is True
    demo = os.path.join(t.current_folder, "build", "demo")
    assert os.path.isfile(demo) is True

    lipo = xcrun.find('lipo')

    t.run_command('"%s" -info "%s"' % (lipo, libhello))
    assert "architecture: %s" % to_apple_arch(arch) in t.out

    t.run_command('"%s" -info "%s"' % (lipo, demo))
    assert "architecture: %s" % to_apple_arch(arch) in t.out
コード例 #2
0
ファイル: test_ios.py プロジェクト: Aleksei-Badyaev/conan
    def test_meson_toolchain(self, arch, os_, os_version, sdk):
        self.xcrun = XCRun(None, sdk)
        self.arch = arch
        self.os = os_
        self.os_version = os_version

        hello_h = gen_function_h(name="hello")
        hello_cpp = gen_function_cpp(name="hello",
                                     preprocessor=["STRING_DEFINITION"])
        app = gen_function_cpp(name="main",
                               includes=["hello"],
                               calls=["hello"])

        self.t = TestClient()

        self.t.save({
            "conanfile.py": self._conanfile_py,
            "meson.build": self._meson_build,
            "meson_options.txt": self._meson_options_txt,
            "hello.h": hello_h,
            "hello.cpp": hello_cpp,
            "main.cpp": app,
            "profile_host": self.profile()
        })

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

        self.t.run("build .")

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

        lipo = self.xcrun.find('lipo')

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

        self.t.run_command('"%s" -info "%s"' % (lipo, demo))
        self.assertIn("architecture: %s" % to_apple_arch(self.arch),
                      self.t.out)
コード例 #3
0
ファイル: test_ios.py プロジェクト: Aleksei-Badyaev/conan
class IOSMesonTestCase(unittest.TestCase):

    _conanfile_py = textwrap.dedent("""
    from conans import ConanFile, tools
    from conan.tools.meson import Meson, MesonToolchain


    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 generate(self):
            tc = MesonToolchain(self)
            tc.generate()

        def build(self):
            meson = Meson(self)
            meson.configure()
            meson.build()
    """)

    _meson_build = textwrap.dedent("""
    project('tutorial', 'cpp')
    add_global_arguments('-DSTRING_DEFINITION="' + get_option('STRING_DEFINITION') + '"',
                         language : 'cpp')
    hello = library('hello', 'hello.cpp')
    executable('demo', 'main.cpp', link_with: hello)
    """)

    _meson_options_txt = textwrap.dedent("""
    option('STRING_DEFINITION', type : 'string', description : 'a string option')
    """)

    def settings(self):
        return [("os", self.os), ("os.version", self.os_version),
                ("arch", self.arch), ("compiler", "apple-clang"),
                ("compiler.version", "12.0"), ("compiler.libcxx", "libc++")]

    def env(self):
        cc = self.xcrun.cc
        cxx = self.xcrun.cxx

        deployment_flag = apple_deployment_target_flag(self.os,
                                                       self.os_version)
        sysroot_flag = " -isysroot " + self.xcrun.sdk_path
        arch_flag = " -arch " + to_apple_arch(self.arch)
        flags = deployment_flag + sysroot_flag + arch_flag

        return {
            'CC': cc,
            'CXX': cxx,
            'CFLAGS': flags,
            'CXXFLAGS': flags,
            'LDFLAGS': flags
        }

    def profile(self):
        template = textwrap.dedent("""
            include(default)
            [settings]
            {settings}
            [buildenv]
            {env}
            """)
        settings = '\n'.join(
            ["%s = %s" % (s[0], s[1]) for s in self.settings()])
        env = '\n'.join(["%s=%s" % (k, v) for k, v in self.env().items()])
        return template.format(settings=settings, env=env)

    @parameterized.expand([('armv8', 'iOS', '10.0', 'iphoneos'),
                           ('armv7', 'iOS', '10.0', 'iphoneos'),
                           ('x86', 'iOS', '10.0', 'iphonesimulator'),
                           ('x86_64', 'iOS', '10.0', 'iphonesimulator')])
    def test_meson_toolchain(self, arch, os_, os_version, sdk):
        self.xcrun = XCRun(None, sdk)
        self.arch = arch
        self.os = os_
        self.os_version = os_version

        hello_h = gen_function_h(name="hello")
        hello_cpp = gen_function_cpp(name="hello",
                                     preprocessor=["STRING_DEFINITION"])
        app = gen_function_cpp(name="main",
                               includes=["hello"],
                               calls=["hello"])

        self.t = TestClient()

        self.t.save({
            "conanfile.py": self._conanfile_py,
            "meson.build": self._meson_build,
            "meson_options.txt": self._meson_options_txt,
            "hello.h": hello_h,
            "hello.cpp": hello_cpp,
            "main.cpp": app,
            "profile_host": self.profile()
        })

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

        self.t.run("build .")

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

        lipo = self.xcrun.find('lipo')

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

        self.t.run_command('"%s" -info "%s"' % (lipo, demo))
        self.assertIn("architecture: %s" % to_apple_arch(self.arch),
                      self.t.out)
コード例 #4
0
ファイル: test_ios.py プロジェクト: tapia/conan
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
コード例 #5
0
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'"