From d931733e4e08b355483c98e6edb2eeb13f5bf5ac Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:10:01 -0500 Subject: [PATCH 1/3] feat: don't build by default when subproject --- xmake.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xmake.lua b/xmake.lua index 09b20365..2002bf2b 100644 --- a/xmake.lua +++ b/xmake.lua @@ -33,6 +33,9 @@ target("commonlibsf") -- set target kind set_kind("static") + -- set build by default + set_default(os.scriptdir() == os.projectdir()) + -- add packages add_packages("spdlog", { public = true }) From 0fceaff6c48f233d76576aec372ca3110f1c65d8 Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:11:02 -0500 Subject: [PATCH 2/3] feat: add support for plugin install and package --- xmake-extra.lua | 57 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/xmake-extra.lua b/xmake-extra.lua index 840ee78d..34b20c4d 100644 --- a/xmake-extra.lua +++ b/xmake-extra.lua @@ -32,7 +32,7 @@ constinit auto SFSEPlugin_Version = []() noexcept { return v; }();]] -local PLUGIN_VERSION_FILE = [[ +local PLUGIN_RC_FILE = [[ #include 1 VERSIONINFO @@ -77,6 +77,15 @@ rule("commonlibsf.plugin") target:set("arch", "x64") target:set("kind", "shared") + target:add("installfiles", target:targetfile(), { prefixdir = "SFSE/Plugins" }) + target:add("installfiles", target:symbolfile(), { prefixdir = "SFSE/Plugins" }) + + if os.getenv("XSE_SF_MODS_PATH") then + target:set("installdir", path.join(os.getenv("XSE_SF_MODS_PATH"), target:name())) + elseif os.getenv("XSE_SF_GAME_PATH") then + target:set("installdir", path.join(os.getenv("XSE_SF_GAME_PATH"), "Data")) + end + local conf = target:extraconf("rules", "commonlibsf.plugin") local conf_dir = path.join(target:autogendir(), "rules", "commonlibsf", "plugin") @@ -151,5 +160,49 @@ rule("commonlibsf.plugin") end add_file("plugin.cpp", PLUGIN_FILE) - add_file("version.rc", PLUGIN_VERSION_FILE) + add_file("version.rc", PLUGIN_RC_FILE) + end) + + on_install(function(target) + local srcfiles, dstfiles = target:installfiles() + if srcfiles and dstfiles then + for idx, srcfile in ipairs(srcfiles) do + os.trycp(srcfile, dstfiles[idx]) + end + end + end) + + on_package(function(target) + import("core.project.config") + import("core.project.project") + import("utils.archive") + + local archive_name = target:name() .. "-" .. (target:version() or "0.0.0") .. ".zip" + print("packing %s .. ", archive_name) + + local root_dir = path.join(os.tmpdir(), "packages", project.name() or "", target:name()) + os.tryrm(root_dir) + + local srcfiles, dstfiles = target:installfiles(path.join(root_dir, "Data")) + if srcfiles and dstfiles then + for idx, srcfile in ipairs(srcfiles) do + os.trycp(srcfile, dstfiles[idx]) + end + end + + local archive_path = path.join(config.buildir(), "packages", archive_name) + local old_dir = os.cd(root_dir) + local archive_files = os.files("**") + os.cd(old_dir) + archive.archive(path.absolute(archive_path), archive_files, { curdir = root_dir }) + end) + + after_build(function(target) + import("core.project.depend") + import("core.project.project") + import("core.project.task") + + depend.on_changed(function() + task.run("install") + end, { files = project.allfiles(), changed = target:is_rebuilt()}) end) From 7992849c32303361374b9e6d44ffa0dd6a5fdff0 Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:34:42 -0500 Subject: [PATCH 3/3] fix: fail gracefully --- xmake-extra.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/xmake-extra.lua b/xmake-extra.lua index 34b20c4d..d8b028fd 100644 --- a/xmake-extra.lua +++ b/xmake-extra.lua @@ -165,7 +165,7 @@ rule("commonlibsf.plugin") on_install(function(target) local srcfiles, dstfiles = target:installfiles() - if srcfiles and dstfiles then + if srcfiles and #srcfiles > 0 and dstfiles and #dstfiles > 0 then for idx, srcfile in ipairs(srcfiles) do os.trycp(srcfile, dstfiles[idx]) end @@ -184,10 +184,12 @@ rule("commonlibsf.plugin") os.tryrm(root_dir) local srcfiles, dstfiles = target:installfiles(path.join(root_dir, "Data")) - if srcfiles and dstfiles then + if srcfiles and #srcfiles > 0 and dstfiles and #dstfiles > 0 then for idx, srcfile in ipairs(srcfiles) do os.trycp(srcfile, dstfiles[idx]) end + else + return end local archive_path = path.join(config.buildir(), "packages", archive_name) @@ -203,6 +205,9 @@ rule("commonlibsf.plugin") import("core.project.task") depend.on_changed(function() - task.run("install") + local srcfiles, dstfiles = target:installfiles() + if srcfiles and #srcfiles > 0 and dstfiles and #dstfiles > 0 then + task.run("install") + end end, { files = project.allfiles(), changed = target:is_rebuilt()}) end)