Skip to content

Commit

Permalink
- BugFix: set tested_reference_str from conan info
Browse files Browse the repository at this point in the history
Signed-off-by: SSE4 <tomskside@gmail.com>
  • Loading branch information
SSE4 committed Mar 21, 2022
1 parent e98a759 commit 47328b5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
11 changes: 8 additions & 3 deletions conans/client/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,8 @@ def info(self, *args):
parser.add_argument("--package-filter", nargs='?',
help='Print information only for packages that match the filter pattern'
' e.g., MyPackage/1.2@user/channel or MyPackage*')
parser.add_argument("--tested_reference_str", action=OnceArgument,
help='set "tested_reference_str" attribute on test_package')
dry_build_help = ("Apply the --build argument to output the information, "
"as it would be done by the install command")
parser.add_argument("-db", "--dry-build", action=Extender, nargs="?", help=dry_build_help)
Expand Down Expand Up @@ -751,7 +753,8 @@ def info(self, *args):
remote_name=args.remote,
build_order=args.build_order,
check_updates=args.update,
install_folder=args.install_folder)
install_folder=args.install_folder,
tested_reference_str=args.tested_reference_str)
if args.json:
json_arg = True if args.json == "1" else args.json
self._outputer.json_build_order(ret, json_arg, os.getcwd())
Expand All @@ -770,7 +773,8 @@ def info(self, *args):
profile_build=profile_build,
remote_name=args.remote,
check_updates=args.update,
install_folder=args.install_folder)
install_folder=args.install_folder,
tested_reference_str=args.tested_reference_str)
if args.json:
json_arg = True if args.json == "1" else args.json
self._outputer.json_nodes_to_build(nodes, json_arg, os.getcwd())
Expand All @@ -790,7 +794,8 @@ def info(self, *args):
update=args.update,
install_folder=args.install_folder,
build=args.dry_build,
lockfile=args.lockfile)
lockfile=args.lockfile,
tested_reference_str=args.tested_reference_str)
deps_graph, _ = data
only = args.only
if args.only == ["None"]:
Expand Down
17 changes: 11 additions & 6 deletions conans/client/conan_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,36 +716,40 @@ def _info_args(self, reference_or_path, install_folder, profile_host, profile_bu
@api_method
def info_build_order(self, reference, settings=None, options=None, env=None,
profile_names=None, remote_name=None, build_order=None, check_updates=None,
install_folder=None, profile_build=None, conf=None):
install_folder=None, profile_build=None, conf=None,
tested_reference_str=None):
profile_host = ProfileData(profiles=profile_names, settings=settings, options=options,
env=env, conf=conf)
reference, graph_info = self._info_args(reference, install_folder, profile_host,
profile_build)
recorder = ActionRecorder()
remotes = self.app.load_remotes(remote_name=remote_name, check_updates=check_updates)
deps_graph = self.app.graph_manager.load_graph(reference, None, graph_info, ["missing"],
check_updates, False, remotes, recorder)
check_updates, False, remotes, recorder,
tested_reference_str=tested_reference_str)
return deps_graph.build_order(build_order)

@api_method
def info_nodes_to_build(self, reference, build_modes, settings=None, options=None, env=None,
profile_names=None, remote_name=None, check_updates=None,
install_folder=None, profile_build=None, conf=None):
install_folder=None, profile_build=None, conf=None,
tested_reference_str=None):
profile_host = ProfileData(profiles=profile_names, settings=settings, options=options,
env=env, conf=conf)
reference, graph_info = self._info_args(reference, install_folder, profile_host,
profile_build)
recorder = ActionRecorder()
remotes = self.app.load_remotes(remote_name=remote_name, check_updates=check_updates)
deps_graph = self.app.graph_manager.load_graph(reference, None, graph_info, build_modes,
check_updates, False, remotes, recorder)
check_updates, False, remotes, recorder,
tested_reference_str=tested_reference_str)
nodes_to_build = deps_graph.nodes_to_build()
return nodes_to_build, deps_graph.root.conanfile

@api_method
def info(self, reference_or_path, remote_name=None, settings=None, options=None, env=None,
profile_names=None, update=False, install_folder=None, build=None, lockfile=None,
profile_build=None, conf=None):
profile_build=None, conf=None, tested_reference_str=None):
profile_host = ProfileData(profiles=profile_names, settings=settings, options=options,
env=env, conf=conf)
reference, graph_info = self._info_args(reference_or_path, install_folder, profile_host,
Expand All @@ -755,7 +759,8 @@ def info(self, reference_or_path, remote_name=None, settings=None, options=None,
# FIXME: Using update as check_update?
remotes = self.app.load_remotes(remote_name=remote_name, check_updates=update)
deps_graph = self.app.graph_manager.load_graph(reference, None, graph_info, build,
update, False, remotes, recorder)
update, False, remotes, recorder,
tested_reference_str=tested_reference_str)

if install_folder:
output_folder = _make_abs_path(install_folder)
Expand Down
3 changes: 2 additions & 1 deletion conans/client/graph/graph_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def load_consumer_conanfile(self, conanfile_path, info_folder,

def load_graph(self, reference, create_reference, graph_info, build_mode, check_updates, update,
remotes, recorder, apply_build_requires=True, lockfile_node_id=None,
is_build_require=False, require_overrides=None):
is_build_require=False, require_overrides=None, tested_reference_str=None):
""" main entry point to compute a full dependency graph
"""
profile_host, profile_build = graph_info.profile_host, graph_info.profile_build
Expand All @@ -122,6 +122,7 @@ def load_graph(self, reference, create_reference, graph_info, build_mode, check_
root_node = self._load_root_node(reference, create_reference, profile_host, graph_lock,
root_ref, lockfile_node_id, is_build_require,
require_overrides)
root_node.conanfile.tested_reference_str = tested_reference_str
deps_graph = self._resolve_graph(root_node, profile_host, profile_build, graph_lock,
build_mode, check_updates, update, remotes, recorder,
apply_build_requires=apply_build_requires)
Expand Down
11 changes: 10 additions & 1 deletion conans/test/assets/genconanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self, name=None, version=None, new_import=False):
self._package_info = None
self._package_id_lines = None
self._test_lines = None
self._test_type = None
self._short_paths = None
self._exports_sources = None
self._exports = None
Expand Down Expand Up @@ -194,6 +195,10 @@ def with_test(self, line):
self._test_lines.append(line)
return self

def with_test_type(self, test_type):
self._test_type = test_type
return self

def with_cmake_build(self):
self._imports.append("from conan.tools.cmake import CMake")
self._generators = self._generators or []
Expand Down Expand Up @@ -383,6 +388,10 @@ def _test_lines_render(self):
lines = ['', ' def test(self):'] + [' %s' % m for m in self._test_lines]
return "\n".join(lines)

@property
def _test_type_render(self):
return "test_type = '{}'".format(self._test_type)

@property
def _short_paths_render(self):
return "short_paths = {}".format(str(self._short_paths))
Expand Down Expand Up @@ -412,7 +421,7 @@ def __repr__(self):
"exports", "generators", "requires", "build_requires", "requirements",
"build_requirements", "scm", "revision_mode", "settings", "options",
"default_options", "package_method", "package_info",
"package_id_lines", "test_lines"
"package_id_lines", "test_lines", "test_type",
):
v = getattr(self, "_{}".format(member), None)
if v is not None:
Expand Down
17 changes: 17 additions & 0 deletions conans/test/integration/command/info/info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,3 +720,20 @@ class Pkg(ConanFile):
client.run("info . --json=file.json")
info = json.loads(client.load("file.json"))
assert info[0]["python_requires"] == ['tool/0.1#f3367e0e7d170aa12abccb175fee5f97']

class TestInfoTestPackage:
# https://github.com/conan-io/conan/issues/10714

def test_tested_reference_str(self):
client = TestClient()
client.save({"conanfile.py": GenConanfile()})
client.run("export . tool/0.1@")

conanfile = GenConanfile().with_test_type("explicit").with_requirement("placeholder")
conanfile = str(conanfile).replace('"placeholder"', 'self.tested_reference_str')
client.save({"conanfile.py": conanfile})

for args in ["", " --build-order tool/0.1@", " --build"]:
client.run("info . --tested_reference_str=tool/0.1@" + args)
assert "AttributeError: 'HelloConan' object has no attribute 'tested_reference_str'"\
not in client.out

0 comments on commit 47328b5

Please sign in to comment.