diff options
| author | ruki <[email protected]> | 2026-02-10 23:48:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-02-10 23:48:02 +0800 |
| commit | 83f17e9557c971690a276ff93a5b65d66eba709d (patch) | |
| tree | 2fd238f7864ea17b733749564aae46cd078c1888 | |
| parent | ee98b61be7054e1b8b8e2668b67c662ba12e264b (diff) | |
keep package source
| -rw-r--r-- | xmake/core/package/package.lua | 18 | ||||
| -rw-r--r-- | xmake/core/project/policy.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/package/tools/cmake.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/actions/download.lua | 2 |
4 files changed, 24 insertions, 1 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 692be9ae8..4ca402cdf 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -662,6 +662,24 @@ function _instance:is_debug() return self:config("debug") or self:config("asan") end +-- should keep package source code after installing? +function _instance:has_source() + if self:is_debug() then + return true + end + if self:is_source_embed() then + return true + end + local project = package._project() + if project and project.policy("package.keep_source") then + return true + end + if self:policy("package.keep_source") then + return true + end + return false +end + -- is the supported package? function _instance:is_supported() -- attempt to get the install script with the current plat/arch diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 0fdd70831..a1aad6d97 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -151,6 +151,8 @@ function policy.policies() ["package.install_always"] = {description = "Always install packages every time.", type = "boolean"}, -- Install packages in the local project folder ["package.install_locally"] = {description = "Install packages in the local project folder.", default = false, type = "boolean"}, + -- Keep package source code after installing (disable source dir cleanup) + ["package.keep_source"] = {description = "Keep package source code after installing.", default = false, type = "boolean"}, -- Set custom headers when downloading package ["package.download.http_headers"] = {description = "Set the custom http headers when downloading package.", type = "table"}, -- Use includes as external header files? e.g. -isystem .. diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 7bf9b8b31..1557aebeb 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -426,6 +426,9 @@ function _get_configs_for_generic(package, configs, opt) if package:is_library() then envs.BUILD_SHARED_LIBS = package:config("shared") and "ON" or "OFF" end + if package:has_source() then + envs.CMAKE_EXPORT_COMPILE_COMMANDS = "ON" + end -- https://cmake.org/cmake/help/latest/variable/CMAKE_LINKER_TYPE.html if package:has_tool("ld", "link") then envs.CMAKE_LINKER_TYPE = "MSVC" diff --git a/xmake/modules/private/action/require/impl/actions/download.lua b/xmake/modules/private/action/require/impl/actions/download.lua index a247acfdc..84c8d85be 100644 --- a/xmake/modules/private/action/require/impl/actions/download.lua +++ b/xmake/modules/private/action/require/impl/actions/download.lua @@ -271,7 +271,7 @@ function _download(package, url, sourcedir, opt) os.mv(sourcedir_tmp, sourcedir) end -- mark this sourcedir as cleanable - if not package:is_debug() then + if not package:has_source() then package:data_set("cleanable_sourcedir", path.absolute(sourcedir)) end elseif extension and extension ~= "" then |
