Integer detection was stopping and succeeding at the first non-integer
character, i.e. "0-4" would be detected as integer "0" and leave "-4" as
the remainder string, meaning the parser would fail later.
Improve this by requesting integer detection to also detect a separator
character and fail if the whole input until that separator is not a
valid number. That way, "0-4" fails to parse as a number, and
deserialize_any will instead properly recognize it as a string.
BUG=b:255223604
TEST=cargo test -p serde_keyvalues
Change-Id: I6b5805c7b0b82c36f61280c26b9f92f219196511
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4060599
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Parsing a quoted string as the last element of a sequence would fail
since ']' was not recognized as a separator. Fix this and factorize the
code recognizing separators into a single function to prevent this kind
of issue from happening again in the future.
BUG=None
TEST=cargo test -p serde_keyvalue
Change-Id: I1367da843787c40fb6c15a615d7cd036bddd1381
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4054812
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Structs can be parsed as part of the command-line input, if they are
enclosed within braces.
BUG=b:218223240
TEST=cargo test -p serde_keyvalue
Change-Id: I05d9d1237036c6ba464408d56c216072e285d801
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3979490
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Pujun Lun <lunpujun@google.com>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Group related bits closer and comment a bit. This does not change the
behavior of the code.
BUG=None
TEST=cargo test -p serde_keyvalue
Change-Id: I01136fbebaa3790311255492f87848e058a8ae8f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3979489
Reviewed-by: Pujun Lun <lunpujun@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Up to now only unit enums were supported. Add support for tuple and
struct enums, which can deserialize the following enum
enum VideoMode {
Fullscreen,
Window(u32, u32),
Remote { host: String },
}
from the following inputs:
mode=fullscreen
mode=window[640,480]
mode=remote[host=workstation]
This allows us to stop using flattened or dedicated enums for parsing and also
results in a less ambiguous syntax for these cases.
BUG=b:248993755
TEST=cargo test -p serde_keyvalue
TEST=cargo test
Change-Id: I142fc91fab19f4a977adec3ee36094e5f95363db
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3915040
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Sequences and sets can be supported by implementing the SeqAccess trait.
This opens up a few new scenarios for the command-line argument parser,
like support for tuples and flags collected into a set.
For instance, the following struct:
struct Layout {
resolution: (u16, u16),
scanlines: Vec<u16>,
}
Can be built from the following input:
resolution=[320,200],scanlines=[0,64,128]
BUG=b:248993755
TEST=cargo test -p serde_keyvalue
TEST=cargo test
Change-Id: Ie8972807ed6b171f5b65f6d5b6d458a2cbf450a5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3915039
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
In order to support tuples and enum variants, we need to add an extra
separator to specify the bounds of the tuple or enum. `[` and `]` are
good candidates since they are not often met in strings and are not
reserved by the shell, contrary to `(` and `)`.
BUG=b:248993755
TEST=cargo test -p serde_keyvalue
TEST=cargo test
Change-Id: I6743461f0cd3af0bce11e4978fa14776048170a5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3915038
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
This wrapper type is useless as we can just implement the access traits
on KeyValueDeserializer directly.
BUG=b:218223240
TEST=cargo test -p serde_keyvalue
Change-Id: I5013b3fea2f0a2febf182a2fd42037d1cbdbe737
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3915037
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
After deserializing a value, do not consume the next character until we
confirm it is the expected delimiter, otherwise the "expected comma"
error will be reported with an extra offset of 1.
TEST=cargo test -p serde_keyvalues
Change-Id: Id3b80a256bfee51eb1125091dcb0114c2e4af226
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3905070
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Add tests for a unit type and an untagged enum.
TEST=cargo test -p serde_keyvalue
Change-Id: Ifb840e3270624ef0e54d69b7eba2e631ffcac4e5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3906752
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Serde's `flatten` property is very useful to transparently add
parameters to a command-line argument, but it comes with a few
important limitations. Document them and discourage its use whenever
possible.
BUG=b:218223240
BUG=b:241300017
TEST=cargo build
Change-Id: I822645acbf0ef563d0c0d14f719571093a5152f2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3889327
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
We will need to control deserialization from a lower-level in order to
remove the `flatten` attribute from the VhostUserParams struct, so make
the KeyValueDeserializer interface available publicly.
BUG=b:217480043
TEST=cargo build
Change-Id: I366a71ef1b4f38ba4673478dc7ae8b928a8f57d3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3889328
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
These methods are better to predict the type of what follows than just
parsing the next character. For instance, '1foo' was interpreted as an
integer whereas it should be a string.
BUG=b:218223240
BUG=b:241300017
TEST=cargo test -p serde_keyvalue
TEST=cargo test
Change-Id: I9a0a3cb73e06783784d47450de7d291adf41aa53
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3889330
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This search/replace updates all copyright notices to drop the
"All rights reserved", Use "ChromiumOS" instead of "Chromium OS"
and drops the trailing dots.
This fulfills the request from legal and unifies our notices.
./tools/health-check has been updated to only accept this style.
BUG=b:246579983
TEST=./tools/health-check
Change-Id: I87a80701dc651f1baf4820e5cc42469d7c5f5bf7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3894243
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Support parsing negative numbers with a specified radix as e.g.
`-0xff00` instead of `0x-ff00`. This is a potentially breaking change
but I don't believe anyone made use of the former syntax anyway.
The new number parser has the nice side-effect of removing some extra
code, and also signaling parsing errors more accurately, so that's an
added bonus. On the other hand we lose the distinction between "invalid
number" and "expected number", but that distinction was dubious anyway
so losing it is for the better IMHO.
BUG=b:218223240
TEST=cargo test -p serde_keyvalue
Change-Id: I6b2943ecd0df92071afe0682b339dcf5b59e2826
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3853315
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Use the nom crate for parsing. This will arguably be both simpler to
read and more reliable than our current ad-hoc parser.
Add a few extra tests to enforce the new rules that the new parser is
supposed to enforce.
BUG=b:218223240
TEST=cargo test -p serde_keyvalues -p crosvm
TEST=ARCVM starts successfully.
Change-Id: I4ea188ffe8aee872071c900793c50127855403ec
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3822428
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
- Remove trailing ::{self} on all use statements
- Remove any resulting single-level use statements (e.g. use libc;)
- Reformat with `tools/fmt --nightly`
BUG=b:239937122
TEST=tools/dev_container tools/presubmit --all
Change-Id: I8afd1b0458ca6d08d9b41a24583f7d4148597ccb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3798973
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
crosvm is switching the import style to use one import per line.
While more verbose, this will greatly reduce the occurence of merge
conflicts going forward.
Note: This is using a nightly feature of rustfmt. So it's a one-off
re-format only. We are considering adding a nightly toolchain to
enable the feature permanently.
BUG=b:239937122
TEST=CQ
Change-Id: Id2dd4dbdc0adfc4f8f3dd1d09da1daafa2a39992
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784345
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
This adds support for parsing hex `m=0x1234abcd` octal `0o755` and
binary `m=0o1100` values according the their prefix. Negative numbers
can also be specified by adding a `-` after the prefix.
Note that negative values like `m=-0x1234` don't work, largely as an
artifact of the way the Num trait works. This could probably be fixed,
but given hex, octal, and binary numbers tend to be used in unsigned
situations most of the time this shouldn't be an issue.
The main motivation for this is the debugcon serial device, which
accepts an argument which is an x86 IO port. These are much more
naturally described in hex.
BUG=b:233610263
Change-Id: Ic68bacd772de6aebfaad0de7b8aa6faf5d4c1555
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3671595
Commit-Queue: Mike Gerow <gerow@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Add a crate for deserializing command-line options given as key-values.
This crate leverages serde to deserialize key-value argument strings (a
commonly used pattern in crosvm) into configuration structures. This
will allow us to remove a big part of the manual parsing currently done
in `main.rs`, will provide consistent arguments to the `crosvm run` and
`crosvm device` commands, and results in more precise error reporting.
The use of serde will also allow us to similarly deserialize
configuration structures from configuration files with very little extra
code involved.
As explained in the crate's documentation, its main entry point is a
`from_key_values` function that allows a build a struct implementing
serde's `Deserialize` trait from a key/values string.
In order to integrate transparently with `argh`, there is also a
`FromKeyValue` derive macro that automatically implements `FromArgValue`
for structs deriving from it.
BUG=b:218223240
BUG=b:217480043
TEST=cargo build
TEST=cargo test -p serde_keyvalue
Change-Id: Id6316e40150d5f08a05e6f04e39ecbc73d72dfa0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3439669
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>