Skip to content

Commit

Permalink
Rename async_main to main (#93)
Browse files Browse the repository at this point in the history
* feat: Rename async_main to main

* docs: Update changelog

* feat: Update how we rename async_main
  • Loading branch information
SergioGasquez authored Feb 5, 2025
1 parent bfd226c commit fa35d04
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Added a version checker that prints a warn message if not using latest esp-generate version (#87)

- After generating the project the tool now checks the rust version, espflash version and probe-rs version (#88)

### Changed
- Update `probe-rs run` arguments (#90)
- When using `embassy` option, `async_main.rs` file was renamed to `main.rs` (#93)

### Fixed

Expand Down
46 changes: 36 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ fn main() -> Result<(), Box<dyn Error>> {
fs::create_dir(&project_dir)?;

for &(file_path, contents) in template_files::TEMPLATE_FILES.iter() {
if let Some(processed) = process_file(contents, &selected, &variables) {
let mut file_path = file_path.to_string();
if let Some(processed) = process_file(contents, &selected, &variables, &mut file_path) {
let file_path = project_dir.join(file_path);

fs::create_dir_all(file_path.parent().unwrap())?;
Expand Down Expand Up @@ -385,6 +386,7 @@ fn process_file(
contents: &str, // Raw content of the file
options: &[String], // Selected options
variables: &[(String, String)], // Variables and their values in tuples
file_path: &mut String, // File path to be modified
) -> Option<String> {
let mut res = String::new();

Expand Down Expand Up @@ -415,16 +417,35 @@ fn process_file(
.or_else(|| trimmed.strip_prefix("#INCLUDEFILE "));

if let Some(cond) = cond {
let include_file = if let Some(stripped) = cond.strip_prefix("!") {
!options.contains(&stripped.to_string())
} else {
options.contains(&cond.to_string())
};

if !include_file {
return None;
if !cond.contains(" ") {
let include_file = if let Some(stripped) = cond.strip_prefix("!") {
!options.contains(&stripped.to_string())
} else {
options.contains(&cond.to_string())
};
if !include_file {
return None;
} else {
continue;
}
} else {
continue;
let mut parts = cond.split_whitespace();
let include_file = if let Some(stripped) = parts.next() {
if let Some(stripped) = stripped.strip_prefix("!") {
!options.contains(&stripped.to_string())
} else {
options.contains(&stripped.to_string())
}
} else {
false
};
if !include_file {
return None;
} else {
let new_name = parts.next().unwrap();
*file_path = new_name.to_string();
continue;
}
}
}
}
Expand Down Expand Up @@ -574,6 +595,7 @@ mod test {
"#,
&["opt1".to_string(), "opt2".to_string()],
&[],
&mut String::from("main.rs"),
)
.unwrap();

Expand Down Expand Up @@ -604,6 +626,7 @@ mod test {
"#,
&[],
&[],
&mut String::from("main.rs"),
)
.unwrap();

Expand Down Expand Up @@ -633,6 +656,7 @@ mod test {
"#,
&["opt1".to_string()],
&[],
&mut String::from("main.rs"),
)
.unwrap();

Expand Down Expand Up @@ -661,6 +685,7 @@ mod test {
"#,
&["opt1".to_string()],
&[],
&mut String::from("main.rs"),
)
.unwrap();

Expand Down Expand Up @@ -689,6 +714,7 @@ mod test {
"#,
&["opt2".to_string()],
&[],
&mut String::from("main.rs"),
)
.unwrap();

Expand Down
4 changes: 0 additions & 4 deletions template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ edition = "2021"
[[bin]]
#REPLACE project-name project-name
name = "project-name"
#IF !option("embassy")
path = "./src/bin/main.rs"
#ELSE
#+path = "./src/bin/async_main.rs"
#ENDIF

[dependencies]
esp-backtrace = { version = "0.15.0", features = [
Expand Down
2 changes: 1 addition & 1 deletion template/src/bin/async_main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//INCLUDEFILE embassy
//INCLUDEFILE embassy src/bin/main.rs
#![no_std]
#![no_main]

Expand Down

0 comments on commit fa35d04

Please sign in to comment.