diff --git a/macros.build-constraints b/macros.build-constraints index 00835da32618b53c02523ba7280f94bb711c3f80..30110bc08af55ba0c15b127212e412c68a47c2a4 100644 --- a/macros.build-constraints +++ b/macros.build-constraints @@ -28,15 +28,38 @@ return clamp end + -- Check file exists + local function file_exists(path) + local file = io.open(path, "r") + if file ~= nil then + file:close() + return true + else + return false + end + end + -- Parse meminfo to find the total amount of memory in the system local function getmem() local mem = 0 + local docker_mem = 0 + -- General environment for l in io.lines('/proc/meminfo') do if l:sub(1, 9) == "MemTotal:" then mem = math.tointeger(string.match(l, "MemTotal:%s+(%d+)")) break end end + -- Docker environment + if file_exists('/.dockerenv') then + for line in io.lines('/sys/fs/cgroup/memory/memory.limit_in_bytes') do + docker_mem = tonumber(line) // 1024 + break + end + if docker_mem < mem then + mem = docker_mem + end + end return mem end @@ -82,6 +105,18 @@ mem_per_process = tonumber(mem_per_process) end local mem_total = 0 + local docker_mem_total = 0 + -- Check file exists + local function file_exists(path) + local file = io.open(path, "r") + if file ~= nil then + file:close() + return true + else + return false + end + end + -- General environment for line in io.lines('/proc/meminfo') do if line:sub(1, 9) == "MemTotal:" then local tokens = {} @@ -92,6 +127,16 @@ break end end + -- Docker environment + if file_exists('/.dockerenv') then + for line in io.lines('/sys/fs/cgroup/memory/memory.limit_in_bytes') do + docker_mem_total = tonumber(line) // 1024 + break + end + if docker_mem_total < mem_total then + mem_total = docker_mem_total + end + end local max_jobs = mem_total // (mem_per_process * 1024) if max_jobs < 1 then max_jobs = 1 diff --git a/openEuler-rpm-config.spec b/openEuler-rpm-config.spec index 7b8044c6d78655d5866f73537bce24c015a9991d..ef9fef1674b767f66f05cfb2d8de75e20b0dd833 100644 --- a/openEuler-rpm-config.spec +++ b/openEuler-rpm-config.spec @@ -3,7 +3,7 @@ Name: %{vendor}-rpm-config Version: 31 -Release: 34 +Release: 35 License: GPL+ AND MIT Summary: specific rpm configuration files URL: https://gitee.com/src-openeuler/openEuler-rpm-config @@ -211,6 +211,9 @@ sed -i "s|@OSCPE@|$(cat /etc/system-release-cpe)|" %{buildroot}%{rpmvdir}/%{vend %{rpmvdir}/find-requires.ksyms %changelog +* Fri Aug 29 2025 lingsheng - 31-35 +- macros.build-constraints add docker support + * Sat Aug 16 2025 Funda Wang - 31-34 - add helper macro to deal with semver - add helper macro to deal with numeric version of perl modules