-
Notifications
You must be signed in to change notification settings - Fork 216
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
Add file config support for ravedude #522
base: main
Are you sure you want to change the base?
Conversation
Also, some further notes:
# [...]
[avrdude]
programmer = "avrisp"
# partno = "t85"
baudrate = 19200
do_chip_erase = true Produces
|
nice! 👍
Feel free to drop the entire Whatever we end up doing with the "builtin boards", they should also simply get encoded in the new TOML format somewhere, as you suggested.
Interesting idea. My original design approach was to model Your suggestion reminds me of the approach of I don't see a big reason why not to go down this route, although I think we should consider the specifics carefully:
To put it into concrete examples: # Ravedude.toml for using well known board
[general]
console = true
baudrate = 57600
board = "uno" # Ravedude.toml for using a completely custom board
[general]
console = true
baudrate = 57600
[board]
name = "ATtiny85 through AVRISP"
[board.reset]
automatic = true
[board.avrdude]
programmer = "avrisp"
partno = "t85"
baudrate = 19200
do_chip_erase = true # Ravedude.toml for customizing well known board
[general]
console = true
baudrate = 57600
[board]
name = "Uno without automatic reset"
inherit = "uno"
[board.reset]
automatic = false What do you think? |
Sounds good!
I assume in this case command-line options would override the TOML file. Would we want a warning to be printed in that case?
Does this signify approval? Because I'd rather not change things just for the sake of changing things. If mandatory TOML configs don't benefit the project in any way, they shouldn't be implemented.
This is a very good point, and I hadn't considered that. Yeah, I agree that this would be a better solution. The examples look great! However, I would like a consistent case across keys. (Either snake_case or kebab-case is fine, although I'm leaning towards kebab case to mirror Cargo.toml.) Also, annoyingly, serde doesn't have "inheritance" behavior built-in, and from some very basic searching around the web I've gathered that the best way to do this is just to make everything an A final note/question: Would this be considered a breaking change...? If not, we'd need to find a way to keep this backwards-compatible. Maybe a "default" config that's used if the file doesn't exist? It depends on how much of a priority backwards compatibility is. |
Hi, sorry for only getting back to you now...
To me, it's really important not to completely break existing users. At least, there should be a trivial migration path that doesn't require deeper understanding of the inner workings of For simplicity, my suggestion would be to keep the existing invocations working as is, as long as no If all else fails, a hacky solution to do this might be to throw the current "legacy" argument parser into a separate module and invoke it when no
Hm, so let's look at all the CLI args we have right now and I'll share my thoughts for each one:
Generally, I wouldn't display warnings for the overrides. I'd only show warnings for deprecated things or errors when someone combines legacy invocations with a new
Yeah, let's do it. For the purpose that
Same here 👍 Thanks again for working on this! I'm excited to see the result :) This will make |
Whew! Yeah, no worries, I've been busy as well... Anyways, a ton of stuff is complete! Additionally, it's now in a state where this could be merged, although a few (minor) things differ from your suggestions. Listing them off:
Additionally, using Ravedude.toml I have successfully uploaded a rust program to the ATtiny85 through the Arduino Nano! Anyways, yeah, unless we want to make changes to any of this (or if there are bugs), this PR is ready to merge! 🎉 (Not saying that it should be merged right now, but that it can be... there are also merge conflicts that need clearing up)
No problem! ravedude (and the entirety of avr-hal, really) makes my life a lot easier when using Rust for AVR-related projects! Happy to help :D |
Oh yeah -- We should also probably modify stuff like the avr-hal template to use Ravedude.toml, along with adding options for completely custom setups. |
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.
Finally found time to take a closer look. Thanks a lot for working on this, it's coming together quite nicely :)
Please check my comments below!
ravedude/src/main.rs
Outdated
return Ok(()); | ||
} | ||
|
||
let ravedude_config_exists = std::path::Path::new("Ravedude.toml").try_exists()?; |
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.
Right now you are searching for Ravedude.toml
in the current working directory. This breaks when you e.g. cargo run
inside the src/
directory. Maybe you can check how other tools like cargo-embed
find their config file and implement something similar?
As a hint, it seems cargo sets some environment variables when running a runner process. One of them is CARGO_MANIFEST_DIR
which seems to indicate the directory where cargo found its own Cargo.toml
...
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.
cargo-embed
uses figment, which looks interesting. I'm most likely gonna switch ravedude over to it to mirror its behavior (and cargo's behavior) with environment variables, although I've held back on it for now due to it possibly being overkill (?) although ravedude itself isn't going to run on a microcontroller so that probably wasn't a good reason.
CARGO_MANIFEST_DIR
seems to be only available when using ravedude as a runner. ravedude should be able to access Ravedude.toml no matter how it's being run, in my opinion.
Currently, I just have ravedude scan all parent directories until it finds a Ravedude.toml
somewhere, which works fine for now... this behavior will probably be replaced by figment, though.
Hi, again, sorry for the delay. I've made modifications to the code and left comments based on your feedback. Thanks! |
…ything take the new structs
…ey are not, in fact, bugs
…ted error messages
…n warning showing up when it's not supposed to
… in board.rs, add test to ci
… not an Option<T>
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.
Heads up: I rebased your changes ontop of the latest main to resolve some conflicts. Please make sure to continue working ontop of the rebased version.
I have a few more comments, check below. I'll hopefully get to testing the new ravedude in more depth soon, then I'll report back if I find anything else. It's looking very very promising already, though! :)
args | ||
.board | ||
.as_deref() | ||
.ok_or_else(|| anyhow::anyhow!("no board given and couldn't find Ravedude.toml in project, either pass a board as an argument or make a Ravedude.toml."))? |
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.
Actually, don't reference the deprecated board name method in this error message. We don't want to advertise the legacy mechanism in any way. Simply state that we couln't find a Ravedude.toml and give a pointer on how to create one.
let manifest_path = 'manifest_path: { | ||
// By default Cargo scans the current dir and all of its parents for Cargo.toml, | ||
// so we mirror its behavior here. | ||
let current_dir = std::env::current_dir()?; | ||
|
||
for dir_to_test in current_dir.ancestors() { | ||
let path_to_test = dir_to_test.join(Path::new("Ravedude.toml")); | ||
if path_to_test.exists() { | ||
break 'manifest_path Some(path_to_test); | ||
} | ||
} | ||
|
||
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.
I wonder if we should still honor CARGO_MANIFEST_DIR
when it is present in the environment. The reason I have in mind is usecases when calling cargo run
with --manifest-path
while the working directory is completely different.
board: String, | ||
// When Ravedude.toml exists, the binary is placed where the board should be. This is an OsString to not lose | ||
// informaton when we have to take the board as the binary. | ||
board: Option<OsString>, |
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.
Got a bit of a tricky problem here right now: The ravedude --help
output is still completely wrong. Ideally, we can get it to just show the new way of doing things and secretly handle the legacy method in the background.
To do this, I think we need to take the following steps:
- Rename the current
bin
to something likeoldbin
with the help message stating that this is an argument used for backwards compatibility. - Rename the current
board
tobin
. Adjust the docstring to the current one frombin
and drop theverbatim_doc_comment
setting.
Followup PR to #521
What the title says. This adds a board named
custom
to ravedude that reads from Ravedude.toml from the project directory.Works with this config (in Ravedude.toml):
And this cargo runner:
Minor detail but this PR also changes
get_board
to returnanyhow::Result<Box<dyn Board>>
, if that matters.Anyways, format and implementation of custom board support in ravedude is up for discussion. If we reach a consensus about what would be best, this PR will be marked as ready for review.