Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double base path setup in editable packages #14109

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions conans/client/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ def _handle_node_editable(self, install_node):
output_folder = editable.get("output_folder")

base_path = os.path.dirname(conanfile_path)
base_path = base_path if conanfile.folders.root is None else \
os.path.normpath(os.path.join(base_path, conanfile.folders.root))

conanfile.folders.set_base_folders(base_path, output_folder)
output = conanfile.output
output.info("Rewriting files of editable package "
Expand All @@ -355,19 +354,20 @@ def _handle_node_editable(self, install_node):
if node.binary == BINARY_EDITABLE_BUILD:
run_build_method(conanfile, self._hook_manager)

rooted_base_path = base_path if conanfile.folders.root is None else \
os.path.normpath(os.path.join(base_path, conanfile.folders.root))

for node in install_node.nodes:
# Get source of information
conanfile = node.conanfile
# New editables mechanism based on Folders
conanfile.folders.set_base_package(output_folder or base_path)
conanfile.folders.set_base_source(base_path)
conanfile.folders.set_base_build(output_folder or base_path)
conanfile.folders.set_base_generators(output_folder or base_path)
conanfile.folders.set_base_package(output_folder or rooted_base_path)
conanfile.folders.set_base_folders(base_path, output_folder)
# Need a temporary package revision for package_revision_mode
# Cannot be PREV_UNKNOWN otherwise the consumers can't compute their packageID
node.prev = "editable"
# TODO: Check this base_path usage for editable when not defined
self._call_package_info(conanfile, package_folder=base_path, is_editable=True)
self._call_package_info(conanfile, package_folder=rooted_base_path, is_editable=True)

def _handle_node_build(self, package, pkg_layout):
node = package.nodes[0]
Expand Down
64 changes: 58 additions & 6 deletions conans/test/integration/editable/test_editable_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,84 @@ def test_editable_folders_root():
""" Editables with self.folders.root = ".." should work too
"""
c = TestClient()
sub1 = textwrap.dedent("""
pkg = textwrap.dedent("""
from conan import ConanFile

class Pkg(ConanFile):
name = "pkg"
version = "0.1"

def layout(self):
self.folders.root = ".."
self.folders.build = "mybuild"
self.cpp.build.libdirs = ["mylibdir"]

def generate(self):
self.output.info(f"PKG source_folder {self.source_folder}")

def package_info(self):
self.output.info(f"PKG package_folder {self.package_folder}")
""")
sub2 = textwrap.dedent("""
app = textwrap.dedent("""
from conan import ConanFile

class App(ConanFile):
requires = "pkg/0.1"
def generate(self):
pkg_libdir = self.dependencies["pkg"].cpp_info.libdir
self.output.info(f"PKG LIBDIR {pkg_libdir}")
""")
c.save({"libs/pkg/conanfile.py": pkg,
"conanfile.py": app})

c.run("editable add libs/pkg")
c.run("install .")
libdir = os.path.join(c.current_folder, "libs", "mybuild", "mylibdir")
assert f"conanfile.py: PKG LIBDIR {libdir}" in c.out
assert f"pkg/0.1: PKG package_folder {c.current_folder}" in c.out
assert f"pkg/0.1: PKG source_folder {c.current_folder}" in c.out


def test_editable_folders_sibiling_root():
""" Editables with self.folders.root = ".." should work too for sibling folders
"""
c = TestClient()
pkg = textwrap.dedent("""
from conan import ConanFile

class Pkg(ConanFile):
name = "pkg"
version = "0.1"

def layout(self):
self.folders.root = ".."
self.folders.build = "mybuild"
self.cpp.build.libdirs = ["mylibdir"]

def generate(self):
self.output.info(f"PKG source_folder {self.source_folder}")

def package_info(self):
self.output.info(f"PKG package_folder {self.package_folder}")
""")
app = textwrap.dedent("""
from conan import ConanFile

class App(ConanFile):
requires = "pkg/0.1"
def generate(self):
pkg_libdir = self.dependencies["pkg"].cpp_info.libdir
self.output.info(f"PKG LIBDIR {pkg_libdir}")
""")
c.save({"sub1/conanfile.py": sub1,
"sub2/conanfile.py": sub2})
c.run("editable add sub1")
c.run("install sub2")
c.save({"pkg/conanfile.py": pkg,
"app/conanfile.py": app})

c.run("editable add pkg")
c.run("install app")
libdir = os.path.join(c.current_folder, "mybuild", "mylibdir")
assert f"conanfile.py: PKG LIBDIR {libdir}" in c.out
assert f"pkg/0.1: PKG source_folder {c.current_folder}" in c.out
assert f"pkg/0.1: PKG package_folder {c.current_folder}" in c.out


def test_editable_matching_folder_names():
Expand Down