Skip to content

Commit

Permalink
Merge pull request #12515 from conan-io/develop2
Browse files Browse the repository at this point in the history
Merge develop2 to release branch
  • Loading branch information
czoido authored Nov 11, 2022
2 parents 866ae06 + dcc4a57 commit 0937ada
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 13 deletions.
2 changes: 2 additions & 0 deletions conan/tools/apple/apple.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __init__(self, conanfile, sdk=None, use_settings_target=False):
sdk it automatically if ``None`` is passed.
:param target_settings: Try to use ``settings_target`` in case they exist (``False`` by default)
"""
settings = None
if conanfile:
settings = conanfile.settings
if use_settings_target and conanfile.settings_target is not None:
Expand All @@ -98,6 +99,7 @@ def __init__(self, conanfile, sdk=None, use_settings_target=False):
if sdk is None and settings:
sdk = settings.get_safe('os.sdk')

self.settings = settings
self.sdk = sdk

def _invoke(self, args):
Expand Down
5 changes: 4 additions & 1 deletion conan/tools/cmake/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, conanfile):

self._cmake_program = "cmake" # Path to CMake should be handled by environment

def configure(self, variables=None, build_script_folder=None):
def configure(self, variables=None, build_script_folder=None, cli_args=None):
"""
Reads the ``CMakePresets.json`` file generated by the
Expand Down Expand Up @@ -99,6 +99,9 @@ def configure(self, variables=None, build_script_folder=None):
arg_list.extend(['-D{}="{}"'.format(k, v) for k, v in self._cache_variables.items()])
arg_list.append('"{}"'.format(cmakelist_folder))

if cli_args:
arg_list.extend(cli_args)

command = " ".join(arg_list)
self._conanfile.output.info("CMake command: %s" % command)
with chdir(self, build_folder):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def template(self):
# FIXME: What is the result of this for multi-config? All configs adding themselves to path?
set(CMAKE_MODULE_PATH {{ '${' }}{{ pkg_name }}_BUILD_DIRS{{ config_suffix }}} {{ '${' }}CMAKE_MODULE_PATH})
set(CMAKE_PREFIX_PATH {{ '${' }}{{ pkg_name }}_BUILD_DIRS{{ config_suffix }}} {{ '${' }}CMAKE_PREFIX_PATH})
{% if not components_names %}
Expand Down
9 changes: 6 additions & 3 deletions conan/tools/gnu/autotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from conan.tools.files.files import load_toolchain_args
from conans.client.subsystems import subsystem_path, deduce_subsystem
from conan.tools.files import chdir
from conan.tools.microsoft import unix_path


def join_arguments(args):
Expand Down Expand Up @@ -68,7 +69,8 @@ def make(self, target=None, args=None):
``make`` call.
"""
make_program = self._conanfile.conf.get("tools.gnu:make_program",
default="mingw32-make" if self._use_win_mingw() else "make")
default="mingw32-make" if self._use_win_mingw()
else "make")
str_args = self._make_args
str_extra_args = " ".join(args) if args is not None else ""
jobs = ""
Expand All @@ -79,17 +81,18 @@ def make(self, target=None, args=None):
command = join_arguments([make_program, target, str_args, str_extra_args, jobs])
self._conanfile.run(command)

def install(self, args=None):
def install(self, args=None, target="install"):
"""
This is just an "alias" of ``self.make(target="install")``
:param args: (Optional, Defaulted to ``None``): List of arguments to use for the
``make`` call. By default an argument ``DESTDIR=unix_path(self.package_folder)``
is added to the call if the passed value is ``None``. See more information about
:ref:`tools.microsoft.unix_path() function<conan_tools_microsoft_unix_path>`
:param target: (Optional, Defaulted to ``None``): Choose which target to install.
"""
args = args if args is not None else ["DESTDIR={}".format(self._conanfile.package_folder)]
self.make(target="install", args=args)
self.make(target=target, args=args)

def autoreconf(self, args=None):
"""
Expand Down
103 changes: 103 additions & 0 deletions conans/test/functional/toolchains/cmake/test_cmake_toolchain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import platform
import re
import textwrap

import pytest
Expand Down Expand Up @@ -1129,3 +1130,105 @@ def test_cmake_toolchain_vars_when_option_declared():
t.run_command("cmake -S . -B build/ -DBUILD_SHARED_LIBS=ON")
assert "mylib target type: SHARED_LIBRARY" in t.out
assert "mylib position independent code: ON" in t.out


@pytest.mark.tool("cmake")
def test_find_program_for_tool_requires():
"""Test that the same reference can be both a tool_requires and a regular requires,
and that find_program (executables) and find_package (libraries) find the correct ones
when cross building.
"""

client = TestClient()

conanfile = textwrap.dedent("""
import os
from conan import ConanFile
from conan.tools.files import copy
class TestConan(ConanFile):
name = "foobar"
version = "1.0"
settings = "os", "arch", "compiler", "build_type"
exports_sources = "*"
def layout(self):
pass
def package(self):
copy(self, pattern="lib*", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"))
copy(self, pattern="*bin", src=self.build_folder, dst=os.path.join(self.package_folder, "bin"))
""")

host_profile = textwrap.dedent("""
[settings]
os=Linux
arch=armv8
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
build_type=Release
""")

build_profile = textwrap.dedent("""
[settings]
os=Linux
arch=x86_64
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
build_type=Release
""")

client.save({"conanfile.py": conanfile,
"libfoo.so": "",
"foobin": "",
"host_profile": host_profile,
"build_profile": build_profile
})

xxx = client.get_default_build_profile()

client.run("create . -pr:b build_profile -pr:h build_profile")
build_context_package_folder = re.search(r"Package folder ([\w\W]+).conan2([\w\W]+)", str(client.out)).group(2).strip()
build_context_package_folder = build_context_package_folder.replace("\\", "/")
client.run("create . -pr:b build_profile -pr:h host_profile")
host_context_package_folder = re.search(r"Package folder ([\w\W]+).conan2([\w\W]+)", str(client.out)).group(2).strip()
host_context_package_folder = host_context_package_folder.replace("\\", "/")

conanfile_consumer = textwrap.dedent("""
from conan import ConanFile
from conan.tools.cmake import cmake_layout
class PkgConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires("foobar/1.0")
def build_requirements(self):
self.tool_requires("foobar/1.0")
""")

cmakelists_consumer = textwrap.dedent("""
cmake_minimum_required(VERSION 3.15)
project(Hello LANGUAGES NONE)
find_package(foobar CONFIG REQUIRED)
find_program(FOOBIN_EXECUTABLE foobin)
message("foobin executable: ${FOOBIN_EXECUTABLE}")
message("foobar include dir: ${foobar_INCLUDE_DIR}")
""")

client.save({
"conanfile_consumer.py": conanfile_consumer,
"CMakeLists.txt": cmakelists_consumer,
"host_profile": host_profile,
"build_profile": build_profile}, clean_first=True)
client.run("install conanfile_consumer.py --requires=pkg/0.1@ -g CMakeToolchain -g CMakeDeps -pr:b build_profile -pr:h host_profile")

with client.chdir("build"):
client.run_command("cmake .. -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release")
# Verify binary executable is found from build context package,
# and library comes from host context package
assert f"{build_context_package_folder}/bin/foobin" in client.out
assert f"{host_context_package_folder}/include" in client.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import platform
import textwrap

Expand Down Expand Up @@ -48,6 +49,7 @@ def build(self):
autotools = Autotools(self)
autotools.configure()
autotools.make()
autotools.install()
""")

client.save({"conanfile.py": conanfile,
Expand All @@ -62,3 +64,6 @@ def build(self):
bat_contents = client.load("conanbuild.bat")
assert "conanvcvars.bat" in bat_contents

# To check that the ``autotools.install()`` has worked correctly
# FIXME IN CONAN 2.0 this will break, no local `package_folder`
assert os.path.exists(os.path.join(client.current_folder, "package", "bin", "main.exe"))
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,24 @@ def build(self):
# It's not needed to declare "hello/0.1" as a dependency, only interested in flags
executable('demo', 'main.cpp')
""")

main = textwrap.dedent("""
#include <stdio.h>
#define STR(x) #x
#define SHOW_DEFINE(x) printf("%s=%s", #x, STR(x))
int main(int argc, char *argv[]) {
SHOW_DEFINE(VAR);
SHOW_DEFINE(VAR2);
SHOW_DEFINE(DEF1);
SHOW_DEFINE(DEF2);
SHOW_DEFINE(DEF3);
return 0;
}
""")

client.save({"conanfile.py": conanfile_py,
"meson.build": meson_build,
"main.cpp": "int main()\n{return 0;}\n"},
"main.cpp": main},
clean_first=True)

client.run("build . -c 'tools.build:cxxflags=[%s]'" % flags)
Expand All @@ -137,9 +152,11 @@ def build(self):
assert "'--native-file {folder}/conan_meson_native.ini' " \
"'--native-file {folder}/conan_meson_deps_flags.ini'" \
"".format(folder=client.current_folder.replace("\\", "/")) in meson_log
# Flags/Defines from deps and consumer are appearing in meson-log.txt as part
# of the command-line
assert flags in meson_log
assert '-DVAR="VALUE" -DVAR2="VALUE2"' in meson_log
assert deps_flags in meson_log
assert '-DDEF3=simple_string -DDEF1=one_string -DDEF2=other_string' in meson_log

app_name = "demo.exe" if platform.system() == "Windows" else "demo"
client.run_command(os.path.join("build", app_name))
assert 'VAR="VALUE' in client.out
assert 'VAR2="VALUE2"' in client.out
assert 'DEF1=one_string' in client.out
assert 'DEF2=other_string' in client.out
assert 'DEF3=simple_string' in client.out
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ def test_configure_arguments():
ab.make()
assert "my_make my_make_args -j23" in runner.command_called

# test install target argument

ab.install()
assert 'my_make install my_make_args DESTDIR=None -j23' in runner.command_called

ab.install(target="install_other")
assert 'my_make install_other my_make_args DESTDIR=None -j23' in runner.command_called
13 changes: 12 additions & 1 deletion conans/test/unittests/tools/apple/test_apple_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from conans.test.utils.mocks import ConanFileMock, MockSettings, MockOptions
from conans.test.utils.test_files import temp_folder
from conan.tools.apple import is_apple_os, to_apple_arch, fix_apple_shared_install_name
from conan.tools.apple import is_apple_os, to_apple_arch, fix_apple_shared_install_name, XCRun

def test_tools_apple_is_apple_os():
conanfile = ConanFileMock()
Expand Down Expand Up @@ -36,3 +36,14 @@ def test_fix_shared_install_name_no_libraries():
with pytest.raises(Exception) as e:
fix_apple_shared_install_name(conanfile)
assert "not found inside package folder" in str(e.value)


def test_xcrun_public_settings():
# https://github.com/conan-io/conan/issues/12485
conanfile = ConanFileMock()
conanfile.settings = MockSettings({"os": "watchOS"})

xcrun = XCRun(conanfile, use_settings_target=True)
settings = xcrun.settings

assert settings.os == "watchOS"
15 changes: 15 additions & 0 deletions conans/test/unittests/tools/cmake/test_cmake_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,18 @@ def test_run_tests(generator, target):

search_pattern = "--target {}"
assert search_pattern.format(target) in conanfile.command


def test_cli_args_configure():
settings = Settings.loads(get_default_settings_yml())

conanfile = ConanFileMock()
conanfile.conf = Conf()
conanfile.folders.generators = "."
conanfile.folders.set_base_generators(temp_folder())
conanfile.settings = settings

write_cmake_presets(conanfile, "toolchain", "Unix Makefiles", {})
cmake = CMake(conanfile)
cmake.configure(cli_args=["--graphviz=foo.dot"])
assert "--graphviz=foo.dot" in conanfile.command
1 change: 1 addition & 0 deletions conans/test/utils/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def __init__(self, shared=None):
self.path = None
self.settings = None
self.settings_build = MockSettings({"os": "Linux", "arch": "x86_64"})
self.settings_target = None
self.options = Options()
if shared is not None:
self.options = namedtuple("options", "shared")(shared)
Expand Down

0 comments on commit 0937ada

Please sign in to comment.