Repository: conan-io/conan

Issue:
[Bug] Error on editable package if 'build_folder' is in layout file
Since the arrival of workspaces, a layout file can contain a `build_folder` section. Nevertheless, this layout fails if used with an editable package (not inside a workspace). Test provided by @lasote ([source](https://github.com/conan-io/conan/compare/develop...lasote:test/graph_info_crash?expand=1)):

```python
    def test_editable_crash(self):
        ref = ConanFileReference.loads("lib/1.0@conan/stable")
        client = TurboTestClient()
        client.create(ref)
        save(os.path.join(client.current_folder, "mylayout"),
             textwrap.dedent("""
                [build_folder]
                build
                """))
        client.run("editable add . {} --layout mylayout".format(ref))
        client.change_to_clean_folder()
        ref2 = ConanFileReference.loads("lib2/1.0@conan/stable")
        conanfile2 = GenConanfile().with_requirement(ref)
        client.create(ref2, conanfile=conanfile2)
```

The problem is that we get to the `BinaryInstaller::_handle_node_editable` function without a `graph_info`, but with a `build_folder` in the layout:

```python
def _handle_node_editable(self, node, graph_info):
    ...
    if build_folder is not None:
        ...
        graph_info.save(build_folder)
```





Discussion:

Patch:
diff --git a/conans/client/cmd/uploader.py b/conans/client/cmd/uploader.py
index 820d4bcb7..22ed4ded6 100644
--- a/conans/client/cmd/uploader.py
+++ b/conans/client/cmd/uploader.py
@@ -505,6 +505,7 @@ def compress_files(files, symlinks, name, dest_dir, output=None):
             info = tarfile.TarInfo(name=filename)
             info.type = tarfile.SYMTYPE
             info.linkname = dest
+            info.size = 0  # A symlink shouldn't have size
             tgz.addfile(tarinfo=info)
 
         mask = ~(stat.S_IWOTH | stat.S_IWGRP)
@@ -519,6 +520,7 @@ def compress_files(files, symlinks, name, dest_dir, output=None):
             info.mode = os.stat(abs_path).st_mode & mask
             if os.path.islink(abs_path):
                 info.type = tarfile.SYMTYPE
+                info.size = 0  # A symlink shouldn't have size
                 info.linkname = os.readlink(abs_path)  # @UndefinedVariable
                 tgz.addfile(tarinfo=info)
             else:
diff --git a/conans/client/graph/graph_builder.py b/conans/client/graph/graph_builder.py
index ab00a32ed..936a129da 100644
--- a/conans/client/graph/graph_builder.py
+++ b/conans/client/graph/graph_builder.py
@@ -150,6 +150,9 @@ class DepsGraphBuilder(object):
             new_node.inverse_closure.add(node)
             node.public_deps[new_node.name] = new_node
 
+            # If the parent node is a build-require, this new node will be a build-require
+            # If the requirement is a build-require, this node will also be a build-require
+            new_node.build_require = node.build_require or require.build_require
             # New nodes will inherit the private property of its ancestor
             new_node.private = node.private or require.private
             if require.private or require.build_require:
diff --git a/conans/client/installer.py b/conans/client/installer.py
index 5aba8faee..14ed46b0a 100644
--- a/conans/client/installer.py
+++ b/conans/client/installer.py
@@ -421,7 +421,7 @@ class BinaryInstaller(object):
         assert pref.id, "Package-ID without value"
 
         # It is necessary to complete the sources of python requires, which might be used
-        for name, python_require in conanfile.python_requires.items():
+        for python_require in conanfile.python_requires.values():
             assert python_require.ref.revision is not None, \
                 "Installer should receive python_require.ref always"
             complete_recipe_sources(self._remote_manager, self._cache,
diff --git a/conans/client/manager.py b/conans/client/manager.py
index 98fa6742c..d6f10eb13 100644
--- a/conans/client/manager.py
+++ b/conans/client/manager.py
@@ -77,7 +77,7 @@ class ConanManager(object):
         installer = BinaryInstaller(self._cache, self._user_io.out, self._remote_manager,
                                     recorder=self._recorder,
                                     hook_manager=self._hook_manager)
-        installer.install(deps_graph, remotes, keep_build=keep_build)
+        installer.install(deps_graph, remotes, keep_build=keep_build, graph_info=graph_info)
 
         if manifest_folder:
             manifest_manager = ManifestManager(manifest_folder, user_io=self._user_io,
diff --git a/conans/client/tools/oss.py b/conans/client/tools/oss.py
index cb46d19dc..32065dbbf 100644
--- a/conans/client/tools/oss.py
+++ b/conans/client/tools/oss.py
@@ -323,13 +323,14 @@ class OSInfo(object):
         if "cygwin" in output:
             return CYGWIN
         elif "msys" in output or "mingw" in output:
-            output = OSInfo.uname("-r")
-            if output.startswith("2"):
-                return MSYS2
-            elif output.startswith("1"):
-                return MSYS
-            else:
-                return None
+            version = OSInfo.uname("-r").split('.')
+            if version and version[0].isdigit():
+                major = int(version[0])
+                if major == 1:
+                    return MSYS
+                elif major >= 2:
+                    return MSYS2
+            return None
         elif "linux" in output:
             return WSL
         else:


Test patch:
diff --git a/conans/test/functional/build_requires/build_requires_test.py b/conans/test/functional/build_requires/build_requires_test.py
index 763873309..a2e3e8b02 100644
--- a/conans/test/functional/build_requires/build_requires_test.py
+++ b/conans/test/functional/build_requires/build_requires_test.py
@@ -6,6 +6,7 @@ from parameterized.parameterized import parameterized
 from conans.paths import CONANFILE
 from conans.test.utils.tools import TestClient
 from conans.util.files import load
+from conans.test.utils.conanfile import TestConanFile
 
 tool_conanfile = """from conans import ConanFile
 
@@ -50,6 +51,20 @@ nonexistingpattern*: SomeTool/1.2@user/channel
 
 
 class BuildRequiresTest(unittest.TestCase):
+    def test_build_requires_diamond(self):
+        t = TestClient()
+        t.save({"conanfile.py": str(TestConanFile("libA", "0.1"))})
+        t.run("create . libA/0.1@user/testing")
+
+        t.save({"conanfile.py": str(TestConanFile("libB", "0.1",
+                                                  requires=["libA/0.1@user/testing"]))})
+        t.run("create . libB/0.1@user/testing")
+
+        t.save({"conanfile.py": str(TestConanFile("libC", "0.1",
+                                                  build_requires=["libB/0.1@user/testing",
+                                                                  "libA/0.1@user/testing"]))})
+        t.run("create . libC/0.1@user/testing")
+        self.assertIn("libC/0.1@user/testing: Created package", t.out)
 
     def create_with_tests_and_build_requires_test(self):
         client = TestClient()
diff --git a/conans/test/functional/configuration/compressed_symlinks_test.py b/conans/test/functional/configuration/compressed_symlinks_test.py
new file mode 100644
index 000000000..f93ff3007
--- /dev/null
+++ b/conans/test/functional/configuration/compressed_symlinks_test.py
@@ -0,0 +1,53 @@
+import os
+import platform
+import unittest
+
+from conans.model.ref import ConanFileReference
+from conans.test.utils.tools import TestServer, TurboTestClient
+
+
+class CompressSymlinksZeroSize(unittest.TestCase):
+
+    @unittest.skipIf(platform.system() != "Linux", "Only linux")
+    def test_package_symlinks_zero_size(self):
+        server = TestServer()
+        client = TurboTestClient(servers={"default": server})
+
+        conanfile = """
+import os
+from conans import ConanFile, tools
+
+class HelloConan(ConanFile):
+
+    def package(self):
+        # Link to file.txt and then remove it
+        tools.save(os.path.join(self.package_folder, "file.txt"), "contents")
+        os.symlink("file.txt", os.path.join(self.package_folder, "link.txt"))    
+"""
+        ref = ConanFileReference.loads("lib/1.0@conan/stable")
+        # By default it is not allowed
+        pref = client.create(ref, conanfile=conanfile)
+        # Upload, it will create the tgz
+        client.upload_all(ref)
+
+        # We can uncompress it without warns
+        p_folder = client.cache.package_layout(pref.ref).package(pref)
+        tgz = os.path.join(p_folder, "conan_package.tgz")
+        client.run_command('gzip -d "{}"'.format(tgz))
+        client.run_command('tar tvf "{}"'.format(os.path.join(p_folder, "conan_package.tar")))
+        lines = str(client.out).splitlines()
+        """
+-rw-r--r-- 0/0               8 1970-01-01 01:00 file.txt
+lrw-r--r-- 0/0               0 1970-01-01 01:00 link.txt -> file.txt
+        """
+
+        self.assertIn("link.txt", " ".join(lines))
+        for line in lines:
+            if ".txt" not in line:
+                continue
+
+            size = int([i for i in line.split(" ") if i][2])
+            if "link.txt" in line:
+                self.assertEqual(int(size), 0)
+            elif "file.txt":
+                self.assertGreater(int(size), 0)
diff --git a/conans/test/functional/editable/layouts_test.py b/conans/test/functional/editable/layouts_test.py
index a06bd84c2..e42e1ce74 100644
--- a/conans/test/functional/editable/layouts_test.py
+++ b/conans/test/functional/editable/layouts_test.py
@@ -6,6 +6,8 @@ import textwrap
 import unittest
 
 from conans.model.editable_layout import LAYOUTS_FOLDER
+from conans.model.ref import ConanFileReference
+from conans.test.utils.conanfile import TestConanFile
 from conans.test.utils.test_files import temp_folder
 from conans.test.utils.tools import TestClient
 from conans.util.files import load, save_files, save
@@ -13,6 +15,23 @@ from conans.util.files import load, save_files, save
 
 class LayoutTest(unittest.TestCase):
 
+    def test_editable_crash(self):
+        ref = ConanFileReference.loads("lib/1.0@conan/stable")
+        client = TestClient()
+        layout = textwrap.dedent("""
+                    [build_folder]
+                    build
+                    """)
+        client.save({"conanfile.py": TestConanFile("lib", "1.0"),
+                     "mylayout": layout})
+        client.run("editable add . {} --layout mylayout".format(ref))
+        client2 = TestClient(base_folder=client.base_folder)
+        client2.save({"conanfile.py": TestConanFile("app", "1.0",
+                                                    requires=["lib/1.0@conan/stable"])})
+        client2.run("create . user/testing")
+        graph_info = os.path.join(client.current_folder, "build", "graph_info.json")
+        self.assertTrue(os.path.exists(graph_info))
+
     def test_missing_wrong_layouts(self):
         client = TestClient()
         conanfile = textwrap.dedent("""
@@ -202,7 +221,8 @@ class LayoutTest(unittest.TestCase):
         client2.run("install . -g cmake -s build_type=Debug", assert_error=True)
         self.assertIn("ERROR: Error parsing layout file '{}' (for reference "
                       "'mytool/0.1@user/testing')\n'settings.build_type' doesn't exist".format(
-            os.path.join(client.current_folder, 'layout')), client2.out)
+                          os.path.join(client.current_folder, 'layout')),
+                      client2.out)
 
         # Now add settings to conanfile
         client.save({"conanfile.py": conanfile.replace("pass", 'settings = "build_type"')})
diff --git a/conans/test/functional/graph/graph_manager_test.py b/conans/test/functional/graph/graph_manager_test.py
index b1d7b034d..3b0ac9c24 100644
--- a/conans/test/functional/graph/graph_manager_test.py
+++ b/conans/test/functional/graph/graph_manager_test.py
@@ -769,7 +769,7 @@ class TransitiveGraphTest(GraphManagerTest):
         self._check_node(liba2, "liba/0.2@user/testing#123", deps=[], build_deps=[],
                          dependents=[libc], closure=[])
 
-    def consecutive_private(self):
+    def test_consecutive_private(self):
         liba_ref = "liba/0.1@user/testing"
         libb_ref = "libb/0.1@user/testing"
         libc_ref = "libc/0.1@user/testing"
diff --git a/conans/test/unittests/client/tools/os_info/osinfo_test.py b/conans/test/unittests/client/tools/os_info/osinfo_test.py
index b361fcd99..13262a4d0 100644
--- a/conans/test/unittests/client/tools/os_info/osinfo_test.py
+++ b/conans/test/unittests/client/tools/os_info/osinfo_test.py
@@ -76,6 +76,23 @@ class OSInfoTest(unittest.TestCase):
                     self.assertEqual(OSInfo.uname(), self._uname.lower())
                     self.assertEqual(OSInfo.detect_windows_subsystem(), MSYS)
 
+    def test_msys3(self):
+        self._uname = 'MSYS_NT-10.0'
+        self._version = '3.0.6(0.338/5/3)'
+        with mock.patch("platform.system", mock.MagicMock(return_value=self._uname)):
+            self.assertTrue(OSInfo().is_windows)
+            self.assertFalse(OSInfo().is_cygwin)
+            self.assertTrue(OSInfo().is_msys)
+            self.assertFalse(OSInfo().is_linux)
+            self.assertFalse(OSInfo().is_freebsd)
+            self.assertFalse(OSInfo().is_macos)
+            self.assertFalse(OSInfo().is_solaris)
+
+            with environment_append({"CONAN_BASH_PATH": "/fake/bash.exe"}):
+                with mock.patch('conans.client.tools.oss.check_output', new=self.subprocess_check_output_mock):
+                    self.assertEqual(OSInfo.uname(), self._uname.lower())
+                    self.assertEqual(OSInfo.detect_windows_subsystem(), MSYS2)
+
     def test_mingw32(self):
         self._uname = 'MINGW32_NT-10.0'
         self._version = '2.10.0(0.325/5/3)'
diff --git a/conans/test/utils/tools.py b/conans/test/utils/tools.py
index faab494c6..6a4b7b773 100644
--- a/conans/test/utils/tools.py
+++ b/conans/test/utils/tools.py
@@ -848,7 +848,7 @@ servers["r2"] = TestServer()
 
     def run_command(self, command):
         self.all_output += str(self.out)
-        self.init_dynamic_vars() # Resets the output
+        self.init_dynamic_vars()  # Resets the output
         return self.runner(command, cwd=self.current_folder)
 
     def save(self, files, path=None, clean_first=False):
@@ -858,6 +858,7 @@ servers["r2"] = TestServer()
         path = path or self.current_folder
         if clean_first:
             shutil.rmtree(self.current_folder, ignore_errors=True)
+        files = {f: str(content) for f, content in files.items()}
         save_files(path, files)
         if not files:
             mkdir(self.current_folder)