-
Notifications
You must be signed in to change notification settings - Fork 31
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 (#2074)
- Loading branch information
1 parent
fde23db
commit b204349
Showing
5 changed files
with
27 additions
and
18 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,23 @@ | ||
// 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. | ||
/// Resolves a relative path from the project root directory and returns its absolute path. | ||
/// | ||
/// # Arguments | ||
/// * `relative_path` - A string slice representing the relative path from the project root. | ||
/// | ||
/// # Returns | ||
/// * An absolute `PathBuf` representing the resolved path starting from the project root. | ||
pub fn resolve_project_relative_path(relative_path: &str) -> PathBuf { | ||
path_of_project_root().join(relative_path) | ||
} | ||
|
||
fn path_of_project_root() -> PathBuf { | ||
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")) | ||
} |
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