summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2024-10-29 09:14:54 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2024-10-29 09:14:54 +1300
commita2d9aadf03f59378db08c0af82449c23ebf38643 (patch)
tree0ed9b6cba7781031d09573b0d3e944a5b78e653b
parentffb979f9cd7d8029251e5bb244428ddaa6724d04 (diff)
downloadbedrock-pc-a2d9aadf03f59378db08c0af82449c23ebf38643.zip
Canonicalize the source path for the assembler
When a relative path with only one path component is passed to the assembler, the parent of that path cannot be determined and so the project libraries descending from that parent cannot be included in the program. To fix this, we canonicalize the path before it is used. This also makes the path comments generated for the project source files more stable and readable.
-rw-r--r--src/bin/br.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/bin/br.rs b/src/bin/br.rs
index 77bf3ee..632291c 100644
--- a/src/bin/br.rs
+++ b/src/bin/br.rs
@@ -170,7 +170,11 @@ fn main_asm(args: Asm) {
// -----------------------------------------------------------------------
// RESOLVE syntactic symbols
let ext = args.ext.unwrap_or(String::from("brc"));
- let mut resolver = if let Some(path) = &args.source {
+ let source_path = args.source.clone().map(|p| {
+ p.canonicalize().unwrap_or(p)
+ });
+
+ let mut resolver = if let Some(path) = &source_path {
match SourceUnit::from_path(&path, &ext) {
Ok(source_unit) => SymbolResolver::from_source_unit(source_unit),
Err(err) => match err {
@@ -201,7 +205,7 @@ fn main_asm(args: Asm) {
SymbolResolver::from_source_unit(source_unit)
};
// Load project libraries.
- if let Some(path) = &args.source {
+ if let Some(path) = &source_path {
if !args.no_libs && !args.no_project_libs {
let project_library = gather_project_libraries(path, &ext);
resolver.add_library_units(project_library);