Skip to content

Commit

Permalink
fix export-pkg json output (#15504)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Jan 24, 2024
1 parent b96e5b0 commit 4beb097
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion conan/api/subapi/export.py
Expand Up @@ -2,7 +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.client.graph.graph import BINARY_BUILD, RECIPE_INCACHE
from conans.model.package_ref import PkgReference
from conans.util.files import mkdir

Expand Down Expand Up @@ -52,6 +52,7 @@ def export_pkg(self, deps_graph, source_folder, output_folder):
cache.assign_prev(pkg_layout)
pkg_node.prev = prev
pkg_node.pref_timestamp = pref.timestamp # assigned by assign_prev
pkg_node.recipe = RECIPE_INCACHE
pkg_node.binary = BINARY_BUILD
# Make sure folder is updated
final_folder = pkg_layout.package()
Expand Down
7 changes: 4 additions & 3 deletions conan/cli/commands/export_pkg.py
Expand Up @@ -93,9 +93,10 @@ def export_pkg(conan_api, parser, *args):

if test_conanfile_path:
from conan.cli.commands.test import run_test
deps_graph = run_test(conan_api, test_conanfile_path, ref, profile_host, profile_build,
remotes=remotes, lockfile=lockfile, update=False, build_modes=None)
# TODO: Do something with lockfile, same as create()
# same as ``conan create`` the lockfile, and deps graph is the one of the exported-pkg
# not the one from test_package
run_test(conan_api, test_conanfile_path, ref, profile_host, profile_build,
remotes=remotes, lockfile=lockfile, update=False, build_modes=None)

conan_api.lockfile.save_lockfile(lockfile, args.lockfile_out, cwd)
return {"graph": deps_graph,
Expand Down
10 changes: 8 additions & 2 deletions conans/test/integration/command/export_pkg_test.py
Expand Up @@ -283,8 +283,8 @@ def test_export_pkg_json(self):
client.save({"conanfile.py": GenConanfile("pkg", "0.1")})

# Wrong folders
client.run("export-pkg . --format=json")
graph = json.loads(client.stdout)
client.run("export-pkg . --format=json", redirect_stdout="exported.json")
graph = json.loads(client.load("exported.json"))
node = graph["graph"]["nodes"]["0"]
assert "pkg/0.1" in node["ref"]
# https://github.com/conan-io/conan/issues/15041
Expand All @@ -295,6 +295,12 @@ def test_export_pkg_json(self):
assert node["rrev_timestamp"] is not None
assert node["prev_timestamp"] is not None

# Make sure the exported json file can be used for ``conan lsit --graph`` input to upload
client.run("list --graph=exported.json -gb=build --format=json")
pkglist = json.loads(client.stdout)
revs = pkglist["Local Cache"]["pkg/0.1"]["revisions"]["485dad6cb11e2fa99d9afbe44a57a164"]
assert "da39a3ee5e6b4b0d3255bfef95601890afd80709" in revs["packages"]

def test_export_pkg_no_ref(self):
client = TestClient()
conanfile = """import os
Expand Down

0 comments on commit 4beb097

Please sign in to comment.