Repository: conan-io/conan

Issue:
PROFILE_DIR with forward slashes
hi there,
I want to use the ```PROFILE_DIR``` variable in my profiles to access a path relative to the value of that variable. Now I do cross-compiling with a compiler that cannot parse backslashes.

An example yaml like this:
```yaml
[env]
ABC=$PROFILE_DIR/path/abc
```
will result in a malformed path as the compiler tries to interpret the slashes as excape characters:
compiler parsed: ... C:UsersNAME.conanprofiles/path/abc ...

Would it be possible to provide an POSIX style path (like PROFILE_DIR_POSIX)?


Discussion:
Hi! thanks for reporting.
Yes, I think we should try to convert the `$PROFILE_DIR` to `/`. I prefer it rather than maintaining two vars. It shouldn't break to any other user, but if it happens we will think what to do.

Resolving patch:
diff --git a/conans/client/profile_loader.py b/conans/client/profile_loader.py
--- a/conans/client/profile_loader.py
+++ b/conans/client/profile_loader.py
@@ -130,7 +130,7 @@ def _load_profile(text, profile_path, default_folder):
 
         # Apply the automatic PROFILE_DIR variable
         if cwd:
-            inherited_vars["PROFILE_DIR"] = os.path.abspath(cwd)
+            inherited_vars["PROFILE_DIR"] = os.path.abspath(cwd).replace('\\', '/')
             # Allows PYTHONPATH=$PROFILE_DIR/pythontools
 
         # Replace the variables from parents in the current profile
@@ -144,7 +144,7 @@ def _load_profile(text, profile_path, default_folder):
         # Merge the inherited profile with the readed from current profile
         _apply_inner_profile(doc, inherited_profile)
 
-        # Return the intherited vars to apply them in the parent profile if exists
+        # Return the inherited vars to apply them in the parent profile if exists
         inherited_vars.update(profile_parser.vars)
         return inherited_profile, inherited_vars
 


Test patch:
diff --git a/conans/test/unittests/client/profile_loader/profile_loader_test.py b/conans/test/unittests/client/profile_loader/profile_loader_test.py
--- a/conans/test/unittests/client/profile_loader/profile_loader_test.py
+++ b/conans/test/unittests/client/profile_loader/profile_loader_test.py
@@ -307,8 +307,10 @@ def save_profile(txt, name):
 
         profile, variables = read_profile("./profile4.txt", tmp, None)
 
-        self.assertEqual(variables, {"MYVAR": "1", "OTHERVAR": "34", "PROFILE_DIR":
-                                      tmp, "ROOTVAR": "0"})
+        self.assertEqual(variables, {"MYVAR": "1",
+                                     "OTHERVAR": "34",
+                                     "PROFILE_DIR": tmp.replace('\\', '/'),
+                                     "ROOTVAR": "0"})
         self.assertEqual("FromProfile3And34", profile.env_values.data[None]["MYVAR"])
         self.assertEqual("1", profile.env_values.data["package1"]["ENVY"])
         self.assertEqual(profile.settings, {"os": "1"})
@@ -325,8 +327,8 @@ def profile_dir_test(self):
 '''
 
         def assert_path(profile):
-            pythonpath = profile.env_values.env_dicts("")[0]["PYTHONPATH"].replace("/", "\\")
-            self.assertEqual(pythonpath, os.path.join(tmp, "my_python_tools").replace("/", "\\"))
+            pythonpath = profile.env_values.env_dicts("")[0]["PYTHONPATH"]
+            self.assertEqual(pythonpath, os.path.join(tmp, "my_python_tools").replace('\\', '/'))
 
         abs_profile_path = os.path.join(tmp, "Myprofile.txt")
         save(abs_profile_path, txt)