forked from conan-io/conan
-
Notifications
You must be signed in to change notification settings - Fork 3
/
autotools_apple_test.py
140 lines (113 loc) · 4.92 KB
/
autotools_apple_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import os
import platform
import textwrap
import unittest
import pytest
from parameterized import parameterized
from conans.client.tools.apple import to_apple_arch
from conans.test.assets.autotools import gen_makefile
from conans.test.assets.sources import gen_function_cpp, gen_function_h
from conans.test.utils.tools import TestClient
@pytest.mark.skipif(platform.system() != "Darwin", reason="requires Xcode")
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"),
("armv8", "Macos", "10.14") # M1
])
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)
@parameterized.expand([("x86_64",), ("armv8",)])
@pytest.mark.xfail(reason="Disabled until fix apple-clang 13.1 and --target value for catalyst")
def test_catalyst(self, arch):
profile = textwrap.dedent("""
include(default)
[settings]
os = Macos
os.version = 12.0
os.sdk = macosx
os.subsystem = catalyst
arch = {arch}
""").format(arch=arch)
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))
expected_arch = to_apple_arch(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)
if arch == "x86_64":
self.t.run_command('"%s"' % app)
self.assertIn("running catalyst 130000", self.t.out)