diff options
| author | ruki <[email protected]> | 2023-02-11 00:28:51 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-02-11 00:28:51 +0800 |
| commit | a39b6c637c50a8121c06943fbd6ef27ed8ef88f7 (patch) | |
| tree | ae9e9cdbc6d12b76279728afdef317c9725000f8 | |
| parent | 12eb31bcf80ae08e762ccda65b4d2a3100f672b1 (diff) | |
improve to install package
3 files changed, 29 insertions, 6 deletions
diff --git a/tests/projects/package/toolchain_llvm/xmake.lua b/tests/projects/package/toolchain_llvm/xmake.lua index 974430856..322334cdb 100644 --- a/tests/projects/package/toolchain_llvm/xmake.lua +++ b/tests/projects/package/toolchain_llvm/xmake.lua @@ -1,7 +1,7 @@ add_rules("mode.debug", "mode.release") -add_requires("llvm 11.0.0", {alias = "llvm-11"}) +add_requires("llvm 14.0.0", {alias = "llvm-14"}) target("test") set_kind("binary") add_files("src/*.c") - set_toolchains("llvm@llvm-11") + set_toolchains("llvm@llvm-14") diff --git a/xmake/modules/private/action/require/impl/actions/download.lua b/xmake/modules/private/action/require/impl/actions/download.lua index acd465b71..d12010723 100644 --- a/xmake/modules/private/action/require/impl/actions/download.lua +++ b/xmake/modules/private/action/require/impl/actions/download.lua @@ -197,6 +197,8 @@ function _download(package, url, sourcedir, opt) else os.mv(sourcedir_tmp, sourcedir) end + -- mark this sourcedir as cleanable + package:data_set("cleanable_sourcedir", path.absolute(sourcedir)) elseif extension and extension ~= "" then -- create an empty source directory if do not extract package file os.tryrm(sourcedir) diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index b8424f940..8d24b050e 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -227,6 +227,25 @@ function _check_package_toolchains(package) end end +-- get failed install directory +function _get_installdir_failed(package) + return path.join(package:cachedir(), "installdir.failed") +end + +-- clear install directory +function _clear_installdir(package) + os.tryrm(package:installdir()) + os.tryrm(_get_installdir_failed(package)) +end + +-- clear source directory +function _clear_sourcedir(package) + local sourcedir = package:data("cleanable_sourcedir") + if sourcedir then + os.tryrm(sourcedir) + end +end + -- install the given package function main(package) @@ -282,8 +301,8 @@ function main(package) local force_reinstall = package:data("force_reinstall") or option.get("force") if force_reinstall or not package:manifest_load() then - -- clean install directory first - os.tryrm(package:installdir()) + -- clear install directory + _clear_installdir(package) -- download package resources download_resources(package) @@ -379,8 +398,7 @@ function main(package) -- copy the invalid package directory to cache local installdir = package:installdir() if os.isdir(installdir) then - local installdir_failed = path.join(package:cachedir(), "installdir.failed") - os.tryrm(installdir_failed) + local installdir_failed = _get_installdir_failed(package) if not os.isdir(installdir_failed) then os.cp(installdir, installdir_failed) end @@ -425,5 +443,8 @@ function main(package) -- leave source codes directory os.cd(oldir) + + -- clean source directory if it is no longer needed + _clear_sourcedir(package) return ok end |
