Skip to content

Commit 8484eb4

Browse files
committed
add detect cache and force, verbose option.
1 parent d42c60e commit 8484eb4

File tree

1 file changed

+47
-18
lines changed

1 file changed

+47
-18
lines changed

xmake/modules/detect/sdks/find_dia_sdk.lua

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
-- imports
2222
import("core.project.config")
23+
import("core.base.option")
2324
import("core.tool.toolchain")
25+
import("core.cache.detectcache")
2426
import("detect.sdks.find_vstudio")
2527

2628
function _is_sdkdir_valid(sdkdir)
@@ -61,23 +63,8 @@ function _find_sdkdir(sdkdir, opt)
6163
return _is_sdkdir_valid(sdkdir) and sdkdir or nil
6264
end
6365

64-
-- find DIA SDK
65-
--
66-
-- @param sdkdir the DIA SDK directory
67-
-- @param opt the argument options, e.g. {toolchain = ..., arch = ...}
68-
--
69-
-- @return the DIA SDK. e.g. {sdkdir = ..., linkdirs = ..., includedirs = ...}
70-
--
71-
-- @code
72-
--
73-
-- local toolchains = find_dia_sdk("/opt/msvc/DIA SDK")
74-
--
75-
-- @endcode
76-
--
77-
function main(sdkdir, opt)
78-
79-
-- init options
80-
opt = opt or {}
66+
function _find_dia_sdk(sdkdir, opt)
67+
-- get sdkdir
8168
sdkdir = _find_sdkdir(sdkdir, opt)
8269
if not sdkdir then
8370
return
@@ -93,7 +80,6 @@ function main(sdkdir, opt)
9380
}
9481
arch = supported_arch[arch]
9582
end
96-
9783
if not arch then
9884
return
9985
end
@@ -108,4 +94,47 @@ function main(sdkdir, opt)
10894
path.join(sdkdir, "include", arch)
10995
}
11096
}
97+
end
98+
99+
-- find DIA SDK
100+
--
101+
-- @param sdkdir the DIA SDK directory
102+
-- @param opt the argument options, e.g. {toolchain = ..., arch = ..., force = false, verbose = false}
103+
--
104+
-- @return the DIA SDK. e.g. {sdkdir = ..., linkdirs = ..., includedirs = ...}
105+
--
106+
-- @code
107+
--
108+
-- local toolchains = find_dia_sdk("/opt/msvc/DIA SDK")
109+
--
110+
-- @endcode
111+
--
112+
function main(sdkdir, opt)
113+
-- init options
114+
opt = opt or {}
115+
116+
-- attempt to load cache first
117+
local key = "detect.sdks.find_dia_sdk"
118+
local cacheinfo = detectcache:get(key) or {}
119+
if not opt.force and cacheinfo.dia_sdk and os.isdir(cacheinfo.dia_sdk.sdkdir) then
120+
return cacheinfo.dia_sdk
121+
end
122+
123+
-- find dia sdk
124+
local dia_sdk = _find_dia_sdk(sdkdir, opt)
125+
if dia_sdk then
126+
if opt.verbose or option.get("verbose") then
127+
cprint("checking for DIA SDK directory ... ${color.success}%s", dia_sdk.sdkdir)
128+
end
129+
else
130+
if opt.verbose or option.get("verbose") then
131+
cprint("checking for DIA SDK directory ... ${color.nothing}${text.nothing}")
132+
end
133+
end
134+
135+
-- save to cache
136+
cacheinfo.dia_sdk = dia_sdk or false
137+
detectcache:set(key, cacheinfo)
138+
detectcache:save()
139+
return dia_sdk
111140
end

0 commit comments

Comments
 (0)