From c775dcb940f93f5254d487d825ae0c33085a1d91 Mon Sep 17 00:00:00 2001 From: ShifftC Date: Mon, 27 Jan 2025 15:34:23 +0100 Subject: [PATCH 1/3] Forward 'archive.extract' errors --- .../action/require/impl/actions/download.lua | 19 +++++++++++++++---- .../impl/actions/download_resources.lua | 17 +++++++++++++++-- .../require/impl/actions/patch_sources.lua | 17 +++++++++++++++-- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/xmake/modules/private/action/require/impl/actions/download.lua b/xmake/modules/private/action/require/impl/actions/download.lua index 47a8bf1242d..13a81698e1c 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 e21b0e0913f..7edd577f778 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 bd5d698bdd2..b6eba7fc129 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 From 7222c603fa360b1c2d41907d936af7f4b166fbcf Mon Sep 17 00:00:00 2001 From: ShifftC Date: Mon, 27 Jan 2025 15:35:08 +0100 Subject: [PATCH 2/3] Make extractor/archiver errors more clear --- xmake/modules/utils/archive/archive.lua | 2 +- xmake/modules/utils/archive/extract.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/modules/utils/archive/archive.lua b/xmake/modules/utils/archive/archive.lua index 80422963888..5d24c506d64 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 found") end -- only archive tar file diff --git a/xmake/modules/utils/archive/extract.lua b/xmake/modules/utils/archive/extract.lua index 7fd9360411b..196e32d670d 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 found") end -- extract file From c12f029731488cb7ccef43111642b38d57e85775 Mon Sep 17 00:00:00 2001 From: ShifftC Date: Mon, 27 Jan 2025 17:11:33 +0100 Subject: [PATCH 3/3] Improve extractor/archiver tips --- xmake/modules/utils/archive/archive.lua | 2 +- xmake/modules/utils/archive/extract.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/modules/utils/archive/archive.lua b/xmake/modules/utils/archive/archive.lua index 5d24c506d64..dbe45470529 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 "no archiver 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 196e32d670d..269c3cd59ec 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 "no extractor found") + raise("cannot extract %s, %s!", path.filename(archivefile), errors or "no extractor(like unzip, ...) found") end -- extract file