From 0c099577f29af30363c6fd73022137a475126004 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Sat, 14 Feb 2026 10:55:18 +0100 Subject: [PATCH] Add support of `nugetsource` for local directory. Add `zip.list` to get list of files from a zip file. --- modules/vstudio/vs2010_nuget.lua | 63 ++++++++++++++++++++++---------- src/host/premake.c | 1 + src/host/premake.h | 1 + src/host/zip_list.c | 33 +++++++++++++++++ website/docs/nugetsource.md | 12 +++++- website/docs/zip/zip.list.md | 17 +++++++++ website/sidebars.js | 3 +- 7 files changed, 108 insertions(+), 22 deletions(-) create mode 100644 src/host/zip_list.c create mode 100644 website/docs/zip/zip.list.md diff --git a/modules/vstudio/vs2010_nuget.lua b/modules/vstudio/vs2010_nuget.lua index 07f8b61e88..109ed380e8 100644 --- a/modules/vstudio/vs2010_nuget.lua +++ b/modules/vstudio/vs2010_nuget.lua @@ -49,6 +49,10 @@ -- function nuget2010.packageAPIInfo(prj, package) + if packageAPIInfos[package] then + return packageAPIInfos[package] + end + local id = nuget2010.packageId(package) local version = nuget2010.packageVersion(package) @@ -56,26 +60,17 @@ -- that case we can examine the nuspec file and the file listing -- locally. - local function examinePackageFromCache() - -- It should be possible to implement this for platforms other than - -- Windows, but we'll need to figure out where the NuGet cache is on - -- these platforms (or if they even have one). - - if not os.ishost("windows") then - return - end - - local cachePath = path.translate(path.join(os.getenv("userprofile"), ".nuget/packages", id)) - - if os.isdir(cachePath) then + local function examinePackageFromDirectory(directory) + if os.isdir(directory) then local packageAPIInfo = {} - printf("Examining cached NuGet package '%s'...", id) + printf("Examining NuGet package '%s' from '%s'...", id, path.translate(directory)) io.flush() - local versionPath = path.translate(path.join(cachePath, version)) + local versionPath = path.translate(path.join(directory, version)) local nuspecPath = path.translate(path.join(versionPath, id .. ".nuspec")) + local nupkgPath = path.translate(path.join(versionPath, id .. "." .. version .. ".nupkg")) if not os.isfile(nuspecPath) then return @@ -102,11 +97,21 @@ packageAPIInfo.packageEntries = {} - for _, file in ipairs(os.matchfiles(path.translate(path.join(versionPath, "**")))) do - local extension = path.getextension(file) + if zip then + local entries, err = zip.list(nupkgPath) - if extension ~= ".nupkg" and extension ~= ".sha512" then - table.insert(packageAPIInfo.packageEntries, path.translate(path.getrelative(versionPath, file))) + if err ~= nil then + p.warn("Cannot list entries of '" .. nupkgPath "'") + else + packageAPIInfo.packageEntries = entries + end + else + for _, file in ipairs(os.matchfiles(path.translate(path.join(versionPath, "**")))) do + local extension = path.getextension(file) + + if extension ~= ".nupkg" and extension ~= ".sha512" then + table.insert(packageAPIInfo.packageEntries, path.translate(path.getrelative(versionPath, file))) + end end end @@ -127,8 +132,28 @@ end end + if os.isdir(prj.nugetsource) then + examinePackageFromDirectory(path.join(prj.nugetsource, id)) + + if packageAPIInfos[package] then + return packageAPIInfos[package] + else + p.error("Cannot find package '" .. package .. "' in local directory: " .. prj.nugetsource) + end + end + if not packageAPIInfos[package] then - examinePackageFromCache() + -- Examine package from cache directory + + -- It should be possible to implement this for platforms other than + -- Windows, but we'll need to figure out where the NuGet cache is on + -- these platforms (or if they even have one). + + if os.ishost("windows") then + local cachePath = path.join(os.getenv("userprofile"), ".nuget/packages", id) + examinePackageFromDirectory(cachePath) + end + end -- If we didn't find the package from the cache, use the NuGet API diff --git a/src/host/premake.c b/src/host/premake.c index 7cadc7a31c..5ea8595914 100644 --- a/src/host/premake.c +++ b/src/host/premake.c @@ -145,6 +145,7 @@ static const luaL_Reg http_functions[] = { #ifdef PREMAKE_COMPRESSION static const luaL_Reg zip_functions[] = { { "extract", zip_extract }, + { "list", zip_list}, { NULL, NULL } }; #endif diff --git a/src/host/premake.h b/src/host/premake.h index d0adb1d373..03d343b41d 100644 --- a/src/host/premake.h +++ b/src/host/premake.h @@ -213,6 +213,7 @@ int http_download(lua_State* L); #ifdef PREMAKE_COMPRESSION int zip_extract(lua_State* L); +int zip_list(lua_State* L); #endif /* Engine interface */ diff --git a/src/host/zip_list.c b/src/host/zip_list.c new file mode 100644 index 0000000000..a0e812bf69 --- /dev/null +++ b/src/host/zip_list.c @@ -0,0 +1,33 @@ +#include "premake.h" + +#ifdef PREMAKE_COMPRESSION + +#include "zip.h" + +int zip_list(lua_State* L) +{ + const char* src = luaL_checkstring(L, 1); + + int err = 0; + struct zip* z_archive = zip_open(src, 0, &err); + + if(!z_archive) + { + lua_newtable(L); + lua_pushstring(L, "Cannot open file"); + return 2; + } + const zip_int64_t entries_count = zip_get_num_entries(z_archive, 0); + lua_createtable(L, entries_count, 0); + for(zip_int64_t i = 0; i != entries_count; ++i) + { + const char* full_name = zip_get_name(z_archive, i, 0); + lua_pushstring(L, full_name); + lua_rawseti(L, -2, i); + } + zip_close(z_archive); + lua_pushnil(L); + return 2; +} + +#endif diff --git a/website/docs/nugetsource.md b/website/docs/nugetsource.md index 56d1920d32..3c0a94e8d2 100644 --- a/website/docs/nugetsource.md +++ b/website/docs/nugetsource.md @@ -6,7 +6,7 @@ nugetsource ("url") ### Parameters ### -`url` is the NuGet v3 feed URL. +`url` is the NuGet v3 feed URL or local directory. ### Applies To ### @@ -14,14 +14,22 @@ Project configurations. ### Availability ### -Premake 5.0.0-alpha12 or later. +Nuget "galleries" since Premake 5.0.0-alpha12 or later. +Local directory since Premake 5.0.0 or later. ### Examples ### +Set source to NuGet gallery. + ```lua nugetsource "https://api.nuget.org/v3/index.json" ``` +Set source to local directory. + +```lua +nugetsource "c:/my_nuget_packages/" +``` ### See Also ### * [nuget](nuget.md) diff --git a/website/docs/zip/zip.list.md b/website/docs/zip/zip.list.md new file mode 100644 index 0000000000..6349d88010 --- /dev/null +++ b/website/docs/zip/zip.list.md @@ -0,0 +1,17 @@ +Get list of file paths contained in an archive. + +```lua +local entries, err = zip.list(sourceZip) +``` + +### Parameters ### +- `sourceZip` is the zip file which has to be extracted + +### Return Value ### + +A new table containing the path of files contained in the archive, following with error string. + +### Availability ### + +Premake 5.0.0 or later. + diff --git a/website/sidebars.js b/website/sidebars.js index d29648dfae..279049ec7b 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -511,7 +511,8 @@ module.exports = { type: 'category', label: 'zip', items: [ - 'zip/zip.extract' + 'zip/zip.extract', + 'zip/zip.list' ] } ],