From 228b8cb39a573275d97f4031160eb902ac29cd2d Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Tue, 20 Nov 2018 16:19:04 -0500 Subject: [PATCH 1/2] build: Also output commitmeta.json This is generally useful but especially so for the pkglist alone for higher level tools displaying releases/build outputs. Closes: #197 --- src/cmd-build | 4 ++++ src/commitmeta_to_json | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100755 src/commitmeta_to_json diff --git a/src/cmd-build b/src/cmd-build index 3ea26aa95f..f5921fa366 100755 --- a/src/cmd-build +++ b/src/cmd-build @@ -209,6 +209,10 @@ EOF # since we may be overriding data from a previous build. cat ${composejson} tmp/meta.json ${commitmeta_input_json} | jq -s add > meta.json +# And add the commit metadata itself, which includes notably the rpmdb pkglist +# in a format that'd be easy to generate diffs out of for higher level tools +"${dn}"/commitmeta_to_json "${workdir}/repo" "${commit}" > commitmeta.json + # Clean up our temporary data rm tmp -rf # Back to the toplevel build directory, so we can rename this one diff --git a/src/commitmeta_to_json b/src/commitmeta_to_json new file mode 100755 index 0000000000..a3d48bf185 --- /dev/null +++ b/src/commitmeta_to_json @@ -0,0 +1,27 @@ +#!/usr/bin/python3 -u + +import argparse +import gi +import sys + +gi.require_version('OSTree', '1.0') +gi.require_version('Json', '1.0') +from gi.repository import GLib, Gio, OSTree, Json + +parser = argparse.ArgumentParser() +parser.add_argument("repo", help="OSTree repo") +parser.add_argument("rev", help="Revision to inspect") +args = parser.parse_args() + +r = OSTree.Repo.new(Gio.File.new_for_path(args.repo)) +r.open(None) + +[_, rev] = r.resolve_rev(args.rev, True) +[_, commit, _] = r.load_commit(rev) +commitmeta = commit.get_child_value(0) + +g = Json.Generator.new() +g.set_root(Json.gvariant_serialize(commitmeta)) +stdout = Gio.UnixOutputStream.new(sys.stdout.fileno(), False) +g.set_pretty(True) +g.to_stream(stdout) From c7db7a552a33beabd1e92d9db2ac2eb5b9f08b59 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 21 Nov 2018 11:10:16 -0500 Subject: [PATCH 2/2] commitmeta_to_json: Byteswap on little-endian platforms Otherwise all numeric values will be wonky. OSTree canonicalizes to big endian. --- src/commitmeta_to_json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/commitmeta_to_json b/src/commitmeta_to_json index a3d48bf185..e1058987f1 100755 --- a/src/commitmeta_to_json +++ b/src/commitmeta_to_json @@ -19,6 +19,8 @@ r.open(None) [_, rev] = r.resolve_rev(args.rev, True) [_, commit, _] = r.load_commit(rev) commitmeta = commit.get_child_value(0) +if sys.byteorder != 'big': + commitmeta = commitmeta.byteswap() g = Json.Generator.new() g.set_root(Json.gvariant_serialize(commitmeta))