Skip to content
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
11 changes: 7 additions & 4 deletions conan/tools/layout/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import os


def basic_layout(conanfile, src_folder="."):
def basic_layout(conanfile, src_folder=".", build_folder=None):
subproject = conanfile.folders.subproject

conanfile.folders.source = src_folder if not subproject else os.path.join(subproject, src_folder)
conanfile.folders.build = "build" if not subproject else os.path.join(subproject, "build")
if conanfile.settings.get_safe("build_type"):
conanfile.folders.build += "-{}".format(str(conanfile.settings.build_type).lower())
if build_folder:
conanfile.folders.build = build_folder if not subproject else os.path.join(subproject, build_folder)
else:
conanfile.folders.build = "build" if not subproject else os.path.join(subproject, "build")
if conanfile.settings.get_safe("build_type"):
conanfile.folders.build += "-{}".format(str(conanfile.settings.build_type).lower())
conanfile.folders.generators = os.path.join(conanfile.folders.build, "conan")
conanfile.cpp.build.bindirs = ["."]
conanfile.cpp.build.libdirs = ["."]
13 changes: 8 additions & 5 deletions test/integration/toolchains/gnu/test_basic_layout.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import os
import platform
import textwrap
import pytest

from conan.test.utils.tools import TestClient


def test_basic_layout_subproject():
@pytest.mark.parametrize("basic_layout, expected_path", [
('basic_layout(self)', 'build-release'),
('basic_layout(self, build_folder="custom_build_folder")', 'custom_build_folder')])
def test_basic_layout_subproject(basic_layout, expected_path):
c = TestClient()
conanfile = textwrap.dedent("""
conanfile = textwrap.dedent(f"""
from conan import ConanFile
from conan.tools.layout import basic_layout
class Pkg(ConanFile):
Expand All @@ -16,10 +19,10 @@ class Pkg(ConanFile):
def layout(self):
self.folders.root = ".."
self.folders.subproject = "pkg"
basic_layout(self)
{basic_layout}
""")
c.save({"pkg/conanfile.py": conanfile})
c.run("install pkg")
ext = "sh" if platform.system() != "Windows" else "bat"
assert os.path.isfile(os.path.join(c.current_folder, "pkg", "build-release", "conan",
assert os.path.isfile(os.path.join(c.current_folder, "pkg", expected_path, "conan",
"conanautotoolstoolchain.{}".format(ext)))
Loading