Skip to content

Commit

Permalink
treefile: Support greater than/less than versions for packages in tre…
Browse files Browse the repository at this point in the history
…efile

Add a helper function for whitespace_split_packages() so that it now splits a String by whitespace only if it is not wrapped between single quotes.
This should allow RHCOS to use syntax like podman > 1.4 in the treefile.
  • Loading branch information
kelvinfan001 committed Jun 30, 2020
1 parent f3ccd92 commit f681f98
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
34 changes: 33 additions & 1 deletion rust/src/treefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,42 @@ impl TreefileExternals {
/// array elements.
fn whitespace_split_packages(pkgs: &[String]) -> Vec<String> {
pkgs.iter()
.flat_map(|pkg| pkg.split_whitespace().map(String::from))
.flat_map(|element| split_whitespace_unless_quote(element).map(String::from))
.collect()
}

// Helper for whitespace_split_packages().
// Splits a String by whitespace unless substring is wrapped between single quotes
// and returns split Strings in an Iterator.
fn split_whitespace_unless_quote(element: &String) -> std::vec::IntoIter<String> {
let mut quoted_pkgs: Vec<String> = vec![];
let mut to_whitespace_split: Vec<String> = vec![];
let mut start_index = 0;
let mut looping_over_quoted_pkg = false;
for (i, c) in element.chars().enumerate() {
if c == '\'' {
if looping_over_quoted_pkg {
quoted_pkgs.push(String::from(&element[start_index..i]));
looping_over_quoted_pkg = false;
} else {
to_whitespace_split.push(String::from(&element[start_index..i]));
looping_over_quoted_pkg = true;
}
start_index = i + 1;
}
if i == element.len() - 1 {
to_whitespace_split.push(String::from(&element[start_index..]));
}
}
let mut ret: Vec<String> = vec![];
ret.extend(quoted_pkgs);
for item in to_whitespace_split.iter() {
ret.extend(item.split_whitespace().map(String::from));
}

ret.into_iter()
}

#[derive(Serialize, Deserialize, Debug, PartialEq)]
enum BootLocation {
#[serde(rename = "new")]
Expand Down
8 changes: 6 additions & 2 deletions tests/compose/test-misc-tweaks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ treefile_append "repos" '["test-repo"]'
# test `recommends: true` (test-basic[-unified] test the false path)
build_rpm foobar recommends foobar-rec
build_rpm foobar-rec
build_rpm quuz
build_rpm corge

echo gpgcheck=0 >> yumrepo.repo
ln "$PWD/yumrepo.repo" config/yumrepo.repo
# the top-level manifest doesn't have any packages, so just set it
treefile_append "packages" '["foobar"]'
treefile_append "packages" $'["\'foobar >= 0.5\' quuz \'corge < 1.0.0\'"]'

# With docs and recommends, also test multi includes
cat > config/documentation.yaml <<'EOF'
Expand Down Expand Up @@ -158,6 +160,8 @@ echo "ok /tmp"
rpm-ostree db list --repo=${repo} ${treeref} > pkglist.txt
assert_file_has_content_literal pkglist.txt 'foobar'
assert_file_has_content_literal pkglist.txt 'foobar-rec'
assert_file_has_content_literal pkglist.txt 'quuz'
assert_file_has_content_literal pkglist.txt 'corge'
echo "ok recommends"

# Test overlays/overrides
Expand All @@ -183,4 +187,4 @@ if runcompose |& tee err.txt; then
assert_not_reached "Successfully composed with add-files for /var/lib?"
fi
assert_file_has_content_literal err.txt "Unsupported path in add-files: /var"
echo "ok bad add-files"
echo "ok bad add-files"

0 comments on commit f681f98

Please sign in to comment.