-
Notifications
You must be signed in to change notification settings - Fork 452
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
Refactor Config structs according to features #800
base: master
Are you sure you want to change the base?
Conversation
As it was stated in Spotifyd#349, structs like `SharedConfigValues` or `SpotifydConfig` contain fields like `mixer`, `control` and `device` which only apply if `alsa-backend` feature is enabled. Therefore, it would be nice if these fields were only documented when the feature is enabled as well as used. Closes Spotifyd#349
src/config.rs
Outdated
@@ -494,28 +505,52 @@ impl SharedConfigValues { | |||
} | |||
} | |||
|
|||
cfg_if::cfg_if! { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this might work as well (and be nicer)
merge!(general fields)
#[cfg(alsa)]
merge!(alsa fields)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. That's a good one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
im not completely sure if changing the config layout like this is a breaking change or not.
I think so. Basically when you're now setting If it's done by Also will need to add docs for the different config options considering |
alright good to know, then we have to bump the version |
We already have another MR that's "waiting" on 0.4 to be merged, we can add this one to the list. Maybe we should make version branches to keep track? |
So the macro stuff has been already addressed. And tested. I'm just concerned about one thing regarding the Should the I made the refactor having the fields like: #[cfg(feature = "alsa-backend")]
pub(crate) audio_device: String,
#[cfg(feature = "alsa-backend")]
pub(crate) control_device: String,
#[cfg(feature = "alsa-backend")]
pub(crate) mixer: String, But I can change them to be Once this is clarified, It might need to be specified in the mdbook a bit more clearly IMO. Then the PR will be ready I think. |
If it is a plain string, and i specify it in the config but not command line will it then fail? |
Exactly! Good point! Let's make it an |
In the wiki mdbook it's not stated clearly that the config options that refer to `mixer`, `controller` and `device` can be directly commented out since they're only used when spotifyd is compiled with `alsa_backend` feature.
I think this looks good! And we should release this in the next breaking change! |
The breaking change concern could be addressed by explicitly telling |
I do remember that spotifyd also had a This is something we could (and I think even should!) consider for a large breaking change at some point. I'd rather have mandatory fields than some magic that works in the background (and not even on all machines) . |
Sorry @sirwindfield but this got lost between tons of notifications. The attributes you mention are indeed |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know if it's worth commenting on this PR, but if there is still interest from the maintainer side, the below can be taken into consideration.
global_section.mixer = "PCM1".to_string(); | ||
|
||
// The test only makes sense if both sections differ. | ||
assert!(spotifyd_section != global_section, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert!()
tests by itself, whether the expression is true.
assert!(spotifyd_section != global_section, true); | |
assert!(spotifyd_section != global_section); |
cfg_if::cfg_if! { | ||
if #[cfg(feature = "alsa_backend")] { | ||
deb_struct | ||
.field("device", &self.device) | ||
.field("control", &self.control) | ||
.field("mixer", &self.mixer) | ||
.finish() | ||
} else { | ||
deb_struct.finish() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By using the below variant, we could get rid of the cfg_if
crate and the effect should be the same.
cfg_if::cfg_if! { | |
if #[cfg(feature = "alsa_backend")] { | |
deb_struct | |
.field("device", &self.device) | |
.field("control", &self.control) | |
.field("mixer", &self.mixer) | |
.finish() | |
} else { | |
deb_struct.finish() | |
} | |
} | |
#[cfg(feature = "alsa_backend")] | |
{ | |
deb_struct | |
.field("device", &self.device) | |
.field("control", &self.control) | |
.field("mixer", &self.mixer); | |
} | |
deb_struct.finish() |
#[test] | ||
fn test_section_merging() { | ||
let mut spotifyd_section = SharedConfigValues::default(); | ||
global_section.mixer = "PCM".to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
global_section.mixer = "PCM".to_string(); | |
spotifyd_section.mixer = "PCM".to_string(); |
// Add the new field to spotifyd section. | ||
spotifyd_section.mixer = "PMC".to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be necessary, right?
@@ -738,4 +752,27 @@ mod tests { | |||
spotifyd_section.username = Some("testUserName".to_string()); | |||
assert_eq!(merged_config, spotifyd_section); | |||
} | |||
|
|||
#[cfg(features = "alsa_backend")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[cfg(features = "alsa_backend")] | |
#[cfg(feature = "alsa_backend")] |
|
||
#[cfg(features = "alsa_backend")] | ||
#[test] | ||
fn test_section_merging() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be renamed.
let mut mixer = { | ||
// We just need to initialize the mixer. The contents will be mutated for sure | ||
// and therefore we don't need to worry since all of the branches are covered. | ||
let mut mixer: Box<dyn FnMut() -> Box<dyn Mixer>> = unimplemented!(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will panic, if run. You can just omit the = ...
part.
#[cfg(feature = "alsa_backend")] | ||
audio_setup: main_loop::AudioSetup { | ||
mixer, | ||
backend, | ||
audio_device: config.audio_device, | ||
}, | ||
#[cfg(not(feature = "alsa_backend"))] | ||
audio_setup: main_loop::AudioSetup { | ||
mixer, | ||
backend, | ||
audio_device: config.audio_device.clone(), | ||
audio_device: None, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[cfg(feature = "alsa_backend")] | |
audio_setup: main_loop::AudioSetup { | |
mixer, | |
backend, | |
audio_device: config.audio_device, | |
}, | |
#[cfg(not(feature = "alsa_backend"))] | |
audio_setup: main_loop::AudioSetup { | |
mixer, | |
backend, | |
audio_device: config.audio_device.clone(), | |
audio_device: None, | |
}, | |
audio_setup: main_loop::AudioSetup { | |
mixer, | |
backend, | |
#[cfg(feature = "alsa_backend")] | |
audio_device: config.audio_device, | |
#[cfg(not(feature = "alsa_backend"))] | |
audio_device: None, | |
}, |
// We need to allow these lints since the conditional compilation is | ||
// what makes them appear. | ||
#[allow(unused_must_use, unreachable_code, unused_variables)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least with the changes below and on Rust 1.63, none of those should be necessary any more.
Hello! I do not have the time to maintain the project actively right now. I think it would still be a good idea to get this PR done, since it just does not make sense to have them in the same struct. The current code base of spotifyd feels more like patch work then anything else to be honest. The tokio 1.0 rewrite did help though. I definitely am interested in seeing how librespot does these days. Maybe some changes allow us to make the whole client more lightweight in general. Or restructure some features/code modules all together. I'll definitely investigate this. I cannot tell you when though. |
As it was stated in #394, structs like
SharedConfigValues
orSpotifydConfig
contain fields likemixer
,control
anddevice
which only apply if
alsa-backend
feature is enabled.Therefore, it would be nice if these fields were only documented when
the feature is enabled as well as used.
Closes #394