Have CLI use the given file's directory as src_dir

This commit is contained in:
Richard Feldman 2020-04-15 08:24:53 -04:00
parent 57c4261b08
commit b19386c1f6
2 changed files with 6 additions and 8 deletions

View File

@ -22,7 +22,6 @@ use std::time::SystemTime;
use inkwell::targets::{ use inkwell::targets::{
CodeModel, FileType, InitializationConfig, RelocMode, Target, TargetTriple, CodeModel, FileType, InitializationConfig, RelocMode, Target, TargetTriple,
}; };
use std::env::current_dir;
use std::io; use std::io;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use target_lexicon::{Architecture, OperatingSystem, Triple, Vendor}; use target_lexicon::{Architecture, OperatingSystem, Triple, Vendor};
@ -34,12 +33,8 @@ fn main() -> io::Result<()> {
match argv.get(1) { match argv.get(1) {
Some(filename) => { Some(filename) => {
let mut path = Path::new(filename).canonicalize().unwrap(); let path = Path::new(filename);
let src_dir = current_dir()?; let src_dir = path.parent().unwrap().canonicalize().unwrap();
if !path.is_absolute() {
path = src_dir.join(path).canonicalize().unwrap();
}
// Create the runtime // Create the runtime
let mut rt = Builder::new() let mut rt = Builder::new()
@ -50,7 +45,7 @@ fn main() -> io::Result<()> {
.expect("Error spawning initial compiler thread."); // TODO make this error nicer. .expect("Error spawning initial compiler thread."); // TODO make this error nicer.
// Spawn the root task // Spawn the root task
let loaded = rt.block_on(load_file(src_dir, path)); let loaded = rt.block_on(load_file(src_dir, path.canonicalize().unwrap()));
loaded.expect("TODO gracefully handle LoadingProblem"); loaded.expect("TODO gracefully handle LoadingProblem");

View File

@ -0,0 +1,3 @@
interface HelloStr exposes [ str ] imports []
str = "Hi, World!"