-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxmake_utils.lua
More file actions
37 lines (32 loc) · 1.14 KB
/
xmake_utils.lua
File metadata and controls
37 lines (32 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function find_jdk_path()
local jdk_path = os.getenv("JAVA_HOME")
if jdk_path and os.isdir(jdk_path) then
return jdk_path
end
if is_host("macosx") and os.isexec("/usr/libexec/java_home") then
local java_home = os.iorun("/usr/libexec/java_home --version 23"):trim()
if java_home then
return java_home
end
end
local java_exe = is_host("windows") and "java.exe" or "java"
local path_separator = is_host("windows") and ";" or ":"
local path_env = os.getenv("PATH")
if not path_env then
print("Warning: PATH environment variable not found.")
return nil
end
for directory in path_env:gmatch("[^" .. path_separator .. "]+") do
local java_path = path.join(directory, java_exe)
if os.isfile(java_path) then
local java_home = path.directory(directory)
local include_path = path.join(java_home, "include")
if os.isdir(include_path) then
return java_home
end
end
end
print("Warning: JAVA_HOME not set")
print("Warning: Java executable not found in PATH")
return nil
end