97 lines
3.2 KiB
Diff
97 lines
3.2 KiB
Diff
From ca038d416eb1d6b7ae4cd4a709a62fc055e25c12 Mon Sep 17 00:00:00 2001
|
|
From: licunlong <licunlong1@huawei.com>
|
|
Date: Fri, 30 Jun 2023 10:55:39 +0800
|
|
Subject: [PATCH] fix: we shouldn't lookup build directory if we are not in CI
|
|
environment
|
|
|
|
---
|
|
libs/basic/src/path_lookup.rs | 51 +++++++++--------------------------
|
|
1 file changed, 12 insertions(+), 39 deletions(-)
|
|
|
|
diff --git a/libs/basic/src/path_lookup.rs b/libs/basic/src/path_lookup.rs
|
|
index c711305..4c9797d 100644
|
|
--- a/libs/basic/src/path_lookup.rs
|
|
+++ b/libs/basic/src/path_lookup.rs
|
|
@@ -11,7 +11,6 @@
|
|
// See the Mulan PSL v2 for more details.
|
|
|
|
//! the management of the unit file lookup path
|
|
-use std::env;
|
|
|
|
/// unit lookup path in /etc
|
|
pub const ETC_SYSTEM_PATH: &str = "/etc/sysmaster";
|
|
@@ -55,28 +54,6 @@ impl LookupPaths {
|
|
|
|
/// init lookup paths
|
|
pub fn init_lookup_paths(&mut self) {
|
|
- let devel_path = || {
|
|
- let out_dir = env::var("OUT_DIR").unwrap_or_else(|_x| {
|
|
- let _tmp_str: Option<&'static str> = option_env!("OUT_DIR");
|
|
- _tmp_str.unwrap_or("").to_string()
|
|
- });
|
|
- if out_dir.is_empty() {
|
|
- env::var("LD_LIBRARY_PATH").map_or("".to_string(), |_v| {
|
|
- let _tmp = _v.split(':').collect::<Vec<_>>()[0];
|
|
- let _tmp_path = _tmp.split("target").collect::<Vec<_>>()[0];
|
|
- _tmp_path.to_string()
|
|
- })
|
|
- } else {
|
|
- out_dir
|
|
- }
|
|
- };
|
|
-
|
|
- let out_dir = devel_path();
|
|
- if !out_dir.is_empty() && out_dir.contains("build") {
|
|
- let tmp_str: Vec<_> = out_dir.split("build").collect();
|
|
- self.search_path.push(tmp_str[0].to_string());
|
|
- self.preset_path.push(tmp_str[0].to_string());
|
|
- }
|
|
self.search_path.push(LIB_SYSTEM_PATH.to_string());
|
|
self.search_path.push(RUN_SYSTEM_PATH.to_string());
|
|
self.search_path.push(ETC_SYSTEM_PATH.to_string());
|
|
@@ -98,29 +75,25 @@ impl Default for LookupPaths {
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
-
|
|
- use std::env;
|
|
-
|
|
use crate::logger;
|
|
|
|
use super::LookupPaths;
|
|
#[test]
|
|
fn test_init_lookup_paths() {
|
|
logger::init_log_to_console("test_init_lookup_paths", log::LevelFilter::Trace);
|
|
- let mut _lp = LookupPaths::default();
|
|
- _lp.init_lookup_paths();
|
|
- for item in _lp.search_path.iter() {
|
|
- log::info!("lookup path is{:?}", item);
|
|
- }
|
|
- let tmp_dir = env::var("OUT_DIR");
|
|
- if tmp_dir.is_err() {
|
|
- return;
|
|
- }
|
|
- let tmp = tmp_dir.unwrap();
|
|
- let tmp_dir_v: Vec<_> = tmp.split("build").collect();
|
|
+ let mut lp = LookupPaths::default();
|
|
+ lp.init_lookup_paths();
|
|
+ assert_eq!(
|
|
+ lp.search_path,
|
|
+ vec!["/usr/lib/sysmaster", "/run/sysmaster", "/etc/sysmaster"]
|
|
+ );
|
|
assert_eq!(
|
|
- _lp.search_path.first().unwrap().to_string(),
|
|
- tmp_dir_v[0].to_string()
|
|
+ lp.preset_path,
|
|
+ vec![
|
|
+ "/etc/sysmaster/system-preset",
|
|
+ "/usr/lib/sysmaster/system-preset"
|
|
+ ]
|
|
);
|
|
+ assert_eq!(lp.persistent_path, "/etc/sysmaster")
|
|
}
|
|
}
|
|
--
|
|
2.33.0
|
|
|