From c8b55d3dcb331a3a3e6911374e9d91b5f051863b Mon Sep 17 00:00:00 2001 From: Imbris Date: Mon, 4 Oct 2021 11:46:25 -0400 Subject: [PATCH] Improve the warning message when USERDATA_STRATEGY was not set during compilation and the binary was moved outside the workspace/crate that it was compiled from, show a warning when an invalid VELOREN_USERDATA_STRATEGY is used, and also actually make sure warnings from userdata selection are logged in voxygen (since the userdata folder needs to be selected to set up logging we have to rerun the selection after logging is set up so that any warnings will be logged). --- common/base/src/userdata_dir.rs | 25 +++++++++++++++++++++++-- voxygen/src/main.rs | 3 +++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/common/base/src/userdata_dir.rs b/common/base/src/userdata_dir.rs index e1fe66c479..5de4e728a8 100644 --- a/common/base/src/userdata_dir.rs +++ b/common/base/src/userdata_dir.rs @@ -41,7 +41,15 @@ pub fn userdata_dir(workspace: bool, strategy: Option<&str>, manifest_dir: &str) path.push("userdata"); Some(path) }, - Some(_) => None, // TODO: panic? catch during compilation? + Some(s) => { + warn!( + "Compiled with an invalid VELOREN_USERDATA_STRATEGY: \"{}\". \ + Valid values are unset, \"system\", and \"executable\". \ + Falling back to unset case.", + s, + ); + None + }, _ => None, }) // 3. The CARGO_MANIFEST_DIR/userdata or CARGO_MANIFEST_DIR/../userdata depending on if a @@ -61,10 +69,23 @@ pub fn userdata_dir(workspace: bool, strategy: Option<&str>, manifest_dir: &str) path } else { // otherwise warn and fallback to the executable strategy - warn!("This binary was moved to outside the project folder where it was compiled and was not compiled with VELOREN_USERDATA_STRATEGY set to \"system\" or \"executable\". Falling back the to the \"executable\" strategy (the userdata folder will be placed in the same folder as the executable)"); + let project_path = path; let mut path = exe_path; path.pop(); path.push("userdata"); + warn!( + "This binary is outside the project folder where it was compiled ({}) \ + and was not compiled with VELOREN_USERDATA_STRATEGY set to \"system\" or \"executable\". \ + Falling back the to the \"executable\" strategy (the userdata folder will be placed in the \ + same folder as the executable: {}) \n\ + NOTE: You can manually select a userdata folder (overriding this automatic selection) by \ + setting the environment variable {} to the desired directory before running. \n\ + NOTE: If you have not moved the executable this can occur when using a custom cargo \ + target-dir that is not inside the project folder.", + project_path.display(), + path.display(), + VELOREN_USERDATA_ENV, + ); path } }) diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index cd6b98eab0..03636809f1 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -44,6 +44,9 @@ fn main() { let log_filename = format!("{}_voxygen.log", now.format("%Y-%m-%d")); let _guards = common_frontend::init_stdout(Some((&logs_dir, &log_filename))); + // Re-run userdata selection so any warnings will be logged + common_base::userdata_dir_workspace!(); + info!("Using userdata dir at: {}", userdata_dir.display()); // Determine Voxygen's config directory either by env var or placed in veloren's