summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-03-17 00:03:55 +0800
committerruki <[email protected]>2026-03-17 00:03:55 +0800
commit9ad1383808d20fbb5ffcfd69dfb507f87c28c3ac (patch)
treee4592ae9e32de3fce57a273b26824caa5a098615
parentb4a1c11be9dac3472299aba9165b4b182dcdc8c1 (diff)
move generate csproj to prepare.lua
-rw-r--r--xmake/rules/csharp/build.lua (renamed from xmake/rules/csharp/build/target.lua)13
-rw-r--r--xmake/rules/csharp/prepare.lua (renamed from xmake/rules/csharp/modules/csharp_utils.lua)48
-rw-r--r--xmake/rules/csharp/xmake.lua3
3 files changed, 25 insertions, 39 deletions
diff --git a/xmake/rules/csharp/build/target.lua b/xmake/rules/csharp/build.lua
index eb61bdef9..9bc6f2e76 100644
--- a/xmake/rules/csharp/build/target.lua
+++ b/xmake/rules/csharp/build.lua
@@ -23,17 +23,6 @@ import("core.base.option")
import("core.tool.compiler")
import("core.project.depend")
import("utils.progress")
-import(".modules.csharp_utils")
-
--- generate .csproj file
-function _get_csprojfile(target)
- local csprojfile = target:data("csharp.csproj")
- if not csprojfile then
- csprojfile = csharp_utils.generate_csproj_file(target)
- target:data_set("csharp.csproj", csprojfile)
- end
- return csprojfile
-end
-- build the source files
function build_sourcefiles(target, sourcebatch, opt)
@@ -44,7 +33,7 @@ function build_sourcefiles(target, sourcebatch, opt)
-- get source files and kind
local sourcefiles = sourcebatch.sourcefiles
local sourcekind = sourcebatch.sourcekind
- local csprojfile = _get_csprojfile(target)
+ local csprojfile = target:data("csharp.csproj")
-- get depend file
local dependfile = target:dependfile(targetfile)
diff --git a/xmake/rules/csharp/modules/csharp_utils.lua b/xmake/rules/csharp/prepare.lua
index 78837cff9..611ad5890 100644
--- a/xmake/rules/csharp/modules/csharp_utils.lua
+++ b/xmake/rules/csharp/prepare.lua
@@ -14,41 +14,37 @@
--
-- Copyright (C) 2015-present, Xmake Open Source Community.
--
--- @author JassJam
--- @file csharp_utils.lua
+-- @author ruki
+-- @file prepare.lua
--
-- imports
import("core.project.config")
-import("csproj_generator", {alias = "generate_csproj"})
+import("core.project.depend")
+import("modules.csproj_generator", {rootdir = os.scriptdir()})
-function _is_csharp_target(target)
- if target:rule("csharp") then
- return true
- end
- for _, sourcefile in ipairs(target:sourcefiles()) do
- local ext = path.extension(sourcefile):lower()
- if ext == ".cs" or ext == ".csproj" then
- return true
- end
- end
- return false
-end
+function main(target)
-function _generated_csproj_path(target)
+ -- compute csproj path
local targetkey = target:fullname():replace("::", path.sep())
local csprojdir = path.join(config.directory(), "rules", "csharp", targetkey, target:plat(), target:arch())
- local csprojname = target:name() .. ".csproj"
- return path.join(csprojdir, csprojname)
-end
+ local csprojfile = path.join(csprojdir, target:name() .. ".csproj")
+ local dependfile = target:dependfile(csprojfile)
-function generate_csproj_file(target)
- if not _is_csharp_target(target) then
- return nil
+ -- collect source files and dep csproj paths as depend values
+ local sourcefiles = target:sourcefiles()
+ local depcsproj = {}
+ for _, dep in ipairs(target:orderdeps()) do
+ local depcsproj_path = dep:data("csharp.csproj")
+ if depcsproj_path then
+ table.insert(depcsproj, depcsproj_path)
+ end
end
- local csprojfile = _generated_csproj_path(target)
- generate_csproj(target, csprojfile)
+
+ -- generate csproj incrementally
+ depend.on_changed(function ()
+ csproj_generator(target, csprojfile)
+ end, {dependfile = dependfile, files = sourcefiles, values = depcsproj})
+
target:data_set("csharp.csproj", csprojfile)
- return csprojfile
end
-
diff --git a/xmake/rules/csharp/xmake.lua b/xmake/rules/csharp/xmake.lua
index 30611d68a..1d5818337 100644
--- a/xmake/rules/csharp/xmake.lua
+++ b/xmake/rules/csharp/xmake.lua
@@ -20,7 +20,8 @@
rule("csharp.build")
set_sourcekinds("cs")
- on_build("build.target")
+ on_prepare("prepare")
+ on_build("build")
rule("csharp")
add_deps("csharp.build")