Skip to content

Commit

Permalink
improve xrepo clean #3679
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Apr 27, 2023
1 parent 5519c95 commit e28f55c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
17 changes: 17 additions & 0 deletions xmake/modules/private/action/require/impl/register_packages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

-- imports
import("core.project.project")
import("core.cache.localcache")

-- register required package environments
-- envs: bin path for *.dll, program ..
Expand Down Expand Up @@ -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()
Expand All @@ -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

18 changes: 17 additions & 1 deletion xmake/modules/private/action/require/impl/remove_packages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

-- imports
import("core.base.option")
import("core.base.hashset")
import("core.package.package")
import("core.cache.localcache")

Expand All @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit e28f55c

Please sign in to comment.