Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into pins
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyeng committed Dec 18, 2019
2 parents 93b1f1f + 500d1a7 commit 9b8514e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 43 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
## Development Environment Setup

0) Windows-Specific Setup

If using Windows, ensure that the `HOME` environment variable is set. For example, using Powershell:

~~~
# In this instance, $HOME is NOT an environment variable, but a shortcut. Set it to the similarly-named environment variable.
$env:HOME = $HOME
~~~

1) [Install Rust](https://www.rust-lang.org/tools/install)

2) Enable Rust nightly version (this must be done for every o2 workspace):
Expand Down
3 changes: 2 additions & 1 deletion rust/origen/cli/src/python.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Responsible for managing Python execution

use origen::core::os;
use origen::STATUS;
use semver::Version;

const PYTHONS: &[&str] = &[
Expand Down Expand Up @@ -34,7 +35,7 @@ impl Default for Config {
available = true;
let poetry_cmd = format!(
"{}/.poetry/bin/poetry",
std::env::var("HOME").expect("$HOME is not defined")
format!("{}", STATUS.home.display())
);
if version >= Version::parse(MIN_PYTHON_VERSION).unwrap() {
return Config {
Expand Down
1 change: 1 addition & 0 deletions rust/origen/pyapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn status(py: Python) -> PyResult<PyObject> {
let _ = ret.set_item("is_app_present", &STATUS.is_app_present);
let _ = ret.set_item("root", format!("{}", STATUS.root.display()));
let _ = ret.set_item("origen_version", &STATUS.origen_version.to_string());
let _ = ret.set_item("home", format!("{}", STATUS.home.display()));
Ok(ret.into())
}

Expand Down
12 changes: 12 additions & 0 deletions rust/origen/src/core/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub struct Status {
/// The Origen version in a Semver object
pub origen_version: Version,
pub start_time: time::Tm,
/// The full file system path to the user's home directory
pub home: PathBuf,
}

impl Default for Status {
Expand All @@ -31,6 +33,7 @@ impl Default for Status {
root: r,
origen_version: version,
start_time: time::now(),
home: get_home_dir(),
}
}
}
Expand All @@ -57,3 +60,12 @@ fn search_for_app_root() -> (bool, PathBuf) {
(true, path)
}
}

fn get_home_dir() -> PathBuf {
if cfg!(windows) {
PathBuf::from(env::var("USERPROFILE").expect("Please set environment variable USERPROFILE to point to your home directory, then try again"))
}
else {
PathBuf::from(env::var("HOME").expect("Please set environment variable HOME to point to your home directory, then try again"))
}
}
43 changes: 10 additions & 33 deletions rust/origen/src/core/utility/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,6 @@ impl Logger {
);
}

fn _filename(&self) -> PathBuf {
return self._output_dir().join("out.log");
}

fn _output_dir(&self) -> PathBuf {
if STATUS.is_app_present {
return (STATUS.root).to_path_buf().join("log");
} else {
match env::var("HOME") {
Ok(var) => PathBuf::from(var).join(".origen").join("log"),
Err(_e) => panic!("No environment variable for HOME!"),
}
}
}

fn _write_header(&self) {
let mut out = String::from("### Origen Log File\n");
out += &format!("### Version: {}\n", STATUS.origen_version);
Expand All @@ -153,14 +138,15 @@ impl Logger {
}

pub fn default_output_dir() -> PathBuf {
let pb;
if STATUS.is_app_present {
return (STATUS.root).to_path_buf().join("log");
pb = (STATUS.root).to_path_buf().join("log");
} else {
match env::var("HOME") {
Ok(var) => PathBuf::from(var).join(".origen").join("log"),
Err(_e) => panic!("No environment variable for HOME!"),
}
pb = (STATUS.home).to_path_buf().join(".origen").join("log");
}
// create all missing directories to avoid panics
fs::create_dir_all(pb.as_path()).expect(&(format!("Could not create the log directory {}",pb.display())));
pb
}

pub fn default_output_file() -> PathBuf {
Expand All @@ -173,19 +159,10 @@ impl Logger {
output_file: f.to_path_buf(),
file_handler: match fs::File::create(f) {
Ok(f) => f,
Err(_e) => match fs::create_dir(f.parent().unwrap()) {
Ok(_d) => match fs::File::create(f) {
Ok(f) => f,
Err(_e) => panic!(
"Could not open log file at {}",
format!("{}", f.to_string_lossy())
),
},
Err(_e) => panic!(
"Could not open log file at {}",
format!("{}", f.to_string_lossy())
),
},
Err(_e) => panic!(
"Could not open log file at {}",
format!("{}", f.to_string_lossy())
),
},
};
l._write_header();
Expand Down

0 comments on commit 9b8514e

Please sign in to comment.