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

[art:build-info] feature: Add --add-cached-nodes flag to allow recollection of non-built packages #127

Merged
merged 3 commits into from
May 23, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions extensions/commands/art/cmd_build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _get_requested_by(nodes, node_id, artifact_type):
class _BuildInfo:

def __init__(self, graph, name, number, repository, with_dependencies=False,
url=None, user=None, password=None):
add_cached_deps=False, url=None, user=None, password=None):
self._graph = graph
self._name = name
self._number = number
Expand All @@ -120,6 +120,7 @@ def __init__(self, graph, name, number, repository, with_dependencies=False,
self._password = password
self._cached_artifact_info = {}
self._with_dependencies = with_dependencies
self._add_cached_deps = add_cached_deps

def get_artifacts(self, node, artifact_type, is_dependency=False):
"""
Expand Down Expand Up @@ -237,13 +238,13 @@ def get_modules(self):
except KeyError:
raise ConanException("JSON does not contain graph information")

for id, node in nodes.items():
for node in nodes.values():
ref = node.get("ref")
if ref:
transitive_dependencies = node.get("dependencies").keys() if node.get("dependencies").keys() else []
binary = node.get("binary")

# only add the nodes that were marked as built
if node.get("binary") == "Build":
if ref and (binary == "Build" or (binary == "Cache" and self._add_cached_deps)):

# recipe module
module = {
Expand Down Expand Up @@ -365,6 +366,10 @@ def build_info_create(conan_api: ConanAPI, parser, subparser, *args):
subparser.add_argument("--with-dependencies", help="Whether to add dependencies information or not. Default: false.",
action='store_true', default=False)

subparser.add_argument("--add-cached-deps", help="It will add not only the Conan packages that are built "
"but also the ones that are used from the cache but not built. Default: false.",
action='store_true', default=False)

args = parser.parse_args(*args)

url, user, password = get_url_user_password(args)
Expand All @@ -374,7 +379,8 @@ def build_info_create(conan_api: ConanAPI, parser, subparser, *args):
# remove the 'conanfile' node
data["graph"]["nodes"].pop("0")
bi = _BuildInfo(data, args.build_name, args.build_number, args.repository,
with_dependencies=args.with_dependencies, url=url, user=user, password=password)
with_dependencies=args.with_dependencies,
add_cached_deps=args.add_cached_deps, url=url, user=user, password=password)

cli_out_write(bi.create())

Expand Down
39 changes: 38 additions & 1 deletion tests/test_artifactory_commands.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os
import json
import tempfile

from tools import run
from tools import run, save
from conan.tools.scm import Version
from conan import conan_version

import pytest

Expand Down Expand Up @@ -209,6 +212,40 @@ def test_build_info_create_deps():
run(f'conan art:build-info delete {build_name}_aggregated --build-number={build_number} --url="{os.getenv("ART_URL")}" --user="{os.getenv("CONAN_LOGIN_USERNAME_EXTENSIONS_STG")}" --password="{os.getenv("CONAN_PASSWORD_EXTENSIONS_STG")}" --delete-all --delete-artifacts')


@pytest.mark.requires_credentials
def test_build_info_create_from_cached_deps():
# Make sure artifactory repos are empty before starting the test
run("conan remove mypkg* -c -r extensions-stg")
run("conan remove mypkg* -c -r extensions-prod")

run(f'conan art:server add artifactory {os.getenv("ART_URL")} --user="{os.getenv("CONAN_LOGIN_USERNAME_EXTENSIONS_STG")}" --password="{os.getenv("CONAN_PASSWORD_EXTENSIONS_STG")}"')

# Create dependency packages and upload them
run("conan new cmake_lib -d name=libc -d version=1.0 --force")
run("conan create . -tf=''")
run("conan new cmake_lib -d name=liba -d version=1.0 -d requires=libc/1.0 --force")
run("conan create . -tf=''")

run("conan upload '*' --dry-run -c -r extensions-stg")

# libc node in graph is cached
run("conan install . --format json > install_release.json")

run(f'conan art:build-info create install_release.json bi_release 1 extensions-stg --server artifactory --with-dependencies > bi_release.json')

with open("bi_release.json", "r") as file:
build_info = json.load(file)

assert len(build_info.get("modules")) == 0

run(f'conan art:build-info create install_release.json bi_release 1 extensions-stg --server artifactory --with-dependencies --add-cached-deps > bi_release.json')

with open("bi_release.json", "r") as file:
build_info = json.load(file)

assert len(build_info.get("modules")) == 2


@pytest.mark.requires_credentials
def test_fail_if_not_uploaded():
"""
Expand Down
Loading