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

Evaluate always SCM attribute before exporting the recipe #4088

Merged
merged 5 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
19 changes: 10 additions & 9 deletions conans/client/cmd/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ def _capture_export_scm_data(conanfile, conanfile_dir, destination_folder, outpu
os.unlink(scm_src_file)

scm_data = get_scm_data(conanfile)
captured_revision = scm_data.capture_revision if scm_data else False
if not scm_data:
return None, False

if not scm_data or not (scm_data.capture_origin or scm_data.capture_revision):
return None, captured_revision
# Resolve SCMData in the user workspace (someone may want to access CVS or import some py)
captured_revision = scm_data.capture_revision

scm = SCM(scm_data, conanfile_dir, output)
if scm_data.capture_origin or scm_data.capture_revision:
# Generate the scm_folder.txt file pointing to the src_path
src_path = scm.get_repo_root()
save(scm_src_file, src_path.replace("\\", "/"))

if scm_data.url == "auto":
origin = scm.get_qualified_remote_url()
Expand All @@ -84,17 +89,14 @@ def _capture_export_scm_data(conanfile, conanfile_dir, destination_folder, outpu
output.warn("Repo origin looks like a local path: %s" % origin)
output.success("Repo origin deduced by 'auto': %s" % origin)
scm_data.url = origin

if scm_data.revision == "auto":
if not scm.is_pristine():
output.warn("Repo status is not pristine: there might be modified files")
scm_data.revision = scm.get_revision()
output.success("Revision deduced by 'auto': %s" % scm_data.revision)

# Generate the scm_folder.txt file pointing to the src_path
src_path = scm.get_repo_root()
save(scm_src_file, src_path.replace("\\", "/"))
_replace_scm_data_in_conanfile(os.path.join(destination_folder, "conanfile.py"),
scm_data)
_replace_scm_data_in_conanfile(os.path.join(destination_folder, "conanfile.py"), scm_data)

return scm_data, captured_revision

Expand Down Expand Up @@ -146,7 +148,6 @@ def _replace_scm_data_in_conanfile(conanfile_path, scm_data):
content = content if not headers else ''.join(headers) + content
save(conanfile_path, content)


def _export_conanfile(conanfile_path, output, client_cache, conanfile, conan_ref, keep_source):

exports_folder = client_cache.export(conan_ref)
Expand Down
64 changes: 64 additions & 0 deletions conans/test/functional/old/scm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,70 @@ def scm_serialization_test(self):
data2 = json.loads(the_json)
self.assertEquals(data, data2)

def test_git_delegated_function(self):
conanfile = """
import os
from conans import ConanFile
from conans.client.tools.scm import Git

def get_revision():
here = os.path.dirname(__file__)
git = Git(here)
return git.get_commit()

def get_url():
def nested_url():
here = os.path.dirname(__file__)
git = Git(here)
return git.get_remote_url()
return nested_url()

class MyLib(ConanFile):
name = "issue"
version = "3831"
scm = {'type': 'git', 'url': get_url(), 'revision': get_revision()}

"""
self.client.save({"conanfile.py": conanfile})
path, commit = create_local_git_repo(folder=self.client.current_folder)
self.client.runner('git remote add origin "%s"' % path.replace("\\", "/"), cwd=path)

self.client.run("export . user/channel")
reference = ConanFileReference.loads("issue/3831@user/channel")
exported_conanfile = self.client.client_cache.conanfile(reference)
content = load(exported_conanfile)
self.assertIn(commit, content)

def test_delegated_python_code(self):
jgsogo marked this conversation as resolved.
Show resolved Hide resolved
conanfile = """
from conans import ConanFile
from recipe_code import get_commit

class MyLib(ConanFile):
name = "issue"
version = "3831"
scm = {'type': 'git', 'url': 'url', 'revision': get_commit()}
"""

code_file = """
import os
from conans.client.tools.scm import Git

def get_commit():
here = os.path.dirname(__file__)
git = Git(here)
return git.get_commit()
"""
self.client.save({"conanfile.py": conanfile, "recipe_code/__init__.py": code_file})
path, commit = create_local_git_repo(folder=self.client.current_folder)
self.client.runner('git remote add origin "%s"' % path.replace("\\", "/"), cwd=path)

self.client.run("export . user/channel")
reference = ConanFileReference.loads("issue/3831@user/channel")
exported_conanfile = self.client.client_cache.conanfile(reference)
content = load(exported_conanfile)
self.assertIn(commit, content)


@attr('svn')
class SVNSCMTest(SVNLocalRepoTestCase):
Expand Down