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

new git conanfile in subfolder test #11533

Merged
merged 1 commit into from
Jun 28, 2022
Merged
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
55 changes: 55 additions & 0 deletions conans/test/functional/tools/scm/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,58 @@ def test_full_scm(self):
assert "pkg1/0.1: MYFILE-BUILD: myheader1!" in c2.out
assert "pkg2/0.1: MYCMAKE-BUILD: mycmake2!" in c2.out
assert "pkg2/0.1: MYFILE-BUILD: my2header!" in c2.out


class TestConanFileSubfolder:
"""verify that we can have a conanfile in a subfolder
# https://github.com/conan-io/conan/issues/11275
"""

conanfile = textwrap.dedent("""
import os
from conan import ConanFile
from conan.tools.scm import Git
from conan.tools.files import update_conandata, load

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

def export(self):
git = Git(self, os.path.dirname(self.recipe_folder))
url, commit = git.get_url_and_commit()
# We store the current url and commit in conandata.yml
update_conandata(self, {"sources": {"commit": commit, "url": url}})
self.output.info("URL: {}".format(url))
self.output.info("COMMIT: {}".format(commit))

def layout(self):
pass # self.folders.source = "source"

def source(self):
git = Git(self)
sources = self.conan_data["sources"]
url = sources["url"]
commit = sources["commit"]
git.clone(url=url, target=".")
git.checkout(commit=commit)
self.output.info("MYCMAKE: {}".format(load(self, "CMakeLists.txt")))
self.output.info("MYFILE: {}".format(load(self, "src/myfile.h")))
""")

def test_conanfile_subfolder(self):
"""
A local repo, without remote, will have commit, but no URL
"""
c = TestClient()
c.save({"conan/conanfile.py": self.conanfile,
"CMakeLists.txt": "mycmakelists",
"src/myfile.h": "myheader"})
commit = c.init_git_repo()
c.run("export conan")
assert "pkg/0.1: COMMIT: {}".format(commit) in c.out
assert "pkg/0.1: URL: {}".format(c.current_folder.replace("\\", "/")) in c.out

c.run("create conan")
assert "pkg/0.1: MYCMAKE: mycmakelists" in c.out
assert "pkg/0.1: MYFILE: myheader" in c.out