Repository: conan-io/conan

Issue:
[question] How to erase values from one profile to the other
### What is your question?

Hello,

I created a reproducible case for the example : https://github.com/Todiq/test_conan

On windows, you just have to run `python build.py` with msvc & clang installed (VS or LLVM, does not matter).

Notice that during the first build (msvc), `Conan toolchain: C++ Standard 17 with extensions OFF` is displayed.

However, during the second one, the C++ standard is not set at all.

My guess is that I made a mistake when using `include(msvc)` in my `clang-windows` profile and that it breaks the set up of variables.

Could you please explain to me how to do it properly using the `include()` functionailty?

Thanks in advance!

### Have you read the CONTRIBUTING guide?

- [X] I've read the CONTRIBUTING guide


Discussion:
Hi @Todiq 

Thanks for your report.

This seems is not intended, a subtle bug in the profile inclusion resolution.
I am submitting a fix in https://github.com/conan-io/conan/pull/16720, hopefully for next 2.6 release.
https://github.com/conan-io/conan/pull/16720 was merged, it will be in next 2.6
Thanks for your quick reaction, as always!



Patch:
diff --git a/conan/internal/api/profile/profile_loader.py b/conan/internal/api/profile/profile_loader.py
index 6f6a83b81ab..8b36ef61f64 100644
--- a/conan/internal/api/profile/profile_loader.py
+++ b/conan/internal/api/profile/profile_loader.py
@@ -319,7 +319,10 @@ def load_replace(doc_replace_requires):
 
         base_profile.settings.update(settings)
         for pkg_name, values_dict in package_settings.items():
-            base_profile.package_settings[pkg_name].update(values_dict)
+            existing = base_profile.package_settings[pkg_name]
+            existing.update(values_dict)
+            # Make sure they are ordered, so `compiler=xxx` goes before `compiler.cppstd` always
+            base_profile.package_settings[pkg_name] = OrderedDict(sorted(existing.items()))
         for pattern, refs in tool_requires.items():
             # If the same package, different version is added, the latest version prevail
             current = base_profile.tool_requires.setdefault(pattern, [])


Test patch:
diff --git a/test/integration/configuration/test_profile_priority.py b/test/integration/configuration/test_profile_priority.py
index 3a18ae74ff4..5fb859766f8 100644
--- a/test/integration/configuration/test_profile_priority.py
+++ b/test/integration/configuration/test_profile_priority.py
@@ -76,3 +76,43 @@ def test_profile_cli_priority():
     assert "user.myconf:myvalue3={'3': '5', 'a': 'b'}" in c.out
     assert "user.myconf:myvalue4={'1': '2'}" in c.out
     assert "user.myconf:myvalue5={'6': '7'}" in c.out
+
+
+def test_profiles_patterns_include():
+    # https://github.com/conan-io/conan/issues/16718
+    c = TestClient()
+    msvc = textwrap.dedent("""
+        [settings]
+        compiler=msvc
+        compiler.cppstd=14
+        compiler.version=193
+        os=Windows
+
+        test*/*:compiler.cppstd=14
+        """)
+    clang = textwrap.dedent("""
+        include(./msvc)
+        [settings]
+        test*/*:compiler=clang
+        test*/*:compiler.cppstd=17
+        test*/*:compiler.runtime_version=v144
+        test*/*:compiler.version=18
+        """)
+    conanfile = textwrap.dedent("""
+        from conan import ConanFile
+        class Pkg(ConanFile):
+            name = "test_pkg"
+            version = "0.1"
+            settings = "os", "compiler"
+            def generate(self):
+                self.output.info(f"MyCompiler={self.settings.compiler}!!!")
+                self.output.info(f"MyCompilerVersion={self.settings.compiler.version}!!!")
+                self.output.info(f"MyCompilerCpp={self.settings.compiler.cppstd}!!!")
+            """)
+    c.save({"conanfile.py": conanfile,
+            "msvc": msvc,
+            "clang": clang})
+    c.run("install . -pr=clang")
+    assert "conanfile.py (test_pkg/0.1): MyCompiler=clang!!!" in c.out
+    assert "conanfile.py (test_pkg/0.1): MyCompilerVersion=18!!!" in c.out
+    assert "conanfile.py (test_pkg/0.1): MyCompilerCpp=17!!!" in c.out