Skip to content

Commit 2035729

Browse files
committed
Merge branch 'main' into czoido/multi-repo-bi
2 parents 8e570d2 + 75899df commit 2035729

2 files changed

Lines changed: 38 additions & 13 deletions

File tree

extensions/commands/art/cmd_build_info.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ def _get_requested_by(nodes, node_id, artifact_type):
113113

114114
class _BuildInfo:
115115

116-
def __init__(self, graph, name, number, repositories, build_url=None, with_dependencies=False,
116+
def __init__(self, conan_api, graph, name, number, repositories, build_url=None, with_dependencies=False,
117117
add_cached_deps=False, url=None, user=None, password=None):
118+
self._conan_api = conan_api
118119
self._graph = graph
119120
self._name = name
120121
self._number = number
@@ -165,6 +166,12 @@ def _get_origin_repo(self, node):
165166
f"The package was not found in any of the specified repositories: {', '.join(self._repositories)}"
166167
)
167168

169+
def get_artifacts_folder(self, node, artifact_type):
170+
if artifact_type == "package":
171+
return node.get("package_folder")
172+
else:
173+
reference = RecipeReference.loads(node.get("ref"))
174+
return self._conan_api.cache.export_path(reference)
168175

169176
def get_artifacts(self, node, artifact_type, is_dependency=False):
170177
"""
@@ -186,14 +193,14 @@ def get_artifacts(self, node, artifact_type, is_dependency=False):
186193
def _get_local_artifacts():
187194
local_artifacts = []
188195
missing_artifacts = []
189-
artifacts_folder = node.get("package_folder") if artifact_type == "package" else node.get("recipe_folder")
196+
artifacts_folder = self.get_artifacts_folder(node, artifact_type)
190197
if artifacts_folder is None and artifact_type == "package" and node.get("binary") == "Skip":
191198
ConanOutput().warning(f"Package is marked as 'Skip' for {node.get('ref')} and will not be included "
192199
"into the Build Info. If you want to get it included, use the conf argument: "
193200
"'-c:a tools.graph:skip_binaries=False' in your conan create/install command.")
194201
return (local_artifacts, missing_artifacts)
195202

196-
artifacts_folder = Path(node.get("package_folder")) if artifact_type == "package" else Path(node.get("recipe_folder"))
203+
artifacts_folder = Path(artifacts_folder)
197204
dl_folder = artifacts_folder.parents[0] / "d"
198205
dl_folder_files = [file for file in dl_folder.glob("*") if file.name in artifacts_names]
199206
artifacts_folder_files = [file for file in artifacts_folder.glob("*") if file.name in artifacts_names]
@@ -279,7 +286,7 @@ def _get_remote_artifacts(artifact):
279286
if sources_artifact:
280287
artifacts.append(sources_artifact)
281288

282-
folder = node.get("package_folder") if artifact_type == "package" else node.get("recipe_folder")
289+
folder = self.get_artifacts_folder(node, artifact_type)
283290
if not artifacts and folder:
284291
raise ConanException(f"There are missing artifacts for the {node.get('ref')} {artifact_type}. "
285292
"Check that you have all the packages installed in the Conan cache when creating the Build Info.")
@@ -437,8 +444,7 @@ def build_info_create(conan_api: ConanAPI, parser, subparser, *args):
437444
data["graph"]["nodes"].pop("0")
438445

439446

440-
bi = _BuildInfo(data, args.build_name, args.build_number,
441-
repositories=args.repository,
447+
bi = _BuildInfo(conan_api, data, args.build_name, args.build_number, repositories=args.repository,
442448
build_url=args.build_url,
443449
with_dependencies=args.with_dependencies,
444450
add_cached_deps=args.add_cached_deps, url=url, user=user, password=password)
@@ -629,7 +635,7 @@ def build_info_append(conan_api: ConanAPI, parser, subparser, *args):
629635
if not any(d['id'] == module.get('id') for d in all_modules):
630636
all_modules.append(module)
631637

632-
bi = _BuildInfo(None, args.build_name, args.build_number, None)
638+
bi = _BuildInfo(conan_api, None, args.build_name, args.build_number, None)
633639
bi_json = bi.header()
634640
bi_json.update({"modules": all_modules})
635641
return json.dumps(bi_json, indent=4)

tests/test_artifactory_commands.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import tempfile
44
import textwrap
55

6-
from tools import run, save
6+
from tools import load, run, save
77
from conan.tools.scm import Version
88
from conan import conan_version
99

@@ -143,11 +143,30 @@ def test_build_info_export_pkg():
143143
run("conan upload mypkg/1.0 -c -r extensions-stg")
144144
run(f'conan art:build-info create export.json mybuildinfo 1 extensions-stg --server=artifactory --out-file=mybuildinfo.json')
145145

146-
with open(f"mybuildinfo.json", "r") as f:
147-
data = json.load(f)
148-
149-
assert "modules" in data
150-
assert any(module.get("type") == "conan" for module in data["modules"])
146+
build_info = json.loads(load("mybuildinfo.json"))
147+
148+
mypkg_modules = [m for m in build_info["modules"] if "mypkg/1.0#294e801a0e1da10084441487e95b80e8" in m.get("id")]
149+
assert len(mypkg_modules) == 2 # Assert both recipe and package modules exist
150+
mypkg_recipe_module = next(m for m in mypkg_modules if m.get("id") == "mypkg/1.0#294e801a0e1da10084441487e95b80e8")
151+
assert len(mypkg_recipe_module["artifacts"]) == 3 # Assert the 3 artifacts exist
152+
mypkg_conanmanifest_data = next(
153+
artifact for artifact in mypkg_recipe_module["artifacts"]
154+
if artifact.get("name") == "conanmanifest.txt"
155+
) # Assert conanmanifest.txt path
156+
assert mypkg_conanmanifest_data[
157+
"path"] == "extensions-stg/_/mypkg/1.0/_/294e801a0e1da10084441487e95b80e8/export/conanmanifest.txt"
158+
mypkg_sources_data = next(
159+
artifact for artifact in mypkg_recipe_module["artifacts"]
160+
if artifact.get("name") == "conan_sources.tgz"
161+
) # Assert conan_sources.tgz path
162+
assert mypkg_sources_data[
163+
"path"] == "extensions-stg/_/mypkg/1.0/_/294e801a0e1da10084441487e95b80e8/export/conan_sources.tgz"
164+
mypkg_conanfile_data = next(
165+
artifact for artifact in mypkg_recipe_module["artifacts"]
166+
if artifact.get("name") == "conanfile.py"
167+
) # Assert conanfile.py path
168+
assert mypkg_conanfile_data[
169+
"path"] == "extensions-stg/_/mypkg/1.0/_/294e801a0e1da10084441487e95b80e8/export/conanfile.py"
151170

152171

153172
@pytest.mark.requires_credentials

0 commit comments

Comments
 (0)