Repository: conan-io/conan

Issue:
Environment variable to set [general]default_profile 
To help us debug your issue please explain:

- [x] I've read the [CONTRIBUTING guide](https://raw.githubusercontent.com/conan-io/conan/develop/.github/CONTRIBUTING.md).
- [ ] I've specified the Conan version, operating system version and any tool that can be relevant.
- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.

This idea was initially proposed at https://github.com/conan-io/conan/issues/1221#issuecomment-403961457

It would be nice if there was an environment variable (perhaps `CONAN_DEFAULT_PROFILE`?) which, if set, would override `[general]default_profile` from `conan.conf `. In an IDE workflow, a project file might be set up to obtain its own dependencies by calling `conan install` (e.g. https://github.com/conan-io/cmake-conan), but it feels wrong to hard-code a desired profile into the call to conan install. Most project systems like this support multiple configurations (e.g. Qt Creator has [kits](http://doc.qt.io/qtcreator/creator-configuring-projects.html), MSVC supports setting up multiple configurations. conan_cmake_settings(...) makes an effort to reverse-engineer the settings from the compiler detection variables, but it's not particularly complete, and in any case a sophisticated profile might have content (e.g. build_requires for toolchains) arguably could never get in this fashion. 

IDE features to define a build template like this usually have a mechanism to add environment variables to the build invocation, and a way to set the default profile through the environment seems consistent with the existing ability to override specific settings from it using [CONAN_ENV_XXXX_YYYY](https://docs.conan.io/en/latest/reference/env_vars.html#conan-env-xxxx-yyyy).





Discussion:
Should be an easy to implement feature, something like:

````python
"CONAN_BASH_PATH": self._env_c("general.bash_path", "CONAN_BASH_PATH", None),
``` 

in ``ConanClientConfigParser``

Resolving patch:
diff --git a/conans/client/conf/__init__.py b/conans/client/conf/__init__.py
--- a/conans/client/conf/__init__.py
+++ b/conans/client/conf/__init__.py
@@ -287,10 +287,20 @@ def get_conf(self, varname):
 
     @property
     def default_profile(self):
-        try:
-            return self.get_item("general.default_profile")
-        except ConanException:
-            return DEFAULT_PROFILE_NAME
+        ret = os.environ.get("CONAN_DEFAULT_PROFILE_PATH", None)
+        if ret:
+            if not os.path.isabs(ret):
+                raise ConanException("Environment variable 'CONAN_DEFAULT_PROFILE_PATH' must point "
+                                     "to an absolute path.")
+            if not os.path.exists(ret):
+                raise ConanException("Environment variable 'CONAN_DEFAULT_PROFILE_PATH' must point to "
+                                     "an existing profile file.")
+            return ret
+        else:
+            try:
+                return unquote(self.get_item("general.default_profile"))
+            except ConanException:
+                return DEFAULT_PROFILE_NAME
 
     @property
     def cache_no_locks(self):
diff --git a/conans/client/migrations.py b/conans/client/migrations.py
--- a/conans/client/migrations.py
+++ b/conans/client/migrations.py
@@ -122,18 +122,6 @@ def _make_migrations(self, old_version):
                 migrate_c_src_export_source(self.client_cache, self.out)
 
 
-def _add_build_cross_settings(client_cache, out):
-    out.warn("Migration: Adding `os_build` and `arch_build` to default settings")
-    try:
-        default_profile = client_cache.default_profile
-        default_profile.settings["arch_build"] = default_profile.settings["arch"]
-        default_profile.settings["os_build"] = default_profile.settings["os"]
-        save(client_cache.default_profile_path, default_profile.dumps())
-    except Exception:
-        out.error("Something went wrong adding 'os_build' and 'arch_build' to your default."
-                  " You can add it manually adjusting them with the same value as 'os' and 'arch'")
-
-
 def _migrate_lock_files(client_cache, out):
     out.warn("Migration: Removing old lock files")
     base_dir = client_cache.store


Test patch:
diff --git a/conans/test/functional/default_profile_test.py b/conans/test/functional/default_profile_test.py
--- a/conans/test/functional/default_profile_test.py
+++ b/conans/test/functional/default_profile_test.py
@@ -6,6 +6,7 @@
 from conans.test.utils.test_files import temp_folder
 from conans.test.utils.tools import TestClient
 from conans.util.files import save
+from conans import tools
 
 
 class DefaultProfileTest(unittest.TestCase):
@@ -129,3 +130,48 @@ def build(self):
         client.save({CONANFILE: cf % "23"}, clean_first=True)
         client.run("export . lasote/stable")
         client.run('install mypackage/0.1@lasote/stable --build missing')
+
+    def test_env_default_profile(self):
+        conanfile = '''
+import os
+from conans import ConanFile
+
+class MyConanfile(ConanFile):
+
+    def build(self):
+        self.output.info(">>> env_variable={}".format(os.environ.get('env_variable'))) 
+'''
+
+        client = TestClient()
+        client.save({CONANFILE: conanfile})
+
+        # Test with the 'default' profile
+        env_variable = "env_variable=profile_default"
+        save(client.client_cache.default_profile_path, "[env]\n" + env_variable)
+        client.run("create . name/version@user/channel")
+        self.assertIn(">>> " + env_variable, client.out)
+
+        # Test with a profile set using and environment variable
+        tmp = temp_folder()
+        env_variable = "env_variable=profile_environment"
+        default_profile_path = os.path.join(tmp, 'env_profile')
+        save(default_profile_path, "[env]\n" + env_variable)
+        with tools.environment_append({'CONAN_DEFAULT_PROFILE_PATH': default_profile_path}):
+            client.run("create . name/version@user/channel")
+            self.assertIn(">>> " + env_variable, client.out)
+
+        # Use relative path defined in environment variable
+        with tools.environment_append({'CONAN_DEFAULT_PROFILE_PATH': '../whatever'}):
+            client.run("create . name/version@user/channel", ignore_error=True)
+            self.assertIn("Environment variable 'CONAN_DEFAULT_PROFILE_PATH' must point to "
+                          "an absolute path", client.out)
+
+        # Use non existing path
+        profile_path = os.path.join(tmp, "this", "is", "a", "path")
+        self.assertTrue(os.path.isabs(profile_path))
+        with tools.environment_append({'CONAN_DEFAULT_PROFILE_PATH': profile_path}):
+            client.run("create . name/version@user/channel", ignore_error=True)
+            self.assertIn("Environment variable 'CONAN_DEFAULT_PROFILE_PATH' must point to "
+                          "an existing profile file.", client.out)
+
+