diff --git a/CHANGELOG.md b/CHANGELOG.md index 382cd04..f930ac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +- [#84]: Fix for comments in linker script + +[#84]: https://github.com/knurling-rs/flip-link/pull/84 + ## [v0.1.7] - 2023-07-20 - [#79]: Summer cleanup diff --git a/src/argument_parser.rs b/src/argument_parser.rs index 68c206b..14f13c2 100644 --- a/src/argument_parser.rs +++ b/src/argument_parser.rs @@ -10,7 +10,8 @@ pub fn get_output_path(args: &[String]) -> crate::Result<&String> { /// Get `search_paths`, specified by `-L` pub fn get_search_paths(args: &[String]) -> Vec { args.windows(2) - .filter_map(|x| (x[0] == "-L").then(|| PathBuf::from(&x[1]))) + .filter(|&x| (x[0] == "-L")) + .map(|x| PathBuf::from(&x[1])) .inspect(|path| log::trace!("new search path: {}", path.display())) .collect() } diff --git a/src/main.rs b/src/main.rs index 6208163..3125bba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -321,7 +321,7 @@ fn perform_addition(line: &str) -> u64 { let (number, unit) = match segment.find(['K', 'M']) { Some(unit_pos) => { let (number, unit) = segment.split_at(unit_pos); - (number, Some(unit)) + (number, unit.chars().next()) } None => (segment, None), }; @@ -335,8 +335,8 @@ fn perform_addition(line: &str) -> u64 { // Handle unit let multiplier = match unit { - Some("K") => 1024, - Some("M") => 1024 * 1024, + Some('K') => 1024, + Some('M') => 1024 * 1024, None => 1, _ => unreachable!(), }; @@ -401,6 +401,31 @@ mod tests { ); } + #[test] + fn ingore_comment() { + const LINKER_SCRIPT: &str = "MEMORY + { + FLASH : ORIGIN = 0x00000000, LENGTH = 256K + RAM : ORIGIN = 0x20000000, LENGTH = 64K /* This is a comment */ + } + + INCLUDE device.x"; + + assert_eq!( + find_ram_in_linker_script(LINKER_SCRIPT), + Some(MemoryEntry { + line: 3, + origin: 0x20000000, + length: 64 * 1024, + }) + ); + + assert_eq!( + get_includes_from_linker_script(LINKER_SCRIPT), + vec!["device.x"] + ); + } + #[test] fn test_perform_addition_hex_and_number() { const ADDITION: &str = "0x20000000 + 1000";