-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(infra): move get_absolute_path function to infra_utils
- Loading branch information
1 parent
0961746
commit b179f10
Showing
5 changed files
with
17 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
// TODO(Arni): Move the function get_absolute_path to this file. | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
// TODO(Tsabary/ Arni): consolidate with other get_absolute_path functions. | ||
/// Returns the absolute path from the project root. | ||
pub fn get_absolute_path(relative_path: &str) -> PathBuf { | ||
let base_dir = env::var("CARGO_MANIFEST_DIR") | ||
// Attempt to get the `CARGO_MANIFEST_DIR` environment variable and convert it to `PathBuf`. | ||
// Ascend two directories ("../..") to get to the project root. | ||
.map(|dir| PathBuf::from(dir).join("../..")) | ||
// If `CARGO_MANIFEST_DIR` isn't set, fall back to the current working directory | ||
.unwrap_or_else(|_| env::current_dir().expect("Failed to get current directory")); | ||
base_dir.join(relative_path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters