From 5af8900a45ad53726429b9a79fbfad55e56df1c2 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 24 Apr 2019 23:45:43 +0800 Subject: [PATCH] add genlist.lua --- PKGLIST.md | 53 +++++++++++++++++++++++++++++++ scripts/genlist.lua | 48 ++++++++++++++++++++++++++++ scripts/list.lua | 18 ++++++----- scripts/packages.lua | 74 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 186 insertions(+), 7 deletions(-) create mode 100755 PKGLIST.md create mode 100644 scripts/genlist.lua create mode 100644 scripts/packages.lua diff --git a/PKGLIST.md b/PKGLIST.md new file mode 100755 index 000000000..4212dd0f9 --- /dev/null +++ b/PKGLIST.md @@ -0,0 +1,53 @@ +## All Packages + +|linux(arch)|windows(arch)|iphoneos(arch)|macosx(arch)|android(arch)| +|-----|-------|--------|------|-------| +|autoconf(*)|bzip2(*)|cmake(*)|autoconf(*)|cmake(*)|| +|automake(*)|cairo(*)|doctest(*)|automake(*)|doctest(*)|| +|bzip2(*)|cmake(*)|libjpeg(*)|bzip2(*)|libjpeg(*)|| +|cairo(*)|doctest(*)|lua(*)|cairo(*)|lua(*)|| +|cjson(*)|expat(*)|nlohmann_json(*)|cjson(*)|nlohmann_json(*)|| +|cmake(*)|freeglut(*)|tbox(*)|cmake(*)|tbox(*)|| +|doctest(*)|freetype(*)|zlib(*)|doctest(*)|zlib(*)|| +|expat(*)|glew(*)||expat(*)||| +|ffmpeg(*)|go(*)||ffmpeg(*)||| +|fontconfig(*)|libjpeg(*)||fontconfig(*)||| +|freeglut(*)|libpng(*)||freetype(*)||| +|freetype(*)|libsdl(*)||glew(*)||| +|glew(*)|libuv(*)||go(*)||| +|go(*)|lua(*)||gperf(*)||| +|gperf(*)|luajit(*)||json-c(*)||| +|json-c(*)|make(*)||libev(*)||| +|libev(*)|nlohmann_json(*)||libiconv(*)||| +|libiconv(*)|patch(*)||libjpeg(*)||| +|libjpeg(*)|pcre(*)||libmill(*)||| +|libmill(*)|pixman(*)||libpng(*)||| +|libpng(*)|python(*)||libsdl(*)||| +|libsdl(*)|sqlite3(*)||libtask(*)||| +|libtask(*)|tbox(*)||libtool(*)||| +|libtool(*)|zlib(*)||libuv(*)||| +|libuv(*)|||libxml2(*)||| +|libxml2(*)|||lua(*)||| +|lua(*)|||luajit(*)||| +|luajit(*)|||make(*)||| +|make(*)|||mbedtls(*)||| +|mbedtls(*)|||mysql(*)||| +|mysql(*)|||nasm(*)||| +|nasm(*)|||ncurses(*)||| +|ncurses(*)|||nlohmann_json(*)||| +|nlohmann_json(*)|||openssl(*)||| +|openssl(*)|||patch(*)||| +|patch(*)|||pcre(*)||| +|pcre(*)|||pcre2(*)||| +|pcre2(*)|||pixman(*)||| +|pixman(*)|||pkg-config(*)||| +|pkg-config(*)|||python(*)||| +|python(*)|||sqlite3(*)||| +|sqlite3(*)|||tbox(*)||| +|tbox(*)|||util-linux(*)||| +|util-linux(*)|||x264(*)||| +|x264(*)|||x265(*)||| +|x265(*)|||xz(*)||| +|xz(*)|||yasm(*)||| +|yasm(*)|||zlib(*)||| +|zlib(*)|||||| diff --git a/scripts/genlist.lua b/scripts/genlist.lua new file mode 100644 index 000000000..9326a5114 --- /dev/null +++ b/scripts/genlist.lua @@ -0,0 +1,48 @@ +import("packages", {alias = "get_packages"}) + +function main(...) + + -- get packages + local packages = get_packages() + local tables = {} + local col = 1 + local row_max = 0 + for _, pkgs in pairs(packages) do + for row, pkg in ipairs(pkgs) do + tables[row] = tables[row] or {} + tables[row][col] = pkg + end + if #pkgs > row_max then + row_max = #pkgs + end + col = col + 1 + end + + -- generate markdown table + local packages_md = "## All Packages\n\n" + for plat, _ in pairs(packages) do + packages_md = packages_md .. "|" .. plat .. "(arch)" + end + packages_md = packages_md .. "|\n" + for plat, _ in pairs(packages) do + packages_md = packages_md .. "|" .. (plat:gsub('.', '-')) + end + packages_md = packages_md .. "|\n" + for y = 1, row_max do + for x = 1, col do + local pkg = tables[y][x] + local info = "" + if pkg then + if pkg.generic then + info = pkg.name .. "(*)" + else + info = pkg.name .. "(" .. table.concat(pkg.archs, ",") .. ")" + end + end + packages_md = packages_md .. "|" .. info + end + packages_md = packages_md .. "|\n" + end + print(packages_md) + io.writefile(path.join(os.scriptdir(), "..", "PKGLIST.md"), packages_md) +end diff --git a/scripts/list.lua b/scripts/list.lua index dfdb1247a..d0450462c 100644 --- a/scripts/list.lua +++ b/scripts/list.lua @@ -1,10 +1,14 @@ +import("packages") + function main(...) - local packages = {} - for _, dir in ipairs(os.dirs(path.join("packages", "*", "*"))) do - local package = path.filename(dir) - local key = package:sub(1, 1) - packages[key] = packages[key] or {} - table.insert(packages[key], package) + for plat, pkgs in pairs(packages()) do + cprint("${magenta}%s${clear}:", plat) + for _, pkg in ipairs(pkgs) do + if pkg.generic then + cprint(" ${yellow}->${clear} %s", pkg.name) + else + cprint(" ${yellow}->${clear} %s (%s)", pkg.name, table.concat(pkg.archs, ", ")) + end + end end - print(packages) end diff --git a/scripts/packages.lua b/scripts/packages.lua new file mode 100644 index 000000000..eb5bfad64 --- /dev/null +++ b/scripts/packages.lua @@ -0,0 +1,74 @@ +-- imports +import("core.package.package") +import("core.platform.platform") + +-- is supported platform and architecture? +function _is_supported(instance, plat, arch) + + -- get script + local script = instance:get("install") + local result = nil + if type(script) == "function" then + result = script + elseif type(script) == "table" then + + -- get plat and arch + local plat = plat or "" + local arch = arch or "" + + -- match script for special plat and arch + local pattern = plat .. '|' .. arch + for _pattern, _script in pairs(script) do + if not _pattern:startswith("__") and pattern:find('^' .. _pattern .. '$') then + result = _script + break + end + end + + -- match script for special plat + if result == nil then + for _pattern, _script in pairs(script) do + if not _pattern:startswith("__") and plat:find('^' .. _pattern .. '$') then + result = _script + break + end + end + end + + -- get generic script + result = result or script["__generic__"] + end + return result +end + +-- the main entry +function main(...) + local packages = {} + local plat = os.host() + for _, packagedir in ipairs(os.dirs(path.join("packages", "*", "*"))) do + local packagename = path.filename(packagedir) + local packagefile = path.join(packagedir, "xmake.lua") + local instance = package.load_from_repository(packagename, nil, packagedir, packagefile) + if instance then + for _, plat in ipairs({"windows", "linux", "macosx", "iphoneos", "android"}) do + local archs = platform.archs(plat) + if archs then + local package_archs = {} + for _, arch in ipairs(archs) do + if _is_supported(instance, plat, arch) then + table.insert(package_archs, arch) + end + end + if #package_archs > 0 then + packages[plat] = packages[plat] or {} + table.insert(packages[plat], {name = instance:name(), archs = package_archs, generic = #package_archs == #archs}) + end + end + end + end + end + for _, packages_plat in pairs(packages) do + table.sort(packages_plat, function(a, b) return a.name < b.name end) + end + return packages +end