8000 Add ability to merge config from an external file. by wrobstory · Pull Request #278 · bazeltools/rules_minidock_tools · GitHub
[go: up one dir, main page]

Skip to content

Add ability to merge config from an external file. - #278

Merged
wrobstory merged 6 commits into
mainfrom
story-labels
Oct 17, 2023
Merged

wrobstory merged 6 commits into
mainfrom
story-labels

Conversation

@wrobstory
Copy link
Copy Markdown
Contributor

We'd like to add the ability to load an external file and pass that as a config, more details here: bazeltools/rules_minidock#8

This PR implements this in the merger app. Rules-based config will always take precedence over the external config file in the event of a conflict.

I moved a bunch of stuff around in the app so that I could add an integration test suite.

@wrobstory
Copy link
Copy Markdown
Contributor Author

Oh yeah one note: it wasnt clear to me what purpose resources/test/sample_out_1 was serving. I assumed it was for doing some testing by hand, and hoped that my testing changes here would remove the need for it to exist.

Comment thread src/lib.rs
pub async fn merge_main(opt: Opt) -> Result<(), anyhow::Error> {
let pusher_config = MergeConfig::parse_file(&opt.merger_config_path)?;

let external_execution_config = match &opt.external_config_path {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't use .map here or something?

ahh maybe not because of the ? man... ? is really a very poor man's traverse.

Comment thread src/merge_outputs.rs Outdated
pub async fn merge(
merge_config: &super::merge_config::MergeConfig,
relative_search_path: &Option<PathBuf>,
external_execution_config: &Option<ExecutionConfig>,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like this could be a &Vector<ExecutionConfig> and just iterate through updating?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, re: the comment on your other PR, if we're going to be able to have multiple file configs, this will need to be a vector.

there is an ExecutionConfig buried in the MergeConfig passed in here, and that one needs to be the last merge, so its fine to leave it as-is.

@wrobstory
Copy link
Copy Markdown
Contributor Author

@johnynek I updated this to take in multiple external configs, want to take another look?

@wrobstory
wrobstory requested a review from johnynek October 16, 2023 22:57
@johnynek johnynek left a comment
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, I just had a suggestion on removing a .clone

Comment thread src/lib.rs Outdated
let mut configs = Vec::new();
for p in paths {
let json_str = fs::read_to_string(&p)?;
let config = serde_json::from_str(&json_str)?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use https://docs.rs/serde_json/latest/serde_json/fn.from_reader.html to read the file directly rather than read string then string to json?

Comment thread src/merge_outputs.rs Outdated
merge_config: &super::merge_config::MergeConfig,
relative_search_path: &Option<PathBuf>,
external_execution_config: &Option<ExecutionConfig>,
external_execution_configs: &Vec<ExecutionConfig>,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I if you remove the &Vec here and just do Vec<ExecutionConfig> we can avoid the clone below. Seems like the caller is the last to use this config.

Comment thread src/merge_outputs.rs Outdated
for config in external_execution_configs {
let mut external_base_cfg = ConfigDelta::default();
external_base_cfg.config = external_execution_config.clone();
external_base_cfg.config = Some(config.clone());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this .clone if we make external_execution_configs not a reference.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah this was a nice catch

@wrobstory
wrobstory merged commit 1262656 into main Oct 17, 2023
@wrobstory
wrobstory deleted the story-labels branch October 17, 2023 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0