-
Notifications
You must be signed in to change notification settings - Fork 950
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
[question] How should replacement for scm
work if recipe not in root Git dir
#11275
Comments
Hi @gabyx Sorry for the delay in responding. I am putting this test, to validate that the recipe can be inside a subfolder and not the root: class TestConanFileSubfolder:
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 As long as the Please have a look and let me know. |
Submitting a PR with the test above that will close this issue: #11533 |
How can I test this? |
OK here is a test visualizing the behavior: import unittest
from conans.test.utils.tools import TestClient
import textwrap
class TestConanFileSubfolder(unittest.TestCase):
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):
print("E: Recipe folder", self.recipe_folder)
print("E: Current folder:", os.getcwd())
git = Git(self, 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):
self.folders.source = "project"
def source(self):
print("S: Current folder:", os.getcwd())
git = Git(self)
sources = self.conan_data["sources"]
url = sources["url"]
commit = sources["commit"]
git.clone(url=url, target=".")
print("CLONED:", os.getcwd(), os.listdir(os.getcwd()))
git.checkout(commit=commit)
self.output.info("MYCMAKE: {}".format(load(self, "project/src/CMakeLists.txt")))
self.output.info("MYFILE: {}".format(load(self, "project/src/myfile.h")))
""")
def test_conanfile_subfolder(self):
"""
A local repo, without remote, will have commit, but no URL
"""
c = TestClient()
c.save({"project/conanfile.py": self.conanfile,
"project/src/CMakeLists.txt": "mycmakelists",
"project/src/myfile.h": "myheader"})
commit = c.init_git_repo()
c.run("export project")
print(c.out)
assert "pkg/0.1: COMMIT: {}".format(commit) in c.out
assert "pkg/0.1: URL: {}".format(c.current_folder.replace("\\", "/")) in c.out
print("==============")
c.run("create project")
print(c.out)
assert "pkg/0.1: MYCMAKE: mycmakelists" in c.out
assert "pkg/0.1: MYFILE: myheader" in c.out The output here of
so inside Is my finding correct? |
So long story short: repo/
- .git
- project
- conanfile.py
- src/allstufftobuild...
- CMakeLists.txt the git checkout should checkout inside Also the doc clearly states that too: https://docs.conan.io/en/1.50/reference/conanfile/methods.html#self-folders
|
I ve seen there is a new, maybe that helps?
|
@memsharded Could you reopen this. |
Feedback: I still think something is wrong with the documentation: Here https://docs.conan.io/en/latest/developing_packages/package_layout.html#example-export-sources-folder
|
I am working on replacing the
scm
attribute in https://docs.conan.io/en/latest/reference/conanfile/tools/scm/git.html#example-implementing-the-scm-featureI stumbled upon the fact that when the
conanfile.py
is in a subfolder/workspace/repo/tests/project
(could also be a submodule, but ignore that for now) of the main repository/workspace/repo
, then the example does not work, or I don't know how to work around this:My problem is that:
sources["url"]
insources
points to a local folder onconan create
which is good, but its the folder where the recipe lies/workspace/repo/tests/project
, and not the root Git dir/workspace/repo
.How can we fix this? Do I need to check if
self.conan_data["sources"]["url"]
is a absolute path instead of an URL?The text was updated successfully, but these errors were encountered: