Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compose+rust: Parse includes via Rust too #1574

Closed
wants to merge 4 commits into from

Conversation

cgwalters
Copy link
Member

The core bug here is that previously if we had multiple YAML files
in include, we ended up overwriting self->treefile_rs for the
last one. Handling inheritance worked, but it broke rojig since
we generate the specfile Rust side.

Fix this by moving more of the parsing into Rust. There are a
lot of advantages to this - the include handling was ugly un-typesafe C code
with no unit tests, now it's memory safe Rust with unit tests.

The downside here is I ended up spelling out the list of fields
again - there's probably a way to unify this via macros but
for now I think this is OK.

@cgwalters
Copy link
Member Author

Depends: #1573

@cgwalters cgwalters changed the title compose+rust: Parse includes via Rust too WIP: compose+rust: Parse includes via Rust too Sep 23, 2018
@cgwalters cgwalters added the WIP label Sep 23, 2018
@cgwalters
Copy link
Member Author

This is going to need more work around the treefile context dir array and add-files.

cgwalters added a commit to cgwalters/rpm-ostree that referenced this pull request Sep 24, 2018
The core bug here is that previously if we had multiple YAML files
in include, we ended up overwriting self->treefile_rs for the
last one. Handling inheritance worked, but it broke rojig since
we generate the specfile Rust side.

Let's have first-one-wins semantics for now.  I have a bigger
fix incoming in coreos#1574
rh-atomic-bot pushed a commit that referenced this pull request Sep 24, 2018
The core bug here is that previously if we had multiple YAML files
in include, we ended up overwriting self->treefile_rs for the
last one. Handling inheritance worked, but it broke rojig since
we generate the specfile Rust side.

Let's have first-one-wins semantics for now.  I have a bigger
fix incoming in #1574

Closes: #1576
Approved by: jlebon
@rh-atomic-bot
Copy link

☔ The latest upstream changes (presumably 2e56784) made this pull request unmergeable. Please resolve the merge conflicts.

@cgwalters cgwalters removed the WIP label Sep 26, 2018
@cgwalters cgwalters changed the title WIP: compose+rust: Parse includes via Rust too compose+rust: Parse includes via Rust too Sep 26, 2018
@cgwalters
Copy link
Member Author

OK, this rolls up two other PRs (#1580 and #1581), but should be good to review now.

@cgwalters
Copy link
Member Author

One big reason I'm doing this is that trying to use treefile inheritance aggressively for Fedora CoreOS, I tripped over things like inheriting from a treefile with postprocess-script not working.

The big thing this PR doesn't fix is repos and .repo files. That one is a bit tricky...would be cleaner if libdnf had a dnf_context_set_repo_dirS (plural).

cgwalters added a commit to cgwalters/os that referenced this pull request Sep 26, 2018
The primary reason I'm doing this is that today rpm-ostree's
treefile inheritance doesn't quite do what one wants with external
files.  There's some major work on that in
coreos/rpm-ostree#1574
But let's not block on/require it.

Furthermore, using the inline `postprocess` value allows us
to clearly demarcate the `maipo`-specific hacks in that file.
cgwalters added a commit to cgwalters/os that referenced this pull request Sep 26, 2018
The primary reason I'm doing this is that today rpm-ostree's
treefile inheritance doesn't quite do what one wants with external
files.  There's some major work on that in
coreos/rpm-ostree#1574
But let's not block on/require it.

Furthermore, using the inline `postprocess` value allows us
to clearly demarcate the `maipo`-specific hacks in that file.
@rh-atomic-bot
Copy link

☔ The latest upstream changes (presumably 8df07a3) made this pull request unmergeable. Please resolve the merge conflicts.

@rh-atomic-bot
Copy link

☔ The latest upstream changes (presumably 7595bce) made this pull request unmergeable. Please resolve the merge conflicts.

@cgwalters cgwalters force-pushed the json-parse-via-rust branch from 17834de to 5ad2867 Compare October 2, 2018 21:24
@cgwalters
Copy link
Member Author

Rebased 🏄‍♂️ and now passing tests!

Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sane at a high level.

rust/src/treefile.rs Outdated Show resolved Hide resolved
src/app/rpmostree-compose-builtin-tree.c Show resolved Hide resolved
src/libpriv/rpmostree-postprocess.c Show resolved Hide resolved
if let Some(ref mut srcv) = src.take() {
let mut v = dest.take().map_or_else(|| vec![], |v| v);
v.append(srcv);
*dest = Some(v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, this is actually slightly changing the semantics now. Before we were prepending fields from includes, but now we're appending, right?

Which I think could matter in some cases? E.g. just from a quick scan:

  • initramfs_args is passed directly down to dracut and not handled by us
  • postprocess, i.e. inlined script ordering
  • add-files... although ahh right, we essentially use NOREPLACE here so it would error out anyway on the second try to write to the same destination.

@jlebon
Copy link
Member

jlebon commented Oct 3, 2018

Looks sane at a high level.

That makes it sound like I didn't review this in depth, but I did. :) The high level approach does look good though.

Since I got it backwards when rewriting it in Rust.
This follows up to coreos#1576
AKA commit 2e56784 - we now process
treefile inheritance in Rust code.  Previously for elements which
reference external files (`postprocess-script` and `add-files`)
we'd hardcoded things to only look in the first context dir.

Now we open file descriptors in the Rust side for these "externals"
as we're parsing, and load them C side.  Hence we'll correctly handle
a `postprocess-script` from an included config.

Other advantages are that the include handling was ugly un-typesafe C code
with no unit tests, now it's memory safe Rust with unit tests.

The downside here is I ended up spelling out the list of fields
again - there's probably a way to unify this via macros but
for now I think this is OK.
@cgwalters
Copy link
Member Author

I'm reworking this on top of a test case for inheritance. Also doing so revealed we weren't inheriting the default_target key.

@cgwalters cgwalters force-pushed the json-parse-via-rust branch from 5ad2867 to 287b122 Compare October 4, 2018 01:23
@cgwalters
Copy link
Member Author

OK, now with new test case and fixups ⬆️

@@ -24,6 +24,8 @@ pysetjsonmember "postprocess-script" \"$PWD/postprocess.sh\"
pysetjsonmember "postprocess" '["""#!/bin/bash
touch /usr/share/postprocess-testing""",
"""#!/bin/bash
set -xeuo pipefail
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah and also this was missing before...I was confused why the test wasn't failing for me with the previous inverted Rust code 😢

@jlebon
Copy link
Member

jlebon commented Oct 4, 2018

LGTM!
@rh-atomic-bot r+ 287b122

@rh-atomic-bot
Copy link

⚡ Test exempted: pull fully rebased and already tested.

rh-atomic-bot pushed a commit that referenced this pull request Oct 4, 2018
This follows up to #1576
AKA commit 2e56784 - we now process
treefile inheritance in Rust code.  Previously for elements which
reference external files (`postprocess-script` and `add-files`)
we'd hardcoded things to only look in the first context dir.

Now we open file descriptors in the Rust side for these "externals"
as we're parsing, and load them C side.  Hence we'll correctly handle
a `postprocess-script` from an included config.

Other advantages are that the include handling was ugly un-typesafe C code
with no unit tests, now it's memory safe Rust with unit tests.

The downside here is I ended up spelling out the list of fields
again - there's probably a way to unify this via macros but
for now I think this is OK.

Closes: #1574
Approved by: jlebon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants