From 02dbdcc2ef7d6c5b7528d2ab75c803f22639ae4c Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Tue, 26 Feb 2019 10:51:14 -0500 Subject: [PATCH] rust/treefile: Add basearch key Add a `basearch` key to the manifest. This can be used at compose time to assert the architecture the compose is running on. Though my motivation is for the common case where it gets omitted from the input manifest and gets automatically added by rpm-ostree into `/usr/share/rpm-ostree/treefile.json` for introspection on the client. (The crucial part here is that the treefile created by rpm-ostree remains deserializable into a `TreeComposeConfig`). Closes: https://github.com/coreos/fedora-coreos-tracker/issues/154 --- rust/src/treefile.rs | 18 ++++++++++++++++++ tests/compose-tests/libbasic-test.sh | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/rust/src/treefile.rs b/rust/src/treefile.rs index 870bd72fcf..1012b1a6f9 100644 --- a/rust/src/treefile.rs +++ b/rust/src/treefile.rs @@ -96,6 +96,22 @@ fn treefile_parse_stream( } }; + treefile.basearch = match (treefile.basearch, basearch) { + (Some(treearch), Some(arch)) => { + if treearch != arch { + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + format!("Invalid basearch: cross-composes are not supported"), + ).into()) + } else { + Some(treearch) + } + } + (None, Some(arch)) => Some(arch.into()), + // really, only for tests do we not specify a basearch. let's just canonicalize to None + (_, None) => None, + }; + // Substitute ${basearch} treefile.treeref = match (basearch, treefile.treeref.take()) { (Some(basearch), Some(treeref)) => { @@ -501,6 +517,8 @@ struct TreeComposeConfig { #[serde(rename = "ref")] #[serde(skip_serializing_if = "Option::is_none")] treeref: Option, + #[serde(skip_serializing_if = "Option::is_none")] + basearch: Option, // Optional rojig data #[serde(skip_serializing_if = "Option::is_none")] rojig: Option, diff --git a/tests/compose-tests/libbasic-test.sh b/tests/compose-tests/libbasic-test.sh index d6fefd684b..401ca6b150 100644 --- a/tests/compose-tests/libbasic-test.sh +++ b/tests/compose-tests/libbasic-test.sh @@ -101,3 +101,7 @@ assert_file_has_content pkglist.txt 'systemd' assert_file_has_content pkglist.txt 'systemd-bootchart' echo "ok compose pkglist" } + +ostree --repo=${repobuild} cat ${treeref} /usr/share/rpm-ostree/treefile.json > treefile.json +assert_jq treefile.json '.basearch == "x86_64"' +echo "ok basearch"