Repository: conan-io/conan

Issue:
[Bug] conan export-pkg has seemingly all values from profile propagated with the exception of CONAN_CMAKE_GENERATOR
When I want to export to local cache from a local source dir, I first run the setup commands and build my project
```
conan install . -if=build -pr=myprofile
conan build . -sf=. -bf=build
```
then when I run *either* of these commands the wrong generator is used
```
conan export-pkg . user/channel -sf=. -bf=build -f
conan export-pkg . user/channel -sf=. -bf=build -pr=myprofile -f
```
Looking at the `command` variable at line 195 in the cmake.py cmake helper class, the command given to cmake is exactly the same for both versions of `export-pkg` above. The cmake command value is how I expect it to be with the exception of that the generator given in the profile is not respected, but uses the default given in conan.conf. If no default in conan.conf is given it defaults back to MinGW Makefiles.  

A workaround is to set the correct generator as default in conan.conf. But this can only be temporary as projects sometimes includes C# so a mix of generators is to be used.

Discussion:

Patch:
diff --git a/conans/client/cmd/export_pkg.py b/conans/client/cmd/export_pkg.py
index ec493de6e..ca7146db2 100644
--- a/conans/client/cmd/export_pkg.py
+++ b/conans/client/cmd/export_pkg.py
@@ -6,6 +6,7 @@ from conans.errors import ConanException
 from conans.model.manifest import FileTreeManifest
 from conans.model.ref import PackageReference
 from conans.util.files import rmdir
+from conans.model.conan_file import get_env_context_manager
 
 
 def export_pkg(cache, graph_manager, hook_manager, recorder, output,
@@ -20,7 +21,8 @@ def export_pkg(cache, graph_manager, hook_manager, recorder, output,
     # to be downloaded from remotes
     deps_graph, _ = graph_manager.load_graph(ref, None, graph_info=graph_info, build_mode=[ref.name],
                                              check_updates=False, update=False,
-                                             remote_name=None, recorder=recorder)
+                                             remote_name=None, recorder=recorder,
+                                             apply_build_requires=False)
     # this is a bit tricky, but works. The root (virtual), has only 1 neighbor,
     # which is the exported pkg
     nodes = deps_graph.root.neighbors()
@@ -47,9 +49,10 @@ def export_pkg(cache, graph_manager, hook_manager, recorder, output,
         packager.export_pkg(conanfile, package_id, package_folder, dest_package_folder,
                             hook_manager, conan_file_path, ref)
     else:
-        packager.create_package(conanfile, package_id, source_folder, build_folder,
-                                dest_package_folder, install_folder, hook_manager, conan_file_path,
-                                ref, local=True)
+        with get_env_context_manager(conanfile):
+            packager.create_package(conanfile, package_id, source_folder, build_folder,
+                                    dest_package_folder, install_folder, hook_manager,
+                                    conan_file_path, ref, local=True)
     with cache.package_layout(ref).update_metadata() as metadata:
         readed_manifest = FileTreeManifest.load(dest_package_folder)
         metadata.packages[package_id].revision = readed_manifest.summary_hash
diff --git a/conans/client/graph/graph_manager.py b/conans/client/graph/graph_manager.py
index 645e30027..64c39fc98 100644
--- a/conans/client/graph/graph_manager.py
+++ b/conans/client/graph/graph_manager.py
@@ -90,7 +90,7 @@ class GraphManager(object):
         return conanfile
 
     def load_graph(self, reference, create_reference, graph_info, build_mode, check_updates, update,
-                   remote_name, recorder):
+                   remote_name, recorder, apply_build_requires=True):
 
         def _inject_require(conanfile, ref):
             """ test_package functionality requires injecting the tested package as requirement
@@ -145,7 +145,8 @@ class GraphManager(object):
                                       build_mode=build_mode, remote_name=remote_name,
                                       profile_build_requires=profile.build_requires,
                                       recorder=recorder,
-                                      processed_profile=processed_profile)
+                                      processed_profile=processed_profile,
+                                      apply_build_requires=apply_build_requires)
 
         # THIS IS NECESSARY to store dependencies options in profile, for consumer
         # FIXME: This is a hack. Might dissapear if the graph for local commands is always recomputed
@@ -172,11 +173,12 @@ class GraphManager(object):
         return conanfile.build_requires
 
     def _recurse_build_requires(self, graph, builder, binaries_analyzer, check_updates, update,
-                                build_mode, remote_name,
-                                profile_build_requires, recorder, processed_profile):
+                                build_mode, remote_name, profile_build_requires, recorder,
+                                processed_profile, apply_build_requires=True):
 
         binaries_analyzer.evaluate_graph(graph, build_mode, update, remote_name)
-
+        if not apply_build_requires:
+            return
         for node in graph.ordered_iterate():
             # Virtual conanfiles doesn't have output, but conanfile.py and conanfile.txt do
             # FIXME: To be improved and build a explicit model for this
@@ -224,7 +226,7 @@ class GraphManager(object):
                 graph.nodes.update(subgraph.nodes)
 
     def _load_graph(self, root_node, check_updates, update, build_mode, remote_name,
-                    profile_build_requires, recorder, processed_profile):
+                    profile_build_requires, recorder, processed_profile, apply_build_requires):
 
         assert isinstance(build_mode, BuildMode)
         builder = DepsGraphBuilder(self._proxy, self._output, self._loader, self._resolver,
@@ -235,7 +237,8 @@ class GraphManager(object):
 
         self._recurse_build_requires(graph, builder, binaries_analyzer, check_updates, update,
                                      build_mode, remote_name,
-                                     profile_build_requires, recorder, processed_profile)
+                                     profile_build_requires, recorder, processed_profile,
+                                     apply_build_requires=apply_build_requires)
 
         # Sort of closures, for linking order
         inverse_levels = {n: i for i, level in enumerate(graph.inverse_levels()) for n in level}


Test patch:
diff --git a/conans/test/functional/command/export_pkg_test.py b/conans/test/functional/command/export_pkg_test.py
index dbde9c941..32654bd50 100644
--- a/conans/test/functional/command/export_pkg_test.py
+++ b/conans/test/functional/command/export_pkg_test.py
@@ -8,31 +8,36 @@ from parameterized import parameterized
 from conans.model.ref import ConanFileReference, PackageReference
 from conans.paths import CONANFILE
 from conans.test.utils.conanfile import TestConanFile
-from conans.test.utils.tools import NO_SETTINGS_PACKAGE_ID, TestClient, TestServer
+from conans.test.utils.tools import NO_SETTINGS_PACKAGE_ID, TestClient
 from conans.util.env_reader import get_env
 from conans.util.files import load, mkdir
+from textwrap import dedent
 
 
 class ExportPkgTest(unittest.TestCase):
 
     def test_dont_touch_server(self):
         # https://github.com/conan-io/conan/issues/3432
-        class RequesterMock(object):
-            def __init__(self, *args, **kwargs):
-                pass
-
-        # https://github.com/conan-io/conan/issues/3432
-        client = TestClient(servers={"default": TestServer()},
-                            requester_class=RequesterMock,
+        client = TestClient(servers={"default": None},
+                            requester_class=None,
                             users={"default": [("lasote", "mypass")]})
-        conanfile = """from conans import ConanFile
-class Pkg(ConanFile):
-    pass
-"""
-        client.save({"conanfile.py": conanfile})
+
+        client.save({"conanfile.py": str(TestConanFile("Pkg", "0.1"))})
         client.run("install .")
         client.run("export-pkg . Pkg/0.1@user/testing")
 
+    def test_dont_touch_server_build_require(self):
+        client = TestClient(servers={"default": None},
+                            requester_class=None,
+                            users={"default": [("lasote", "mypass")]})
+        profile = dedent("""
+            [build_requires]
+            some/other@pkg/notexists
+            """)
+        client.save({"conanfile.py": str(TestConanFile("Pkg", "0.1")),
+                     "myprofile": profile})
+        client.run("export-pkg . Pkg/0.1@user/testing -pr=myprofile")
+
     def test_transitive_without_settings(self):
         # https://github.com/conan-io/conan/issues/3367
         conanfile = """from conans import ConanFile
@@ -151,6 +156,25 @@ class HelloPythonConan(ConanFile):
         self.assertIn("optionOne: False", client.out)
         self.assertIn("optionOne: 123", client.out)
 
+    def test_profile_environment(self):
+        # https://github.com/conan-io/conan/issues/4832
+        conanfile = dedent("""
+            import os
+            from conans import ConanFile
+            class HelloPythonConan(ConanFile):
+                def package(self):
+                    self.output.info("ENV-VALUE: %s!!!" % os.getenv("MYCUSTOMVAR"))
+            """)
+        profile = dedent("""
+            [env]
+            MYCUSTOMVAR=MYCUSTOMVALUE
+            """)
+        client = TestClient()
+        client.save({CONANFILE: conanfile,
+                     "myprofile": profile})
+        client.run("export-pkg . Hello/0.1@lasote/stable -pr=myprofile")
+        self.assertIn("Hello/0.1@lasote/stable: ENV-VALUE: MYCUSTOMVALUE!!!", client.out)
+
     def test_options_install(self):
         # https://github.com/conan-io/conan/issues/2242
         conanfile = """from conans import ConanFile
@@ -385,7 +409,8 @@ class TestConan(ConanFile):
         # Partial reference is ok
         client.save({CONANFILE: conanfile, "file.txt": "txt contents"})
         client.run("export-pkg . conan/stable")
-        self.assertIn("Hello/0.1@conan/stable package(): Packaged 1 '.txt' file: file.txt", client.out)
+        self.assertIn("Hello/0.1@conan/stable package(): Packaged 1 '.txt' file: file.txt",
+                      client.out)
 
         # Specify different name or version is not working
         client.run("export-pkg . lib/1.0@conan/stable -f", assert_error=True)
diff --git a/conans/test/functional/generators/cmake_paths_test.py b/conans/test/functional/generators/cmake_paths_test.py
index dcd9f25dc..4b90a7036 100644
--- a/conans/test/functional/generators/cmake_paths_test.py
+++ b/conans/test/functional/generators/cmake_paths_test.py
@@ -28,7 +28,7 @@ class CMakePathsGeneratorTest(unittest.TestCase):
                    '${{CMAKE_PREFIX_PATH}} ${{CMAKE_CURRENT_LIST_DIR}})'
         if platform.system() != "Windows":
             expected = expected.replace("\r", "")
-        self.assertEquals(expected.format(pfolder1=pfolder1, pfolder2=pfolder2), contents)
+        self.assertEqual(expected.format(pfolder1=pfolder1, pfolder2=pfolder2), contents)
 
     def cmake_paths_integration_test(self):
         """First package with own findHello0.cmake file"""