summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-03-16 23:51:45 +0800
committerruki <[email protected]>2026-03-16 23:51:45 +0800
commit0c81f2b127c94a75257f05e24508209cc10419b0 (patch)
treec38c24c7503935026925d6e8ca9266e065105f00
parent495d8e9f70608edf20f9b719df96312a21ae78c3 (diff)
remove find csproj
-rw-r--r--xmake/rules/csharp/build/target.lua4
-rw-r--r--xmake/rules/csharp/modules/csharp_utils.lua66
-rw-r--r--xmake/rules/csharp/modules/itemgroups.lua2
3 files changed, 9 insertions, 63 deletions
diff --git a/xmake/rules/csharp/build/target.lua b/xmake/rules/csharp/build/target.lua
index 689bbe6c5..eb61bdef9 100644
--- a/xmake/rules/csharp/build/target.lua
+++ b/xmake/rules/csharp/build/target.lua
@@ -25,11 +25,11 @@ import("core.project.depend")
import("utils.progress")
import(".modules.csharp_utils")
--- find or generate .csproj file
+-- generate .csproj file
function _get_csprojfile(target)
local csprojfile = target:data("csharp.csproj")
if not csprojfile then
- csprojfile = csharp_utils.find_or_generate_csproj(target)
+ csprojfile = csharp_utils.generate_csproj_file(target)
target:data_set("csharp.csproj", csprojfile)
end
return csprojfile
diff --git a/xmake/rules/csharp/modules/csharp_utils.lua b/xmake/rules/csharp/modules/csharp_utils.lua
index 4861ff0b8..23a9978ef 100644
--- a/xmake/rules/csharp/modules/csharp_utils.lua
+++ b/xmake/rules/csharp/modules/csharp_utils.lua
@@ -59,69 +59,15 @@ function _map_rid_arch(arch)
return nil
end
-function find_csproj(target)
- local csproj = target:data("csharp.csproj")
- if csproj then
- return csproj
- end
- for _, sourcefile in ipairs(target:sourcefiles()) do
- if path.extension(sourcefile):lower() == ".csproj" then
- local csprojabs = path.is_absolute(sourcefile) and sourcefile or path.absolute(sourcefile, os.projectdir())
- if os.isfile(csprojabs) then
- return csprojabs
- end
- end
- end
- return nil
-end
-
-function find_or_generate_csproj(target, opt)
- opt = opt or {}
- local csproj = find_csproj(target)
- local generated = target:data("csharp.csproj.generated")
- local generated_with_deps = target:data("csharp.csproj.generated.with_deps")
-
- -- prefer existing source .csproj directly
- if csproj and not generated then
- return csproj
- end
-
- -- generated .csproj in memory cache
- if csproj and generated then
- if opt.skip_deps or generated_with_deps then
- return csproj
- end
- end
-
+function generate_csproj_file(target, opt)
if not _is_csharp_target(target) then
return nil
end
-
- local csprojfile = csproj or _generated_csproj_path(target)
- local generated_now = false
-
- -- in load phase (skip_deps), reuse existing generated file to avoid
- -- touching mtime and causing unnecessary rebuilds.
- if not (opt.skip_deps and os.isfile(csprojfile)) then
- generate_csproj(target, csprojfile, table.join(opt, {
- is_csharp_target = _is_csharp_target,
- find_or_generate_csproj = find_or_generate_csproj
- }))
- generated_now = true
- end
-
- target:data_set("csharp.csproj", csprojfile)
- target:data_set("csharp.csproj.generated", true)
- if opt.skip_deps then
- -- keep this conservative in load phase: build/install phase will
- -- generate a deps-enabled project if needed, and content checks avoid
- -- unnecessary rewrites.
- if generated_now or generated_with_deps == nil then
- target:data_set("csharp.csproj.generated.with_deps", false)
- end
- else
- target:data_set("csharp.csproj.generated.with_deps", true)
- end
+ local csprojfile = _generated_csproj_path(target)
+ generate_csproj(target, csprojfile, table.join(opt or {}, {
+ is_csharp_target = _is_csharp_target,
+ generate_csproj_file = generate_csproj_file
+ }))
return csprojfile
end
diff --git a/xmake/rules/csharp/modules/itemgroups.lua b/xmake/rules/csharp/modules/itemgroups.lua
index 6a7506bba..93e25ea53 100644
--- a/xmake/rules/csharp/modules/itemgroups.lua
+++ b/xmake/rules/csharp/modules/itemgroups.lua
@@ -46,7 +46,7 @@ function _collect_project_references(context)
for _, depname in ipairs(table.wrap(context.target:get("deps"))) do
local dep = context.target:dep(depname)
if dep and context.opt.is_csharp_target and context.opt.is_csharp_target(dep) then
- local depcsproj = context.opt.find_or_generate_csproj and context.opt.find_or_generate_csproj(dep)
+ local depcsproj = context.opt.generate_csproj_file and context.opt.generate_csproj_file(dep)
if depcsproj then
table.insert(references, _normalize_relative(context.csprojdir, depcsproj))
end