diff options
| author | ruki <[email protected]> | 2023-04-27 22:39:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-04-27 22:39:39 +0800 |
| commit | e28f55cccea484270d628e9c8c5d972c0cded42b (patch) | |
| tree | bf00707f6c9c346bda48b6858a0eb901c49c4024 | |
| parent | 5519c957c6fb9e4eb9098dcafba17aa483993267 (diff) | |
improve xrepo clean #3679
| -rw-r--r-- | xmake/modules/private/action/require/impl/register_packages.lua | 17 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/remove_packages.lua | 18 |
2 files changed, 34 insertions, 1 deletions
diff --git a/xmake/modules/private/action/require/impl/register_packages.lua b/xmake/modules/private/action/require/impl/register_packages.lua index cfc18b2f3..a6f0e750a 100644 --- a/xmake/modules/private/action/require/impl/register_packages.lua +++ b/xmake/modules/private/action/require/impl/register_packages.lua @@ -20,6 +20,7 @@ -- imports import("core.project.project") +import("core.cache.localcache") -- register required package environments -- envs: bin path for *.dll, program .. @@ -129,6 +130,8 @@ end -- register all required root packages to local cache function main(packages) + + -- register to package cache for add_packages() for _, instance in ipairs(packages) do if instance:is_toplevel() then local required_packagename = instance:alias() or instance:name() @@ -138,5 +141,19 @@ function main(packages) end end end + + -- register references for `xrepo clean` + -- @see https://github.com/xmake-io/xmake/issues/3679 + local references = {} + for _, instance in ipairs(packages) do + if not instance:is_system() and not instance:is_thirdparty() then + local installdir = instance:installdir({readonly = true}) + if os.isdir(installdir) then + table.insert(references, installdir) + end + end + end + localcache.set("references", "packages", references) + localcache.save("references") end diff --git a/xmake/modules/private/action/require/impl/remove_packages.lua b/xmake/modules/private/action/require/impl/remove_packages.lua index f8f93c663..1a5e99f83 100644 --- a/xmake/modules/private/action/require/impl/remove_packages.lua +++ b/xmake/modules/private/action/require/impl/remove_packages.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.base.hashset") import("core.package.package") import("core.cache.localcache") @@ -44,6 +45,21 @@ function _get_package_configs_str(manifest_file) end end +-- has reference from project? +-- @see https://github.com/xmake-io/xmake/issues/3679 +function _has_reference_from_project(projectdir, packagedir) + local project_references_file = path.join(projectdir, ".xmake", os.host(), os.arch(), "cache", "references") + if os.isfile(project_references_file) then + local references = io.load(project_references_file) + if references and references.packages then + local packages = hashset.from(references.packages) + if packages:has(packagedir) then + return true + end + end + end +end + -- remove package directories function _remove_packagedirs(packagedir, opt) @@ -58,7 +74,7 @@ function _remove_packagedirs(packagedir, opt) local references = os.isfile(references_file) and io.load(references_file) or nil if references then for projectdir, refdate in pairs(references) do - if os.isdir(projectdir) then + if os.isdir(projectdir) and _has_reference_from_project(projectdir, hashdir) then referenced = true break end |
