Skip to content

Commit eb0da4f

Browse files
Merge pull request RustPython#366 from rmliddle/develop
Fixes build on Windows
2 parents 03fb016 + f89dc00 commit eb0da4f

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/main.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ extern crate log;
77
extern crate rustpython_parser;
88
extern crate rustpython_vm;
99
extern crate rustyline;
10-
extern crate xdg;
1110

1211
use clap::{App, Arg};
1312
use rustpython_parser::parser;
@@ -143,6 +142,22 @@ fn shell_exec(vm: &mut VirtualMachine, source: &str, scope: PyObjectRef) -> bool
143142
true
144143
}
145144

145+
#[cfg(not(target_family = "unix"))]
146+
fn get_history_path() -> PathBuf {
147+
//Path buffer
148+
PathBuf::from(".repl_history.txt")
149+
}
150+
151+
#[cfg(target_family = "unix")]
152+
fn get_history_path() -> PathBuf {
153+
//work around for windows dependent builds. The xdg crate is unix specific
154+
//so access to the BaseDirectories struct breaks builds on python.
155+
extern crate xdg;
156+
157+
let xdg_dirs = xdg::BaseDirectories::with_prefix("rustpython").unwrap();
158+
xdg_dirs.place_cache_file("repl_history.txt").unwrap()
159+
}
160+
146161
fn run_shell(vm: &mut VirtualMachine) -> PyResult {
147162
println!(
148163
"Welcome to the magnificent Rust Python {} interpreter",
@@ -155,9 +170,8 @@ fn run_shell(vm: &mut VirtualMachine) -> PyResult {
155170
let mut input = String::new();
156171
let mut rl = Editor::<()>::new();
157172

158-
let xdg_dirs = xdg::BaseDirectories::with_prefix("rustpython").unwrap();
159-
let repl_history_path = xdg_dirs.place_cache_file("repl_history.txt").unwrap();
160-
let repl_history_path_str = repl_history_path.to_str().unwrap();
173+
//retrieve a history_path_str dependent to the os
174+
let repl_history_path_str = &get_history_path();
161175
if rl.load_history(repl_history_path_str).is_err() {
162176
println!("No previous history.");
163177
}

0 commit comments

Comments
 (0)