@@ -11,27 +11,27 @@ pub use executor::*;
1111use std:: path:: PathBuf ;
1212use tokio:: process:: Command ;
1313
14- /// xmake命令包装器的主要结构
14+ /// xmake 命令包装器的主要结构
1515#[ derive( Debug , Clone ) ]
1616#[ allow( dead_code) ] // 这是一个库模块,某些方法可能在外部使用
1717pub struct XmakeWrapper {
18- /// xmake可执行文件路径
18+ /// xmake 可执行文件路径
1919 pub xmake_env : String ,
2020 /// 工作目录
2121 pub working_dir : Option < PathBuf > ,
2222}
2323
2424#[ allow( dead_code) ] // 这是一个库模块,某些方法可能在外部使用
2525impl XmakeWrapper {
26- /// 创建新的xmake包装器实例
26+ /// 创建新的 xmake 包装器实例
2727 pub fn new ( ) -> Self {
2828 Self {
2929 xmake_env : "xmake" . to_string ( ) ,
3030 working_dir : None ,
3131 }
3232 }
3333
34- /// 使用自定义xmake路径创建实例
34+ /// 使用自定义 xmake 路径创建实例
3535 pub fn with_path < P : AsRef < str > > ( xmake_path : P ) -> Self {
3636 Self {
3737 xmake_env : xmake_path. as_ref ( ) . to_string ( ) ,
@@ -45,17 +45,17 @@ impl XmakeWrapper {
4545 self
4646 }
4747
48- /// 创建一个新的xmake命令
48+ /// 创建一个新的 xmake 命令
4949 pub fn command ( & self ) -> XmakeCommandBuilder {
5050 XmakeCommandBuilder :: new ( self . clone ( ) )
5151 }
5252
53- /// 执行xmake命令
53+ /// 执行 xmake 命令
5454 pub async fn execute ( & self , cmd : & XmakeCommand ) -> Result < XmakeOutput , XmakeError > {
5555 execute_command ( self , cmd) . await
5656 }
5757
58- /// 检查xmake是否可用
58+ /// 检查 xmake 是否可用
5959 pub async fn check_available ( & self ) -> bool {
6060 let result = Command :: new ( & self . xmake_env )
6161 . arg ( "--version" )
@@ -69,13 +69,13 @@ impl XmakeWrapper {
6969 }
7070
7171 pub async fn get_xmake_path ( & self ) -> Option < PathBuf > {
72- // 首先尝试直接解析当前配置的xmake_env路径
72+ // 首先尝试直接解析当前配置的 xmake_env 路径
7373 let xmake_path = PathBuf :: from ( & self . xmake_env ) ;
7474 if xmake_path. is_absolute ( ) && xmake_path. exists ( ) {
7575 return Some ( xmake_path) ;
7676 }
7777
78- // 尝试从环境变量获取xmake路径
78+ // 尝试从环境变量获取 xmake 路径
7979 if let Ok ( xmake_root) = std:: env:: var ( "XMAKE_ROOT" ) {
8080 let xmake_exe = PathBuf :: from ( xmake_root) . join ( "bin" ) . join ( "xmake" ) ;
8181 if xmake_exe. exists ( ) {
@@ -90,7 +90,7 @@ impl XmakeWrapper {
9090 }
9191 }
9292
93- // 使用which/where命令在PATH中查找xmake
93+ // 使用 which/where 命令在 PATH 中查找 xmake
9494 let which_cmd = if cfg ! ( windows) { "where" } else { "which" } ;
9595
9696 let result = Command :: new ( which_cmd) . arg ( & self . xmake_env ) . output ( ) . await ;
@@ -109,6 +109,17 @@ impl XmakeWrapper {
109109
110110 None
111111 }
112+
113+ pub async fn get_xmake_program_dir ( & self ) -> Option < PathBuf > {
114+ if let Ok ( xmake_program_dir) = std:: env:: var ( "XMAKE_PROGRAM_DIR" ) {
115+ let xmake_program_dir = PathBuf :: from ( xmake_program_dir) ;
116+ if xmake_program_dir. exists ( ) {
117+ return Some ( xmake_program_dir) ;
118+ }
119+ }
120+
121+ None
122+ }
112123}
113124
114125impl Default for XmakeWrapper {
0 commit comments