summaryrefslogtreecommitdiff
path: root/xmake/rules/csharp/buildcmd.lua
diff options
context:
space:
mode:
authorJassJam <[email protected]>2026-02-28 15:37:56 +0000
committerruki <[email protected]>2026-03-14 00:10:58 +0800
commita92e7c4087443cd91dafe14d2a5aa316a288b7c5 (patch)
treee356878da6af96a71d547906006fe45ebdbb8ed3 /xmake/rules/csharp/buildcmd.lua
parenta35ec2dcea9ca5c639ca9d1332a46ede16b959c0 (diff)
feat: generate csproj on demand
Diffstat (limited to 'xmake/rules/csharp/buildcmd.lua')
-rw-r--r--xmake/rules/csharp/buildcmd.lua36
1 files changed, 31 insertions, 5 deletions
diff --git a/xmake/rules/csharp/buildcmd.lua b/xmake/rules/csharp/buildcmd.lua
index e3c45ace8..b8f85360a 100644
--- a/xmake/rules/csharp/buildcmd.lua
+++ b/xmake/rules/csharp/buildcmd.lua
@@ -18,10 +18,35 @@
-- @file buildcmd.lua
--
-import("csharp_common")
+import("modules.csharp_common", {rootdir = os.scriptdir(), alias = "csharp_common"})
+
+local function _get_output_mtime(target, targetfile, targetdirabs)
+ local mtime = targetfile and os.mtime(targetfile) or nil
+ if mtime then
+ return mtime
+ end
+
+ if targetdirabs and os.isdir(targetdirabs) then
+ -- dotnet can place outputs under tfm/rid subdirectories depending on
+ -- project properties, so scan recursively for a matching assembly name.
+ local basename = target:basename() or target:name()
+ for _, ext in ipairs({".exe", ".dll", ".so", ".dylib"}) do
+ for _, file in ipairs(os.files(path.join(targetdirabs, "**", basename .. ext))) do
+ local filemtime = os.mtime(file)
+ if filemtime and (not mtime or filemtime > mtime) then
+ mtime = filemtime
+ end
+ end
+ end
+ if not mtime then
+ mtime = os.mtime(targetdirabs)
+ end
+ end
+ return mtime
+end
function main(target, batchcmds, opt)
- local csprojfile = assert(csharp_common.find_csproj(target), "target(%s): missing csharp .csproj file!", target:name())
+ local csprojfile = assert(csharp_common.find_or_generate_csproj(target), "target(%s): missing csharp .csproj file!", target:name())
local dotnet = csharp_common.get_dotnet_program(target)
local configuration = csharp_common.build_mode_to_configuration()
local verbosity = csharp_common.get_dotnet_verbosity()
@@ -54,9 +79,10 @@ function main(target, batchcmds, opt)
local targetfile = target:targetfile()
if targetfile then
- local sourcefiles = target:sourcefiles()
- batchcmds:add_depfiles(sourcefiles)
- batchcmds:set_depmtime(os.mtime(targetfile))
+ local depfiles = table.wrap(target:sourcefiles())
+ table.insert(depfiles, csprojfile)
+ batchcmds:add_depfiles(table.unique(depfiles))
+ batchcmds:set_depmtime(_get_output_mtime(target, targetfile, targetdirabs))
batchcmds:set_depcache(target:dependfile(targetfile))
end
end