From a0fa1eda03036f3e7d2e5e228643e7e405cadfcc Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 9 Oct 2023 22:41:04 +0800 Subject: [PATCH] improve build artifacts script --- packages/g/gdk-pixbuf/xmake.lua | 2 +- scripts/build_artifacts.lua | 70 ++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/packages/g/gdk-pixbuf/xmake.lua b/packages/g/gdk-pixbuf/xmake.lua index bd68e240e..82d450366 100644 --- a/packages/g/gdk-pixbuf/xmake.lua +++ b/packages/g/gdk-pixbuf/xmake.lua @@ -18,7 +18,7 @@ package("gdk-pixbuf") add_extsources("brew::gdk-pixbuf") add_syslinks("resolv") add_patches("2.42.6", path.join(os.scriptdir(), "patches", "2.42.6", "macosx.patch"), "ad2705a5a9aa4b90fb4588bb567e95f5d82fccb6a5d463cd07462180e2e418eb") - elseif is_plat("linux") then + elseif is_plat("linux") then add_extsources("pacman::gdk-pixbuf2") end diff --git a/scripts/build_artifacts.lua b/scripts/build_artifacts.lua index d07b14c31..69438e220 100644 --- a/scripts/build_artifacts.lua +++ b/scripts/build_artifacts.lua @@ -1,6 +1,7 @@ import("core.package.package") import("core.base.semver") -import("packages") +import("core.base.hashset") +import("packages", {alias = "packages_util"}) -- load package function _load_package(packagename, packagedir, packagefile) @@ -48,6 +49,7 @@ function _build_artifacts(name, versions) end function _get_latest_modified_packages() + print("find latest modified packages ..") local instances = {} local files = os.iorun("git diff --name-only HEAD^") for _, file in ipairs(files:split('\n')) do @@ -58,17 +60,56 @@ function _get_latest_modified_packages() local packagename = path.filename(packagedir) if #path.filename(path.directory(packagedir)) == 1 then local instance = _load_package(packagename, packagedir, file) - if instance and packages.is_supported(instance, "windows") + if instance and packages_util.is_supported(instance, "windows") and (instance.is_headeronly and not instance:is_headeronly()) then table.insert(instances, instance) + print(" > %s", instance:name()) end end end end + print("%d found", #instances) return instances end -function _get_packagedeps_in_latest_24h() +function _get_all_packages() + local packages = _g.packages + if not packages then + packages = {} + for _, packagedir in ipairs(os.dirs(path.join("packages", "*", "*"))) do + local packagename = path.filename(packagedir) + local packagefile = path.join(packagedir, "xmake.lua") + local instance = _load_package(packagename, packagedir, packagefile) + local basename = instance:get("base") + if instance and basename then + local basedir = path.join("packages", basename:sub(1, 1):lower(), basename:lower()) + local basefile = path.join(basedir, "xmake.lua") + instance._BASE = _load_package(basename, basedir, basefile) + end + if instance and packages_util.is_supported(instance, "windows") + and (instance.is_headeronly and not instance:is_headeronly()) then + table.insert(packages, instance) + end + end + _g.packages = packages + end + return packages +end + +function _get_packagerefs_of(instance) + local packagerefs = {} + local packages = _get_all_packages() + for _, packageref in ipairs(packages) do + local deps = packageref:get("deps") + if deps and table.contains(table.wrap(deps), instance:name()) then + table.insert(packagerefs, packageref) + end + end + return packagerefs +end + +function _get_packagerefs_in_latest_24h() + print("find packagerefs in latest 24h ..") local instances = {} local list = os.iorun("git log --since=\"24 hours ago\" --oneline") local lines = list:split('\n') @@ -77,7 +118,6 @@ function _get_packagedeps_in_latest_24h() local commit = line:split(" ")[1] if commit and #commit == 8 then local files = os.iorun("git diff --name-only " .. commit .. "^") - print(files) for _, file in ipairs(files:split('\n')) do file = file:trim() if file:find("packages", 1, true) and path.filename(file) == "xmake.lua" then @@ -86,7 +126,7 @@ function _get_packagedeps_in_latest_24h() local packagename = path.filename(packagedir) if #path.filename(path.directory(packagedir)) == 1 then local instance = _load_package(packagename, packagedir, file) - if instance and packages.is_supported(instance, "windows") + if instance and packages_util.is_supported(instance, "windows") and (instance.is_headeronly and not instance:is_headeronly()) then table.insert(instances, instance) end @@ -95,14 +135,26 @@ function _get_packagedeps_in_latest_24h() end end end + local packagerefs = hashset.new() for _, instance in ipairs(instances) do - print(instance:name()) + print("%s: ", instance:name()) + for _, packageref in ipairs(_get_packagerefs_of(instance)) do + packagerefs:insert(packageref) + print(" -> %s", packageref:name()) + end + end + local result = {} + for _, packageref in packagerefs:keys() do + if #result < 64 then + table.insert(result, packageref) + end end + print("%d found", #result) + return result end -function main() - --_get_packagedeps_in_latest_24h() - local instances = _get_latest_modified_packages() +function main(updaterefs) + local instances = updaterefs and _get_packagerefs_in_latest_24h() or _get_latest_modified_packages() for _, instance in ipairs(instances) do local versions = instance:versions() if versions and #versions > 0 then