Skip to content

Commit 72a1aa6

Browse files
committed
Fix Conan Source folders.root issue
- Fixed issue in local.py where source() method did not account for self.folders.root (when specified) - Added test/integration/command/source_test.py::SourceTest::test_local_source_layout_root Close #18376
1 parent a890941 commit 72a1aa6

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

conan/api/subapi/local.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ def source(self, path, name=None, version=None, user=None, channel=None, remotes
8282
with conanfile_exception_formatter(conanfile, "layout"):
8383
conanfile.layout()
8484

85-
folder = conanfile.recipe_folder
85+
folder = conanfile.recipe_folder if conanfile.folders.root is None else \
86+
os.path.normpath(os.path.join(conanfile.recipe_folder, conanfile.folders.root))
87+
8688
conanfile.folders.set_base_source(folder)
8789
conanfile.folders.set_base_export_sources(folder)
8890
conanfile.folders.set_base_recipe_metadata(os.path.join(folder, "metadata"))

test/integration/command/source_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,30 @@ def source(self):
142142
self.assertIn("conanfile.py: Running source!", client.out)
143143
self.assertEqual("Hello World", client.load("file1.txt"))
144144

145+
def test_local_source_layout_root(self):
146+
# Ensure that if a root folder is specified Conan source method
147+
# uses it. This is especially important when running with
148+
# no_copy_source where both the build() and source() methods
149+
# need to reference source_folder (so the value must be the
150+
# same in both methods)
151+
conanfile = textwrap.dedent('''
152+
from conan import ConanFile
153+
154+
class ConanLib(ConanFile):
155+
156+
def layout(self):
157+
self.folders.root = "root_folder"
158+
159+
def source(self):
160+
self.output.info(f"Source Folder: {self.source_folder}")
161+
''')
162+
# First, failing source()
163+
client = TestClient(light=True)
164+
client.save({CONANFILE: conanfile})
165+
166+
client.run("source .")
167+
self.assertTrue(client.out.strip().endswith("spaces\\root_folder"))
168+
145169
def test_retrieve_exports_sources(self):
146170
# For Conan 2.0 if we install a package from a remote and we want to upload to other
147171
# remote we need to download the sources, as we consider revisions immutable, let's

0 commit comments

Comments
 (0)