Skip to content

Instantly share code, notes, and snippets.

@hroncok
Created May 18, 2022 12:42
Show Gist options
  • Save hroncok/1ea437d2d57f9863fa3ed05bb67a2fd2 to your computer and use it in GitHub Desktop.
Save hroncok/1ea437d2d57f9863fa3ed05bb67a2fd2 to your computer and use it in GitHub Desktop.
%spdx() %{lua:
local licenses = require 'fedora.licenses'
local expr = rpm.expand('%*')
local function convert(spdx)
if spdx == '' then
return ''
end
local fedoras = licenses.spdx2fedora[spdx]
if fedoras == nil then
rpm.expand('%{warn:Unknown SPDX license "' .. spdx .. '", using literally}')
return spdx
end
if #fedoras > 1 then
rpm.expand('%{warn:Multiple options for SPDX license "' .. spdx .. '", using the first option: "' .. fedoras[1] .. '"}')
end
return fedoras[1]
end
local idx = 1
local out = ''
local current = ''
while idx <= #expr do
if expr:sub(idx, idx+4) == ' AND ' then
out = out .. convert(current) .. ' and '
current = ''
idx = idx+4
elseif expr:sub(idx, idx+3) == ' OR ' then
out = out .. convert(current) .. ' or '
current = ''
idx = idx+3
elseif expr:sub(idx, idx) == '(' then
out = out .. convert(current) .. '('
current = ''
elseif expr:sub(idx, idx) == ')' then
out = out .. convert(current) .. ')'
current = ''
else
c = expr:sub(idx, idx)
current = current .. c
end
idx = idx+1
end
print(out .. convert(current))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment