Migrate all crates from edition 2021 to 2024. This includes
updating Cargo.toml files and fixing code compatibility issues.
The MSRV is bumped to 1.85.0 to support edition 2024.
Note: global_init() requires #[allow(unsafe_code)] for
std::env::set_var which is now unsafe in edition 2024.
This is safe because the function is called early in main()
before any threads are spawned.
Closes: #1414
Signed-off-by: Daniele Guarascio <guarascio.daniele@gmail.com>
Really we want to just return the original slice that the Parameter
was created from. This also aligns with how Cmdline and ParameterKey
impl Display.
Where this really matters the most is to ensure we retain the quoting
that the parameter was created with, so I added a test just to sanity
check that. Before this change the test would fail because "foo"
would be stripped of its quotes and just rendered as foo unquoted.
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
Primary motivation here is that these two should be equivalent:
foo="quoted value"
"foo=quoted value"
This also adds tests for a few more oddball cases that weren't covered
before but clarify the expected kernel behavior.
Closes: #1737
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
This commit refactors the kernel_cmdline parsing implementation to
reduce code duplication and provide a clearer separation of concerns.
Key changes:
1. Introduced CmdlineIterBytes as a dedicated iterator for splitting
the command line into raw parameter byte slices. This centralizes
the quote-aware whitespace splitting logic in one place.
2. Refactored CmdlineIter to wrap CmdlineIterBytes instead of
duplicating the splitting logic. This eliminates redundant code
and ensures consistent behavior.
3. Consolidated Parameter::parse and Parameter::parse_one into a
single parse() method. Parameter::parse now uses CmdlineIterBytes
directly to find the first parameter, then passes it to
parse_internal() which assumes the input is already a single
parameter.
4. Added iter_bytes() and iter_str() methods to Cmdline for cases
where users need raw byte slices or strings without full Parameter
parsing overhead.
5. Removed utf8::Parameter::parse_one() in favor of a simplified
parse() that wraps the bytes implementation.
Assisted-by: Claude Code (Sonnet 4.5)
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
Add a new `add` method to both `bytes::Cmdline` and `utf8::Cmdline`
that appends parameters without modifying existing ones. Unlike
`add_or_modify`, this method preserves duplicate keys with different
values (e.g., multiple `console=` parameters), which is valid for
certain kernel parameters.
The method returns `Action::Added` when a new parameter is appended,
and `Action::Existed` when the exact parameter already exists.
Assisted-by: Claude Code (Sonnet 4.5)
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
This makes it ergonomic to take two `Cmdline`s and update one by
appending the parameters in the other.
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
In some cases it will be important to differentiate whether we added a
net-new parameter vs. modifying an existing parameter.
Motivated by trying to update bootc_kargs to use kernel_cmdline. We
want to parse the booted kargs, and then merge with any args defined
in kargs.d. But it should error if a value in kargs.d already exists
in the booted system with a different value. The previous API did not
provide enough visibility to make this determiniation.
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
This is an obvious thing one might want to do. Ensures we can make an
owned Cmdline directly from an owned String.
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
The (now-named) parse_one method is not particularly useful outside of
`CmdlineIter`. Almost always end users don't care about extra
unparsed content, they just want the `Option<Parameter>`.
This greatly improves ergnomics for users so they can create
parameters like...
`Parameter::parse("foo=bar").unwrap()`
... knowing at the call-site that "foo=bar" is a valid parameter so
the `unwrap()` is safe.
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
We already impl AsRef<str> but this just makes it more convenient to
render the command line for users.
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
Add `add_or_modify` and `remove` methods to `Cmdline` in both `bytes`
and `utf8` modules, along with unit tests.
Closes: #1596
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
- Removed `From<bytes::Parameter>` implementation for
`utf8::Parameter` and similar for `utf8::ParameterKey`. This was
public and would allow end-users to construct utf8 parameters from
non-utf8 data. Replaced internally with `from_bytes` in the places
where we know we can safely convert known-UTF-8 data.
- Added `TryFrom<bytes::Paramter>` implementation for
`utf8::Parameter` to allow checked conversions, plus tests.
- Added `iter_utf8` and `find_utf8` to `bytes::Cmdline`, plus tests.
- Updated `find_root_args_to_inherit` in bootc to use these
improvements. Notably bootc will now allow non-UTF8 data in the
kernel cmdline, *unless* it occurs in parameters that bootc is
explicitly looking for.
- Added more tests to `find_root_args_to_inherit` to validate expected
functionality with non-UTF-8 data.
- Fixed a parser bug that gemini pointed out with unmatched quotes,
plus tests to check for that.
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
Split the kernel command line parsing functionality into two focused
modules. The `bytes` module handles raw byte parsing without UTF-8
requirements, matching kernel behavior for arbitrary byte
sequences. The `utf8` module provides string-based parsing for cases
where UTF-8 validation is needed. The `utf8` module reuses the
`bytes` module primitives where possible, and uses the fact that
`utf8::Cmdline` can only be constructed from valid UTF-8 to do
unchecked conversions between the two.
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
This moves the bulk of the parsing logic into `Parameter`. Its
`parse` method returns a 2-tuple, its items being:
1. An `Option<Parameter>` which contains the parsed `Parameter`.
This will be `None` if the provided input is empty or contains only
whitespace.
2. A byte slice of the rest of the input which was not consumed by
the yielded `Parameter`.
This also adds new tests for some cases that would fail under the
previous parser implementation.
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
This appears to have been accidentally added somewhere along the way,
and I would like to use these in composefs-boot.
Also fixes duplicate docstring copy/paste error on
`require_value_of_utf8`.
Signed-off-by: John Eckersberg <jeckersb@redhat.com>
Creates a new dedicated crate for kernel command line parsing functionality,
moving it out of bootc-lib for better separation of concerns and modularity.
Changes:
- Create new bootc-kernel-cmdline crate under crates/kernel_cmdline/
- Move kernel_cmdline.rs from bootc-lib to the new crate as lib.rs
- Add bootc-kernel-cmdline dependency to bootc-lib
- Update imports in bootc-lib to use bootc_kernel_cmdline:: namespace
- Add missing Debug derive and documentation to fix lints
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: John Eckersberg <jeckersb@redhat.com>