Skip to content
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
18 changes: 13 additions & 5 deletions extensions/commands/art/cmd_build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _get_requested_by(nodes, node_id, artifact_type):
class _BuildInfo:

def __init__(self, graph, name, number, repository, build_url=None, with_dependencies=False,
add_cached_deps=False, url=None, user=None, password=None):
add_cached_deps=False, url=None, user=None, password=None, conan_api=None):
self._graph = graph
self._name = name
self._number = number
Expand All @@ -126,6 +126,14 @@ def __init__(self, graph, name, number, repository, build_url=None, with_depende
self._cached_artifact_info = {}
self._with_dependencies = with_dependencies
self._add_cached_deps = add_cached_deps
self._conan_api = conan_api

def get_artifacts_folder(self, node, artifact_type):
if artifact_type == "package":
return node.get("package_folder")
else:
reference = RecipeReference.loads(node.get("ref"))
return self._conan_api.cache.export_path(reference)
Comment on lines +131 to +136

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the package folder is ok in both conan create/install and export-pkg graphs, however for the re recipe_folder, in the export-pkg graph the path points to the user local folder, so here I resorted to query the conan cache to get the recipe path in the cache

Comment thread
danimtb marked this conversation as resolved.

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

artifacts_folder = Path(node.get("package_folder")) if artifact_type == "package" else Path(node.get("recipe_folder"))
artifacts_folder = Path(artifacts_folder)
dl_folder = artifacts_folder.parents[0] / "d"
dl_folder_files = [file for file in dl_folder.glob("*") if file.name in artifacts_names]
artifacts_folder_files = [file for file in artifacts_folder.glob("*") if file.name in artifacts_names]
Expand Down Expand Up @@ -238,7 +246,7 @@ def _get_remote_artifacts(artifact):
if sources_artifact:
artifacts.append(sources_artifact)

folder = node.get("package_folder") if artifact_type == "package" else node.get("recipe_folder")
folder = self.get_artifacts_folder(node, artifact_type)
if not artifacts and folder:
raise ConanException(f"There are missing artifacts for the {node.get('ref')} {artifact_type}. "
"Check that you have all the packages installed in the Conan cache when creating the Build Info.")
Expand Down Expand Up @@ -399,7 +407,7 @@ def build_info_create(conan_api: ConanAPI, parser, subparser, *args):
bi = _BuildInfo(data, args.build_name, args.build_number, args.repository,
build_url=args.build_url,
with_dependencies=args.with_dependencies,
add_cached_deps=args.add_cached_deps, url=url, user=user, password=password)
add_cached_deps=args.add_cached_deps, url=url, user=user, password=password, conan_api=conan_api)

return bi.create()

Expand Down
33 changes: 33 additions & 0 deletions tests/test_build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,36 @@ def package_info(self):
# Check libb package now has the meson dependency
build_info["modules"][3]["dependencies"]
assert len(build_info["modules"][3]["dependencies"]) == 2


def test_export_pkg():
Comment thread
danimtb marked this conversation as resolved.
Outdated
"""
Test build info created with export-pkg command
"""
run("conan new header_lib -d name=lib1 -d version=1.0")
run("conan create .")

run("conan new cmake_lib -d name=lib2 -d version=1.0 -d requires=lib1/1.0 --force")
run("conan build .")
run("conan export-pkg . --test-folder= -f json > export_pkg.json")
run("conan upload lib* -c -r conancenter --dry-run") # To generate the .tgz files in conan local cache

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More a question for the client: Isn't it possible to pass an empty remote or not add the argument for a dry-run? (I guess it's not but maybe it should be possible?) passing conancenter there feels a bit odd

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not possible, the --dry-run still checks in the remote what needs to be uploaded and what not, so it checks the server too.


run("conan art:build-info create export_pkg.json build_name 1 repo --with-dependencies --add-cached-deps > bi.json")
build_info = json.loads(load("bi.json"))
assert len(build_info["modules"]) == 4


def test_simple_create():
"""
Test build info created with simple conan create command to verify same output as the export-pkg command
"""
run("conan new header_lib -d name=lib1 -d version=1.0")
run("conan create .")

run("conan new cmake_lib -d name=lib2 -d version=1.0 -d requires=lib1/1.0 --force")
run("conan create . -f json > create.json")
run("conan upload lib* -c -r conancenter --dry-run") # To generate the .tgz files in conan local cache

run("conan art:build-info create create.json build_name 1 repo --with-dependencies --add-cached-deps > bi.json")
build_info = json.loads(load("bi.json"))
assert len(build_info["modules"]) == 4
Loading