From f8723406844fa8b2f2fe9904e67e69e6cd99a9d2 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 17 Mar 2026 00:04:58 +0800 Subject: move generate csproj to config --- xmake/rules/csharp/config.lua | 50 ++++++++++++++++++++++++++++++++++++++++++ xmake/rules/csharp/prepare.lua | 50 ------------------------------------------ xmake/rules/csharp/xmake.lua | 2 +- 3 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 xmake/rules/csharp/config.lua delete mode 100644 xmake/rules/csharp/prepare.lua diff --git a/xmake/rules/csharp/config.lua b/xmake/rules/csharp/config.lua new file mode 100644 index 000000000..97b3a4303 --- /dev/null +++ b/xmake/rules/csharp/config.lua @@ -0,0 +1,50 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, Xmake Open Source Community. +-- +-- @author ruki +-- @file config.lua +-- + +-- imports +import("core.project.config") +import("core.project.depend") +import("modules.csproj_generator", {rootdir = os.scriptdir()}) + +function main(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 csprojfile = path.join(csprojdir, target:name() .. ".csproj") + local dependfile = target:dependfile(csprojfile) + + -- 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 + + -- generate csproj incrementally + depend.on_changed(function () + csproj_generator(target, csprojfile) + end, {dependfile = dependfile, files = sourcefiles, values = depcsproj}) + + target:data_set("csharp.csproj", csprojfile) +end diff --git a/xmake/rules/csharp/prepare.lua b/xmake/rules/csharp/prepare.lua deleted file mode 100644 index 611ad5890..000000000 --- a/xmake/rules/csharp/prepare.lua +++ /dev/null @@ -1,50 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, Xmake Open Source Community. --- --- @author ruki --- @file prepare.lua --- - --- imports -import("core.project.config") -import("core.project.depend") -import("modules.csproj_generator", {rootdir = os.scriptdir()}) - -function main(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 csprojfile = path.join(csprojdir, target:name() .. ".csproj") - local dependfile = target:dependfile(csprojfile) - - -- 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 - - -- generate csproj incrementally - depend.on_changed(function () - csproj_generator(target, csprojfile) - end, {dependfile = dependfile, files = sourcefiles, values = depcsproj}) - - target:data_set("csharp.csproj", csprojfile) -end diff --git a/xmake/rules/csharp/xmake.lua b/xmake/rules/csharp/xmake.lua index 1d5818337..f13003520 100644 --- a/xmake/rules/csharp/xmake.lua +++ b/xmake/rules/csharp/xmake.lua @@ -20,7 +20,7 @@ rule("csharp.build") set_sourcekinds("cs") - on_prepare("prepare") + on_config("config") on_build("build") rule("csharp") -- cgit v1.3.1