summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-01-28 09:34:24 +0800
committerGitHub <[email protected]>2025-01-28 09:34:24 +0800
commit1c95d287f8bf7b80afc30e68ceb7f438afcccb7a (patch)
tree8a4eda704b51a80efef9e6a3416bb89418aaec59
parent56162130cb62ff02fe27a9978efc687934673a5f (diff)
parentc12f029731488cb7ccef43111642b38d57e85775 (diff)
Merge pull request #6124 from Shiffted/extract_error
Clearer extract errors
-rw-r--r--xmake/modules/private/action/require/impl/actions/download.lua19
-rw-r--r--xmake/modules/private/action/require/impl/actions/download_resources.lua17
-rw-r--r--xmake/modules/private/action/require/impl/actions/patch_sources.lua17
-rw-r--r--xmake/modules/utils/archive/archive.lua2
-rw-r--r--xmake/modules/utils/archive/extract.lua2
5 files changed, 47 insertions, 10 deletions
diff --git a/xmake/modules/private/action/require/impl/actions/download.lua b/xmake/modules/private/action/require/impl/actions/download.lua
index 47a8bf124..13a81698e 100644
--- a/xmake/modules/private/action/require/impl/actions/download.lua
+++ b/xmake/modules/private/action/require/impl/actions/download.lua
@@ -220,7 +220,20 @@ function _download(package, url, sourcedir, opt)
local sourcedir_tmp = sourcedir .. ".tmp"
os.rm(sourcedir_tmp)
local extension = archive.extension(packagefile)
- local ok = try {function() archive.extract(packagefile, sourcedir_tmp, {excludes = opt.url_excludes}); return true end}
+ local errors
+ local ok = try {
+ function()
+ archive.extract(packagefile, sourcedir_tmp, {excludes = opt.url_excludes})
+ return true
+ end,
+ catch {
+ function (errs)
+ if errs then
+ errors = tostring(errs)
+ end
+ end
+ }
+ }
if ok then
-- move to source directory and we skip it to avoid long path issues on windows if only one root directory
os.rm(sourcedir)
@@ -241,7 +254,7 @@ function _download(package, url, sourcedir, opt)
-- create an empty source directory if do not extract package file
os.tryrm(sourcedir)
os.mkdir(sourcedir)
- raise("cannot extract %s, maybe extractors(like unzip, ...) are not found!", packagefile)
+ raise(errors or string.format("cannot extract %s, maybe missing extractor or invalid package file!", packagefile))
else
-- if it is not archive file, we only need to create empty source directory and use package:originfile()
os.tryrm(sourcedir)
@@ -439,5 +452,3 @@ function main(package, opt)
os.cd(oldir)
return ok
end
-
-
diff --git a/xmake/modules/private/action/require/impl/actions/download_resources.lua b/xmake/modules/private/action/require/impl/actions/download_resources.lua
index e21b0e091..7edd577f7 100644
--- a/xmake/modules/private/action/require/impl/actions/download_resources.lua
+++ b/xmake/modules/private/action/require/impl/actions/download_resources.lua
@@ -135,14 +135,27 @@ function _download(package, resource_name, resource_url, resource_hash)
local resourcedir_tmp = resourcedir .. ".tmp"
os.tryrm(resourcedir_tmp)
local extension = archive.extension(resource_file)
- local ok = try {function() archive.extract(resource_file, resourcedir_tmp); return true end}
+ local errors
+ local ok = try {
+ function()
+ archive.extract(resource_file, resourcedir_tmp)
+ return true
+ end,
+ catch {
+ function (errs)
+ if errs then
+ errors = tostring(errs)
+ end
+ end
+ }
+ }
if ok then
os.tryrm(resourcedir)
os.mv(resourcedir_tmp, resourcedir)
elseif extension and extension ~= "" then
os.tryrm(resourcedir_tmp)
os.tryrm(resourcedir)
- raise("cannot extract %s", resource_file)
+ raise(errors or string.format("cannot extract %s", resource_file))
else
-- if it is not archive file, we only need to create empty resource directory and use package:resourcefile(resource_name)
os.tryrm(resourcedir)
diff --git a/xmake/modules/private/action/require/impl/actions/patch_sources.lua b/xmake/modules/private/action/require/impl/actions/patch_sources.lua
index bd5d698bd..b6eba7fc1 100644
--- a/xmake/modules/private/action/require/impl/actions/patch_sources.lua
+++ b/xmake/modules/private/action/require/impl/actions/patch_sources.lua
@@ -107,14 +107,27 @@ function _patch(package, patchinfo)
local patchdir = patch_file .. ".dir"
local patchdir_tmp = patchdir .. ".tmp"
os.tryrm(patchdir_tmp)
- local ok = try {function() archive.extract(patch_file, patchdir_tmp); return true end}
+ local errors
+ local ok = try {
+ function()
+ archive.extract(patch_file, patchdir_tmp)
+ return true
+ end,
+ catch {
+ function (errs)
+ if errs then
+ errors = tostring(errs)
+ end
+ end
+ }
+ }
if ok then
os.tryrm(patchdir)
os.mv(patchdir_tmp, patchdir)
else
os.tryrm(patchdir_tmp)
os.tryrm(patchdir)
- raise("cannot extract %s", patch_file)
+ raise(errors or string.format("cannot extract %s", patch_file))
end
-- apply patch files
diff --git a/xmake/modules/utils/archive/archive.lua b/xmake/modules/utils/archive/archive.lua
index 804229638..dbe454705 100644
--- a/xmake/modules/utils/archive/archive.lua
+++ b/xmake/modules/utils/archive/archive.lua
@@ -306,7 +306,7 @@ function _archive(archivefile, inputfiles, extension, archivers, opt)
return true
end
end
- raise("cannot archive %s, %s!", path.filename(archivefile), errors or "archivers not found!")
+ raise("cannot archive %s, %s!", path.filename(archivefile), errors or "no archiver(like zip, ...) found")
end
-- only archive tar file
diff --git a/xmake/modules/utils/archive/extract.lua b/xmake/modules/utils/archive/extract.lua
index 7fd936041..269c3cd59 100644
--- a/xmake/modules/utils/archive/extract.lua
+++ b/xmake/modules/utils/archive/extract.lua
@@ -446,7 +446,7 @@ function _extract(archivefile, outputdir, extension, extractors, opt)
return true
end
end
- raise("cannot extract %s, %s!", path.filename(archivefile), errors or "extractors not found!")
+ raise("cannot extract %s, %s!", path.filename(archivefile), errors or "no extractor(like unzip, ...) found")
end
-- extract file