Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for universal binaries macOS using Ninja #17024

Merged
merged 8 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion conan/tools/cmake/cmakedeps/templates/target_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def filename(self):
if self.arch:
data_fname += "-{}".format(self.arch)
data_fname += "-data.cmake"
return data_fname
# https://github.com/conan-io/conan/issues/17009
return data_fname.replace("|", "_")

@property
def _build_modules_activated(self):
Expand Down
2 changes: 1 addition & 1 deletion conan/tools/env/virtualbuildenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _filename(self):
if configuration:
f += "-" + configuration.replace(".", "_")
if arch:
f += "-" + arch.replace(".", "_")
f += "-" + arch.replace(".", "_").replace("|", "_")
return f

def environment(self):
Expand Down
2 changes: 1 addition & 1 deletion conan/tools/env/virtualrunenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _filename(self):
if self.configuration:
f += "-" + self.configuration.replace(".", "_")
if self.arch:
f += "-" + self.arch.replace(".", "_")
f += "-" + self.arch.replace(".", "_").replace("|", "_")
return f

def environment(self):
Expand Down
44 changes: 44 additions & 0 deletions test/functional/toolchains/cmake/test_universal_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,47 @@ def test(self):
client.run_command("lipo -info './build/armv8|armv8.3|x86_64/Release/foo'")

assert "foo are: x86_64 arm64 arm64e" in client.out


@pytest.mark.skipif(platform.system() != "Darwin", reason="Only OSX")
@pytest.mark.tool("cmake", "3.23")
def test_create_universal_binary_ninja():
client = TestClient()

client.run("new cmake_lib -d name=mylibrary -d version=1.0")

client.run('export .')

conanfile = textwrap.dedent("""
[requires]
mylibrary/1.0
[generators]
CMakeToolchain
CMakeDeps
VirtualBuildEnv
VirtualRunEnv
""")

cmake = textwrap.dedent("""
cmake_minimum_required(VERSION 3.23)
project(ninjatest CXX)

find_package(mylibrary CONFIG REQUIRED)
""")

client.save({"conanfile.txt": conanfile,
"CMakeLists.txt": cmake},
clean_first=True)

client.run('install . -s=arch="armv8|x86_64" --build=missing -of=build')

with client.chdir("build"):
client.run_command("cmake .. -GNinja "
"-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake "
"-DCMAKE_POLICY_DEFAULT_CMP0091=NEW "
"-DCMAKE_BUILD_TYPE=Release")

assert "ninja: error: build.ninja:87: expected newline, got '|'" not in client.out
czoido marked this conversation as resolved.
Show resolved Hide resolved
assert "Build files have been written to:" in client.out
# test that there are no files with the "|" character in the build folder
assert not any("|" in f for f in os.listdir(os.path.join(client.current_folder, "build")))