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

Build info issue/6080 #6088

Merged
merged 6 commits into from Nov 19, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 5 additions & 9 deletions conans/build_info/build_info.py
Expand Up @@ -46,13 +46,14 @@ def __init__(self, output, build_info_file, lockfile, multi_module=True, skip_en
self._user = user
self._password = password
self._apikey = apikey
self._output = output
self._conan_cache = ClientCache(os.path.join(get_conan_user_home(), ".conan"), output)

def parse_pref(self, pref):
ref = ConanFileReference.loads(pref, validate=False)
rrev = ref.revision.split("#")[0].split(":")[0]
pid = ref.revision.split("#")[0].split(":")[1]
prev = ref.revision.split("#")[1]
prev = "" if len(ref.revision.split("#")) == 1 else ref.revision.split("#")[1]
return {
"name": ref.name,
"version": ref.version,
Expand Down Expand Up @@ -106,14 +107,9 @@ def _get_metadata_artifacts(self, metadata, request_path, use_id=False, name_for

if response.status_code == 200:
data = response.json()
ret[data["checksums"]["sha1"]] = {"md5": data["checksums"],
"name": "conan_sources.tgz",
"id": None}
elif response.status_code == 401:
raise AuthenticationException(response_to_str(response))
else:
raise RequestErrorException(response_to_str(response))

ret[data["checksums"]["sha1"]] = {"md5": data["checksums"]["md5"],
"name": "conan_sources.tgz" if not use_id else None,
"id": "conan_sources.tgz" if use_id else None}
return set([Artifact(k, **v) for k, v in ret.items()])

def _get_recipe_artifacts(self, pref, add_prefix, use_id):
Expand Down
61 changes: 61 additions & 0 deletions conans/test/integration/test_build_info_creation.py
Expand Up @@ -55,6 +55,13 @@ def mock_response(url, data=None, **kwargs):
mock_resp.content = None
return mock_resp

def mock_response_get(url, data=None, **kwargs):
mock_resp = Mock()
mock_resp.status_code = 200
if "conan_sources.tgz" in url:
mock_resp.status_code = 404
return mock_resp

def _test_buildinfo(self, client, user_channel):
conanfile = textwrap.dedent("""
from conans import ConanFile, load
Expand Down Expand Up @@ -171,3 +178,57 @@ def test_build_info_create_update_publish(self, mock_cache, user_home_mock):
user_channels = ["", "user/channel"]
for user_channel in user_channels:
self._test_buildinfo(client, user_channel)

@patch("conans.build_info.build_info.get_conan_user_home")
@patch("conans.build_info.build_info.ClientCache")
@patch("conans.build_info.build_info.requests.get", new=mock_response_get)
def test_build_info_create_scm(self, mock_cache, user_home_mock):
base_folder = temp_folder(True)
cache_folder = os.path.join(base_folder, ".conan")
servers = {"default": TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")],
users={"lasote": "mypass"})}
client = TestClient(servers=servers, users={"default": [("lasote", "mypass")]},
cache_folder=cache_folder)

mock_cache.return_value = client.cache
user_home_mock.return_value = base_folder
conanfile = textwrap.dedent("""
from conans import ConanFile, load
import os
class Pkg(ConanFile):
name = "PkgA"
version = "0.1"
scm = {"type": "git",
"url": "auto",
"revision": "auto"}

def imports(self):
self.copy("myfile.txt", folder=True)
def package(self):
self.copy("*myfile.txt")
""")

client.save({"conanfile.py": conanfile,
"myfile.txt": "HelloA"})
client.run_command("git init")
client.run_command('git config user.email "you@example.com"')
client.run_command('git config user.name "Your Name"')
client.run_command("git remote add origin https://github.com/fake/fake.git")
client.run_command("git add .")
client.run_command("git commit -m \"initial commit\"")

client.run("export .")

client.run("graph lock .")

client.run("create . --lockfile")
client.run("upload * --confirm -r default --force")

sys.argv = ["conan_build_info", "--v2", "start", "MyBuildName", "42"]
run()
sys.argv = ["conan_build_info", "--v2", "create",
os.path.join(client.current_folder, "buildinfo.json"), "--lockfile",
os.path.join(client.current_folder, LOCKFILE)]
run()
if not os.path.exists(os.path.join(client.current_folder, "buildinfo.json")):
self.fail("build info create failed")