config: Improve API for DiagnosticsLogging configuration. - #44703
Conversation
mrobinson
left a comment
There was a problem hiding this comment.
This looks good. My main concern is the addition of 5 new crate dependencies to the servo itself. Is it possible to avoid the dependency on bitvec somehow?
| #[strum(to_string = "style-tree")] | ||
| #[strum(message = "Log the DOM after each restyle")] |
There was a problem hiding this comment.
Maybe we should also include the rustdoc string so that these values also show up in the API documentation?
There was a problem hiding this comment.
I think I tried that as strum also allows programmatically retrieving a variant's documentation string, but that means we can't split the documentation as message and detailed_message. But perhaps detailed_message is not very useful as only two variants have that. I'll remove detailed_message and switch message to doc strings.
|
|
||
| if cli_options.contains(&"help".into()) { | ||
| // TODO: Remove hardcoded binary name by perhaps receiving this a an argument. | ||
| println!("Usage: servoshell -Z option,[option,...]\n\twhere options include:"); |
There was a problem hiding this comment.
| println!("Usage: servoshell -Z option,[option,...]\n\twhere options include:"); | |
| println!( | |
| "Usage: {} -Z option,[option,...]\n\twhere options include:" | |
| env::args().first().unwrap_or_default() | |
| ); |
| } | ||
|
|
||
| if cli_options.contains(&"help".into()) { | ||
| // TODO: Remove hardcoded binary name by perhaps receiving this a an argument. |
There was a problem hiding this comment.
| // TODO: Remove hardcoded binary name by perhaps receiving this a an argument. | |
| // TODO: Remove hardcoded binary name by perhaps receiving this as an argument. |
Though maybe you could just do this with the code below?
There was a problem hiding this comment.
I didn't want to do that because the grand parent in the call chain of this function is already doing the same work to split the args and explictly passing down the args without binary. We can just thread that through the call chain, but I haven't tested what the binary name would look like in Android or OHOS, so I decided to handle it separately.
mukilan
left a comment
There was a problem hiding this comment.
Is it possible to avoid the dependency on
bitvecsomehow?
We could use a HashSet<DiagnosticLoggingOptions> instead if we are not concerned about space usage or the performance overhead during layout. Otherwise, I am not sure how to avoid the dependency without rolling our own BitArray like data structure.
| #[strum(to_string = "style-tree")] | ||
| #[strum(message = "Log the DOM after each restyle")] |
There was a problem hiding this comment.
I think I tried that as strum also allows programmatically retrieving a variant's documentation string, but that means we can't split the documentation as message and detailed_message. But perhaps detailed_message is not very useful as only two variants have that. I'll remove detailed_message and switch message to doc strings.
| } | ||
|
|
||
| if cli_options.contains(&"help".into()) { | ||
| // TODO: Remove hardcoded binary name by perhaps receiving this a an argument. |
There was a problem hiding this comment.
I didn't want to do that because the grand parent in the call chain of this function is already doing the same work to split the args and explictly passing down the args without binary. We can just thread that through the call chain, but I haven't tested what the binary name would look like in Android or OHOS, so I decided to handle it separately.
ab2f2ae to
5d4fc99
Compare
5d4fc99 to
53082a3
Compare
Another option is to simply use a |
I think this is probably fine for now. Thanks! |
53082a3 to
ea33c29
Compare
|
I've updated the PR to use |
The current `extend_from_string` API is not suitable for embedders as it was written specifically for servoshell and therefore makes a lot of assumptions - the binary name, the format and text of the help message, etc. It also exits the whole process after displaying the help string. Change the behaviour of this API by making it responsible only for parsing string flags. The logic for formatting and displaying the help message is moved to servoshell. This patch also switches the `DiagnosticsLogging` from a struct to a `BitArray` and exposes strum-based APIs so that the embedder can enumerate the available diagnostics option, retrieve the documentation string associated with each option and also parse the strings back to a valid `DiagnosticsLogging` struct. Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
ea33c29 to
7396780
Compare
The current
extend_from_stringAPI is not suitable for embedders as it was written specifically for servoshell and therefore makes a lot of assumptions - the binary name, the format and text of the help message, etc. It also exits the whole process after displaying the help string.Change the behaviour of this API by making it responsible only for parsing string flags. The logic for formatting and displaying the help message is moved to servoshell. This patch also switches the
DiagnosticsLoggingfrom a struct to aBitArrayand exposes strum-based APIs so that the embedder can enumerate the available diagnostics option, retrieve the documentation string associated with each option and also parse the strings back to a validDiagnosticsLoggingstruct.Testing: Includes a unit test for the API used by embedders.