Skip to content

Commit 2f0647e

Browse files
committed
factored out xdg to cfg functions to allow windows builds to succeed
1 parent 0daa038 commit 2f0647e

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/main.rs

Lines changed: 19 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,23 @@ fn shell_exec(vm: &mut VirtualMachine, source: &str, scope: PyObjectRef) -> bool
143142
true
144143
}
145144

145+
#[cfg(target_family = "windows")]
146+
fn get_history_path() -> String {
147+
//
148+
String::from(".repl_history.txt")
149+
}
150+
151+
#[cfg(target_family = "unix")]
152+
fn get_history_path() -> String {
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+
let repl_history_path = xdg_dirs.place_cache_file("repl_history.txt").unwrap();
159+
repl_history_path.to_str().unwrap()
160+
}
161+
146162
fn run_shell(vm: &mut VirtualMachine) -> PyResult {
147163
println!(
148164
"Welcome to the magnificent Rust Python {} interpreter",
@@ -155,9 +171,8 @@ fn run_shell(vm: &mut VirtualMachine) -> PyResult {
155171
let mut input = String::new();
156172
let mut rl = Editor::<()>::new();
157173

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();
174+
//retrieve a history_path_str dependent to the os
175+
let repl_history_path_str = &get_history_path();
161176
if rl.load_history(repl_history_path_str).is_err() {
162177
println!("No previous history.");
163178
}

0 commit comments

Comments
 (0)