Skip to content

Commit

Permalink
Add package revision to format=json in 'conan export-pkg' command (#1…
Browse files Browse the repository at this point in the history
…5042)

* add package revision at conan export-pkg

* remove print

* fix test
  • Loading branch information
memsharded authored Nov 2, 2023
1 parent e49aa26 commit 2dd857f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions conan/api/subapi/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from conan.internal.conan_app import ConanApp
from conans.client.cmd.export import cmd_export
from conans.client.conanfile.package import run_package_method
from conans.client.graph.graph import BINARY_BUILD
from conans.model.package_ref import PkgReference


Expand Down Expand Up @@ -46,6 +47,9 @@ def export_pkg(self, deps_graph, source_folder, output_folder):
pref = PkgReference(pref.ref, pref.package_id, prev)
pkg_layout.reference = pref
cache.assign_prev(pkg_layout)
pkg_node.prev = prev
pkg_node.pref_timestamp = pref.timestamp # assigned by assign_prev
pkg_node.binary = BINARY_BUILD
# Make sure folder is updated
final_folder = pkg_layout.package()
conanfile.folders.set_base_package(final_folder)
Expand Down
16 changes: 12 additions & 4 deletions conans/test/integration/command/export_pkg_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,17 @@ def test_export_pkg_json(self):
client.save({"conanfile.py": GenConanfile("pkg", "0.1")})

# Wrong folders
client.run("export-pkg . --format=json", redirect_stdout="file.json")
graph = json.loads(client.load("file.json"))
assert "pkg/0.1" in graph["graph"]["nodes"]["0"]["ref"]
client.run("export-pkg . --format=json")
graph = json.loads(client.stdout)
node = graph["graph"]["nodes"]["0"]
assert "pkg/0.1" in node["ref"]
# https://github.com/conan-io/conan/issues/15041
assert "da39a3ee5e6b4b0d3255bfef95601890afd80709" == node["package_id"]
assert "485dad6cb11e2fa99d9afbe44a57a164" == node["rrev"]
assert "0ba8627bd47edc3a501e8f0eb9a79e5e" == node["prev"]
assert "Build" == node["binary"]
assert node["rrev_timestamp"] is not None
assert node["prev_timestamp"] is not None

def test_export_pkg_no_ref(self):
client = TestClient()
Expand Down Expand Up @@ -391,7 +399,7 @@ def package_info(self):
for n in nodes.values():
ref = n["ref"]
if ref == hello_pkg_ref:
assert n['binary'] is None # The exported package has no binary status
assert n['binary'] == "Build"
hello_cpp_info = n['cpp_info']
elif ref == pkg_pkg_ref:
assert n['binary'] == "Cache"
Expand Down

0 comments on commit 2dd857f

Please sign in to comment.