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

Add new layout() test for projects sharing common code in parent folders #11556

Merged
merged 8 commits into from Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 52 additions & 0 deletions conans/test/functional/layout/test_in_subfolder.py
Expand Up @@ -54,3 +54,55 @@ def build(self):
c.run("build conan")
assert "conanfile.py (pkg/0.1): MYCMAKE-BUILD: mycmake!" in c.out
assert c.load("build/mylib.a") == "mylib"


def test_exports_sources_common_code():
""" very similar to the above, but intended for a multi-package project sharing some
common code
"""
c = TestClient()
conanfile = textwrap.dedent("""
import os
from conan import ConanFile
from conan.tools.files import load, copy, save
class Pkg(ConanFile):
name = "pkg"
version = "0.1"

def layout(self):
self.folders.root = ".."
self.folders.source = "pkg"
self.folders.build = "build"

def export_sources(self):
source_folder = os.path.join(self.recipe_folder, "..")
copy(self, "*.txt", source_folder, self.export_sources_folder)
copy(self, "*.cmake", source_folder, self.export_sources_folder)

def source(self):
cmake = load(self, "CMakeLists.txt")
self.output.info("MYCMAKE-SRC: {}".format(cmake))

def build(self):
path = os.path.join(self.source_folder, "CMakeLists.txt")
cmake = load(self, path)
self.output.info("MYCMAKE-BUILD: {}".format(cmake))

path = os.path.join(self.export_sources_folder, "common", "myutils.cmake")
cmake = load(self, path)
self.output.info("MYUTILS-BUILD: {}".format(cmake))
""")
c.save({"pkg/conanfile.py": conanfile,
"pkg/CMakeLists.txt": "mycmake!",
"common/myutils.cmake": "myutils!"})
c.run("create pkg")
assert "pkg/0.1: MYCMAKE-SRC: mycmake!" in c.out
assert "pkg/0.1: MYCMAKE-BUILD: mycmake!" in c.out
assert "pkg/0.1: MYUTILS-BUILD: myutils!" in c.out

# Local flow
c.run("install pkg")
# SOURCE NOT CALLED! It doesnt make sense (will fail due to local exports)
c.run("build pkg")
assert "conanfile.py (pkg/0.1): MYCMAKE-BUILD: mycmake!" in c.out
assert "conanfile.py (pkg/0.1): MYUTILS-BUILD: myutils!" in c.out
Empty file.