Repository: conan-io/conan
Pull request #12635 (2022-11-30 09:48:04)

[conf] objcpp instead of objcxx
Changelog: omit
Docs: omit



Patch:
diff --git a/conan/tools/cmake/toolchain/blocks.py b/conan/tools/cmake/toolchain/blocks.py
index f22d6f760..5846f0097 100644
--- a/conan/tools/cmake/toolchain/blocks.py
+++ b/conan/tools/cmake/toolchain/blocks.py
@@ -682,7 +682,7 @@ class CompilersBlock(Block):
         compilers = {}
         # Allowed <LANG> variables (and <LANG>_LAUNCHER)
         compilers_mapping = {"c": "C", "cuda": "CUDA", "cpp": "CXX", "objc": "OBJC",
-                             "objcxx": "OBJCXX", "rc": "RC", 'fortran': "Fortran", 'asm': "ASM",
+                             "objcpp": "OBJCXX", "rc": "RC", 'fortran': "Fortran", 'asm': "ASM",
                              "hip": "HIP", "ispc": "ISPC"}
         for comp, lang in compilers_mapping.items():
             # To set CMAKE_<LANG>_COMPILER
diff --git a/conan/tools/meson/toolchain.py b/conan/tools/meson/toolchain.py
index ca4d7fe7b..17f553242 100644
--- a/conan/tools/meson/toolchain.py
+++ b/conan/tools/meson/toolchain.py
@@ -258,7 +258,7 @@ class MesonToolchain(object):
         self.apple_min_version_flag = [apple_min_version_flag(self._conanfile)]
         # Objective C/C++ ones
         self.objc = compilers_by_conf.get("objc", "clang")
-        self.objcpp = compilers_by_conf.get("objcxx", "clang++")
+        self.objcpp = compilers_by_conf.get("objcpp", "clang++")
         self.objc_args = self._get_env_list(build_env.get('OBJCFLAGS', []))
         self.objc_link_args = self._get_env_list(build_env.get('LDFLAGS', []))
         self.objcpp_args = self._get_env_list(build_env.get('OBJCXXFLAGS', []))
diff --git a/conans/client/installer.py b/conans/client/installer.py
index 87d47a616..79d6c0782 100644
--- a/conans/client/installer.py
+++ b/conans/client/installer.py
@@ -689,6 +689,12 @@ class BinaryInstaller(object):
                         conanfile.cpp_info.public_deps = public_deps
 
                         if not is_editable:
+                            # IMPORTANT: Need to go first, otherwise fill_old_cppinfo() destroys
+                            # component information
+                            conanfile.layouts.package.set_relative_base_folder(conanfile.package_folder)
+                            conanfile.buildenv_info.compose_env(conanfile.layouts.package.buildenv_info)
+                            conanfile.runenv_info.compose_env(conanfile.layouts.package.runenv_info)
+                            conanfile.conf_info.compose_conf(conanfile.layouts.package.conf_info)
                             # Copy the infos.package into the old cppinfo
                             fill_old_cppinfo(conanfile.cpp.package, conanfile.cpp_info)
                         else:
@@ -701,9 +707,10 @@ class BinaryInstaller(object):
                         # cppinfos inside
                         # convert directory entries to be relative to the declared folders.build
                         conanfile.cpp.build.set_relative_base_folder(conanfile.build_folder)
-
+                        conanfile.layouts.build.set_relative_base_folder(conanfile.build_folder)
                         # convert directory entries to be relative to the declared folders.source
                         conanfile.cpp.source.set_relative_base_folder(conanfile.source_folder)
+                        conanfile.layouts.source.set_relative_base_folder(conanfile.source_folder)
 
                         full_editable_cppinfo = NewCppInfo()
                         full_editable_cppinfo.merge(conanfile.cpp.source)
@@ -711,12 +718,12 @@ class BinaryInstaller(object):
                         # Paste the editable cpp_info but prioritizing it, only if a
                         # variable is not declared at build/source, the package will keep the value
                         fill_old_cppinfo(full_editable_cppinfo, conanfile.cpp_info)
-                        conanfile.buildenv_info.compose_env(conanfile.cpp.source.buildenv_info)
-                        conanfile.buildenv_info.compose_env(conanfile.cpp.build.buildenv_info)
-                        conanfile.runenv_info.compose_env(conanfile.cpp.source.runenv_info)
-                        conanfile.runenv_info.compose_env(conanfile.cpp.build.runenv_info)
-                        conanfile.conf_info.compose_conf(conanfile.cpp.source.conf_info)
-                        conanfile.conf_info.compose_conf(conanfile.cpp.build.conf_info)
+                        conanfile.buildenv_info.compose_env(conanfile.layouts.source.buildenv_info)
+                        conanfile.buildenv_info.compose_env(conanfile.layouts.build.buildenv_info)
+                        conanfile.runenv_info.compose_env(conanfile.layouts.source.runenv_info)
+                        conanfile.runenv_info.compose_env(conanfile.layouts.build.runenv_info)
+                        conanfile.conf_info.compose_conf(conanfile.layouts.source.conf_info)
+                        conanfile.conf_info.compose_conf(conanfile.layouts.build.conf_info)
 
                     if conanfile._conan_dep_cpp_info is None:
                         try:
diff --git a/conans/model/conan_file.py b/conans/model/conan_file.py
index bacba824f..76ff1dd26 100644
--- a/conans/model/conan_file.py
+++ b/conans/model/conan_file.py
@@ -17,7 +17,7 @@ from conans.model.build_info import DepsCppInfo
 from conans.model.conf import Conf
 from conans.model.dependencies import ConanFileDependencies
 from conans.model.env_info import DepsEnvInfo
-from conans.model.layout import Folders, Infos
+from conans.model.layout import Folders, Infos, Layouts
 from conans.model.new_build_info import from_old_cppinfo
 from conans.model.options import Options, OptionsValues, PackageOptions
 from conans.model.requires import Requirements
@@ -175,6 +175,7 @@ class ConanFile(object):
         # layout() method related variables:
         self.folders = Folders()
         self.cpp = Infos()
+        self.layouts = Layouts()
 
         self.cpp.package.includedirs = ["include"]
         self.cpp.package.libdirs = ["lib"]
diff --git a/conans/model/conf.py b/conans/model/conf.py
index ba3094804..62f91da8d 100644
--- a/conans/model/conf.py
+++ b/conans/model/conf.py
@@ -53,7 +53,7 @@ BUILT_IN_CONFS = {
     "tools.build:defines": "List of extra definition flags used by different toolchains like CMakeToolchain and AutotoolsToolchain",
     "tools.build:sharedlinkflags": "List of extra flags used by CMakeToolchain for CMAKE_SHARED_LINKER_FLAGS_INIT variable",
     "tools.build:exelinkflags": "List of extra flags used by CMakeToolchain for CMAKE_EXE_LINKER_FLAGS_INIT variable",
-    "tools.build:compiler_executables": "Defines a Python dict-like with the compilers path to be used. Allowed keys {'c', 'cpp', 'cuda', 'objc', 'objcxx', 'rc', 'fortran', 'asm', 'hip', 'ispc'}",
+    "tools.build:compiler_executables": "Defines a Python dict-like with the compilers path to be used. Allowed keys {'c', 'cpp', 'cuda', 'objc', 'objcpp', 'rc', 'fortran', 'asm', 'hip', 'ispc'}",
     "tools.microsoft.bash:subsystem": "Set subsystem to use for Windows. Possible values: 'msys2', 'msys', 'cygwin', 'wsl' and 'sfu'",
     "tools.microsoft.bash:path": "Path to the shell executable. Default: 'bash'",
     "tools.apple:sdk_path": "Path for the sdk location. This value will be passed as SDKROOT or -isysroot depending on the generator used",
diff --git a/conans/model/layout.py b/conans/model/layout.py
index d8c17202f..d0ddb98a9 100644
--- a/conans/model/layout.py
+++ b/conans/model/layout.py
@@ -4,27 +4,32 @@ from conans.model.conf import Conf
 from conans.model.new_build_info import NewCppInfo
 
 
-class _SubInfo(NewCppInfo):
-    def __init__(self, with_defaults=False):
-        super().__init__(with_defaults)
+class Infos(object):
+
+    def __init__(self):
+        self.source = NewCppInfo()
+        self.build = NewCppInfo()
+        self.package = NewCppInfo(with_defaults=True)
+
+
+class PartialLayout(object):
+    def __init__(self):
         from conan.tools.env import Environment
         self.buildenv_info = Environment()
         self.runenv_info = Environment()
         self.conf_info = Conf()
 
     def set_relative_base_folder(self, folder):
-        super().set_relative_base_folder(folder)
         self.buildenv_info.set_relative_base_folder(folder)
         self.runenv_info.set_relative_base_folder(folder)
         self.conf_info.set_relative_base_folder(folder)
 
 
-class Infos(object):
-
+class Layouts(object):
     def __init__(self):
-        self.source = _SubInfo()
-        self.build = _SubInfo()
-        self.package = _SubInfo(with_defaults=True)
+        self.source = PartialLayout()
+        self.build = PartialLayout()
+        self.package = PartialLayout()
 
 
 class Folders(object):


Test patch:
diff --git a/conans/test/integration/editable/test_editable_envvars.py b/conans/test/integration/editable/test_editable_envvars.py
index 81fe645a2..f98658099 100644
--- a/conans/test/integration/editable/test_editable_envvars.py
+++ b/conans/test/integration/editable/test_editable_envvars.py
@@ -10,11 +10,19 @@ def test_editable_envvars():
     dep = textwrap.dedent("""
         from conan import ConanFile
         class Dep(ConanFile):
+            name = "dep"
+            version = "1.0"
             def layout(self):
                 self.folders.source = "mysource"
                 self.folders.build = "mybuild"
-                self.cpp.source.runenv_info.append_path("MYRUNPATH", "mylocalsrc")
-                self.cpp.build.buildenv_info.define_path("MYBUILDPATH", "mylocalbuild")
+                self.layouts.source.runenv_info.append_path("MYRUNPATH", "mylocalsrc")
+                self.layouts.build.buildenv_info.define_path("MYBUILDPATH", "mylocalbuild")
+
+                self.layouts.package.buildenv_info.define_path("MYBUILDPATH", "mypkgbuild")
+                self.layouts.package.runenv_info.append_path("MYRUNTPATH", "mypkgsrc")
+
+            def package_info(self):
+                self.buildenv_info.define("OTHERVAR", "randomvalue")
         """)
 
     c.save({"dep/conanfile.py": dep,
@@ -27,10 +35,24 @@ def test_editable_envvars():
     build_path = os.path.join(c.current_folder, "dep", "mybuild", "mylocalbuild")
     buildenv = c.load("conanbuildenv.sh")
     assert f'export MYBUILDPATH="{build_path}"' in buildenv
+    # The package_info() buildenv is aggregated, no prob
+    # But don't use same vars
+    assert 'export OTHERVAR="randomvalue"' in buildenv
     runenv = c.load("conanrunenv.sh")
     run_path = os.path.join(c.current_folder, "dep", "mysource", "mylocalsrc")
     assert f'export MYRUNPATH="$MYRUNPATH:{run_path}"' in runenv
 
+    c.run("editable remove dep/1.0")
+    c.run("create dep")
+    c.run("install pkg -s os=Linux -s:b os=Linux")
+    buildenv = c.load("conanbuildenv.sh")
+    assert 'mypkgbuild' in buildenv
+    assert "mylocalbuild" not in buildenv
+    assert 'export OTHERVAR="randomvalue"' in buildenv
+    runenv = c.load("conanrunenv.sh")
+    assert 'mypkgsrc' in runenv
+    assert "mylocalsrc" not in runenv
+
 
 def test_editable_conf():
     c = TestClient()
@@ -41,10 +63,10 @@ def test_editable_conf():
             def layout(self):
                 self.folders.source = "mysource"
                 self.folders.build = "mybuild"
-                self.cpp.source.conf_info.append_path("myconf", "mylocalsrc")
-                self.cpp.build.conf_info.append_path("myconf", "mylocalbuild")
-                self.cpp.build.conf_info.update_path("mydictconf", {"a": "mypatha", "b": "mypathb"})
-                self.cpp.build.conf_info.define_path("mydictconf2", {"c": "mypathc"})
+                self.layouts.source.conf_info.append_path("myconf", "mylocalsrc")
+                self.layouts.build.conf_info.append_path("myconf", "mylocalbuild")
+                self.layouts.build.conf_info.update_path("mydictconf", {"a": "mypatha", "b": "mypathb"})
+                self.layouts.build.conf_info.define_path("mydictconf2", {"c": "mypathc"})
         """)
 
     pkg = textwrap.dedent("""
diff --git a/conans/test/unittests/tools/cmake/test_cmaketoolchain.py b/conans/test/unittests/tools/cmake/test_cmaketoolchain.py
index 2b9670452..d66be8732 100644
--- a/conans/test/unittests/tools/cmake/test_cmaketoolchain.py
+++ b/conans/test/unittests/tools/cmake/test_cmaketoolchain.py
@@ -490,3 +490,18 @@ def test_variables_types(conanfile):
 
     contents = load(os.path.join(conanfile.generators_folder, "conan_toolchain.cmake"))
     assert 'set(FOO ON CACHE BOOL "Variable FOO conan-toolchain defined")' in contents
+
+
+def test_compilers_block(conanfile):
+    cmake_mapping = {"c": "C", "cuda": "CUDA", "cpp": "CXX", "objc": "OBJC",
+                     "objcpp": "OBJCXX", "rc": "RC", 'fortran': "Fortran", 'asm': "ASM",
+                     "hip": "HIP", "ispc": "ISPC"}
+    compilers = {"c": "path_to_c", "cuda": "path_to_cuda", "cpp": "path_to_cpp",
+                 "objc": "path_to_objc", "objcpp": "path_to_objcpp", "rc": "path_to_rc",
+                 'fortran': "path_to_fortran", 'asm': "path_to_asm", "hip": "path_to_hip",
+                 "ispc": "path_to_ispc"}
+    conanfile.conf.define("tools.build:compiler_executables", compilers)
+    toolchain = CMakeToolchain(conanfile)
+    content = toolchain.content
+    for compiler, lang in cmake_mapping.items():
+        assert f'set(CMAKE_{lang}_COMPILER "path_to_{compiler}")' in content
diff --git a/conans/test/unittests/tools/gnu/autotoolschain_test.py b/conans/test/unittests/tools/gnu/autotoolschain_test.py
index b632170f4..8141dc8c8 100644
--- a/conans/test/unittests/tools/gnu/autotoolschain_test.py
+++ b/conans/test/unittests/tools/gnu/autotoolschain_test.py
@@ -2,6 +2,7 @@ import pytest
 
 from conan.tools.gnu import AutotoolsToolchain
 from conans.errors import ConanException
+from conans.model.conf import Conf
 from conans.test.utils.mocks import ConanFileMock, MockSettings
 
 
@@ -90,3 +91,20 @@ def test_get_gnu_triplet_for_cross_building_raise_error():
         msg = "'compiler' parameter for 'get_gnu_triplet()' is not specified and " \
               "needed for os=Windows"
         assert msg == str(conan_error.value)
+
+
+def test_compilers_mapping():
+    autotools_mapping = {"c": "CC", "cpp": "CXX", "cuda": "NVCC", "fortran": "FC"}
+    compilers = {"c": "path_to_c", "cpp": "path_to_cpp", "cuda": "path_to_cuda",
+                 "fortran": "path_to_fortran"}
+    settings = MockSettings({"build_type": "Release",
+                             "os": "Windows",
+                             "arch": "x86_64"})
+    conanfile = ConanFileMock()
+    conanfile.conf = Conf()
+    conanfile.conf.define("tools.build:compiler_executables", compilers)
+    conanfile.settings = settings
+    autotoolschain = AutotoolsToolchain(conanfile)
+    env = autotoolschain.environment().vars(conanfile)
+    for compiler, env_var in autotools_mapping.items():
+        assert env[env_var] == f"path_to_{compiler}"