summary refs log tree commit diff
path: root/src/argument.rs
Commit message (Collapse)AuthorAge
* Merge remote-tracking branch 'origin/master'Alyssa Ross2020-05-10
|\
| * crosvm: Apply cargo fix for some clippy errorsKeiichi Watanabe2020-04-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Executed the following command to fix trivial style problems automatically. $ rustup run nightly cargo fix -Z unstable-options --clippy \ --all-features --all-targets BUG=chromium:908640 TEST=build Change-Id: I8a42806dc573b25d4ca918112e7b420793261d37 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2145537 Tested-by: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* | Merge remote-tracking branch 'origin/master'Alyssa Ross2020-03-26
|\|
| * crosvm: Change expected field to String in InvalidValueJudy Hsiao2020-03-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change the type of argument::Error::InvalidValue::expected from "&'static str" to String. It allows the lower level parse error object to handle the output of the expected value so that the rule of parsing will not be duplicated. For example, instead of: ``` v.parse::<Settings>() .map_err(|e| argument::Error::InvalidValue { value: v.to_string(), expected: "The value of setting should null or cras", })?; ``` we can have: ``` v.parse::<Settings>() .map_err(|e| argument::Error::InvalidValue { value: v.to_string(), expected: e.to_string(), })?; ``` and the expected value can be handled in the Display implementaion of Settings::ParseError. BUG=b:140866281 TEST=cargo build Change-Id: Ieba12a21103945fe0e47c70a190a4e5d985af537 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2103605 Tested-by: Judy Hsiao <judyhsiao@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Auto-Submit: Judy Hsiao <judyhsiao@chromium.org> Commit-Queue: Judy Hsiao <judyhsiao@chromium.org>
* | crosvm: improve crosvm run --help outputAlyssa Ross2020-03-09
|/ | | | | | | | | | | | | | | The specifiers and descriptions for crosvm options are just too long to fit into a table. Options were already eclipsing the widths of the table cells, and sizing them correctly just made the table infeasibly wide. So, instead, just print out paragraphs for each option, and stop trying to fit things into a table. Use this opportunity to add some spacing and make key value lists within option descriptions more readable. Also, make formatting consistent. Consistent spacing between sentences, consistent default output, etc.
* Fix parsing arguments that require a value at the end of command lineDmitry Torokhov2019-12-22
| | | | | | | | | | | | | | | | | | | | | | | We may be in state of waiting for the value for the parameter, and run out of the parameters. In this case we should try to parse the parameter as if it does not have a value and see if that succeeds. This makes sure that crosvm run ... --plugin-mount fails with error that --plugin-mount option needs a value instead of succeeding. BUG=None TEST=cargo test Change-Id: I9f3f1f3c7e6e2ca88efed1eeea5a52dd4aae70ef Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1975097 Reviewed-by: Dmitry Torokhov <dtor@chromium.org> Tested-by: Dmitry Torokhov <dtor@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
* When parsing --parameter <value> argument do not clobber parser errorsDmitry Torokhov2019-12-22
| | | | | | | | | | | | | | | | | | | | | | When parsing arguments in form of "--parameter <value>", because it is yet unclear whether the parameter needs a value or not, we first try to parse it together with the next argument, and if that fails, try to parse it standalone. If both fail, then we should take the error from the first one, as it is more informative. This way, doing crosvm run --plugin ... --plugin-mount bin --plugin-mount lib will fail with error that "bin is not absolute path" and not that value is missing for "--plugin-mount". BUG=None TEST=cargo test Change-Id: Icc3bb0fcab4fb90e38eff3d116679091b598120d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1975096 Commit-Queue: Dmitry Torokhov <dtor@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* Adds a flag_or_value command line argument optionJason Macnak2019-12-09
| | | | | | | | | | | | | | | | | | | | | | ... to allow for specifying either '--gpu' to get default params or '--gpu=width=800,height=600,egl,surfaceless' to get custom params. Note: this introduces some potential ambiguity if the flag_or_value argument is the last arg specified before a positional argument. For example, 'crosvm run --gpu something' could either be parsed as a single value ('--gpu=something') or a flag and a positional argument ('--gpu' and 'something'). This change currently expects that the functor passed to set_arguments() will return an error on '--gpu=something' in order to resolve the disambiguity. BUG=b:134086390 TEST=built crosvm and booted cuttlefish locally Change-Id: Ib9be604af82583a39d7bd0a403e2168ef7350389 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1929603 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Jason Macnak <natsu@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* split crosvm into a library and a main "crosvm" binaryZach Reizner2019-08-06
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change has 3 parts: - Modify the Cargo.toml to point at the bin and the lib source. - Move modules and Config struct into the lib source - Fix the argument/plugins module's doc comments which had never been tested. The motivation for this change is to make testing crosvm's major functionality (booting guest kernels, emulating hardware, etc) easier to do from a cargo test. Being able to launce a crosvm config via the API instead of the binary's command line will be possible with this change. A side benefit is that this also enables doc tests in the lib side of crosvm. The doc tests in binaries are not run due to a limitation in how they get tested by cargo. TEST=cargo test ./build_test kokoro/kokoro_simulator.sh emerge crosvm BUG=None Change-Id: I9d4b3a24231b895e8dfaf9e7b0f2b33350772041 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1730333 Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Zach Reizner <zachr@chromium.org>
* edition: Eliminate ref keywordDavid Tolnay2019-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As described in: https://doc.rust-lang.org/edition-guide/rust-2018/ownership-and-lifetimes/default-match-bindings.html which also covers the new mental model that the Rust Book will use for teaching binding modes and has been found to be more friendly for both beginners and experienced users. Before: match *opt { Some(ref v) => ..., None => ..., } After: match opt { Some(v) => ..., None => ..., } TEST=cargo check --all-features TEST=local kokoro Change-Id: I3c5800a9be36aaf5d3290ae3bd3116f699cb00b7 Reviewed-on: https://chromium-review.googlesource.com/1566669 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* main: add --cpu-affinity option to pin VCPUsDaniel Verkamp2019-04-09
| | | | | | | | | | | | | | | | | | This allows setting the affinity of the VCPU threads to specific host CPUs. Note that each individual CPU has its affinity set to the full set of CPUs specified, so the host kernel may still reschedule VCPU threads on whichever host CPUs it sees fit (within the specified set). BUG=chromium:909793 TEST=build_test Change-Id: I09b893901caf91368b64f5329a6e9f39027fef23 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1554865 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* crosvm: avoid deprecated trim_left_matchesDaniel Verkamp2019-03-25
| | | | | | | | | | | | | | As of Rust 1.33.0, use of trim_left_matches warns that it is deprecated and should be replaced with trim_start_matches. BUG=None TEST=build_test Change-Id: I42bd5dba10aeffcd076882d28cb02551c50ff614 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1534963 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* error: Consistently use Display instead of error description()David Tolnay2019-03-02
| | | | | | | | | | | | | | | | The description method is deprecated and its signature forces less helpful error messages than what Display can provide. BUG=none TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu Change-Id: I27fc99d59d0ef457c5273dc53e4c563ef439c2c0 Reviewed-on: https://chromium-review.googlesource.com/1497735 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* lint: Resolve the easier clippy lintsDavid Tolnay2018-12-03
| | | | | | | | | | | | | | | | | | | | Hopefully the changes are self-explanatory and uncontroversial. This eliminates much of the noise from `cargo clippy` and, for my purposes, gives me a reasonable way to use it as a tool when writing and reviewing code. Here is the Clippy invocation I was using: cargo +nightly clippy -- -W clippy::correctness -A renamed_and_removed_lints -Aclippy::{blacklisted_name,borrowed_box,cast_lossless,cast_ptr_alignment,enum_variant_names,identity_op,if_same_then_else,mut_from_ref,needless_pass_by_value,new_without_default,new_without_default_derive,or_fun_call,ptr_arg,should_implement_trait,single_match,too_many_arguments,trivially_copy_pass_by_ref,unreadable_literal,unsafe_vector_initialization,useless_transmute} TEST=cargo check --features wl-dmabuf,gpu,usb-emulation TEST=boot linux Change-Id: I55eb1b4a72beb2f762480e3333a921909314a0a2 Reviewed-on: https://chromium-review.googlesource.com/1356911 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* cargo fmt all source codeZach Reizner2018-10-09
| | | | | | | | | | | | | | Now that cargo fmt has landed, run it over everything at once to bring rust source to the standard formatting. TEST=cargo test BUG=None Change-Id: Ic95a48725e5a40dcbd33ba6d5aef2bd01e91865b Reviewed-on: https://chromium-review.googlesource.com/1259287 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: argument parsing without clapZach Reizner2017-09-02
This removes the clap dependency by replacing that functionality with a custom written parser. Binary size is reduced by about 60% in optimized and stripped mode. TEST=cargo run -- run -h BUG=None Change-Id: I2eaf6fcff121ab16613c444693d95fdf3ad04da3 Reviewed-on: https://chromium-review.googlesource.com/636011 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>