Skip to content

Commit

Permalink
rust/treefile: Add basearch key
Browse files Browse the repository at this point in the history
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: coreos/fedora-coreos-tracker#154
  • Loading branch information
jlebon committed Feb 26, 2019
1 parent 7f02b92 commit 02dbdcc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions rust/src/treefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ fn treefile_parse_stream<R: io::Read>(
}
};

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)) => {
Expand Down Expand Up @@ -501,6 +517,8 @@ struct TreeComposeConfig {
#[serde(rename = "ref")]
#[serde(skip_serializing_if = "Option::is_none")]
treeref: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
basearch: Option<String>,
// Optional rojig data
#[serde(skip_serializing_if = "Option::is_none")]
rojig: Option<Rojig>,
Expand Down
4 changes: 4 additions & 0 deletions tests/compose-tests/libbasic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 02dbdcc

Please sign in to comment.