Created
May 18, 2022 12:42
-
-
Save hroncok/1ea437d2d57f9863fa3ed05bb67a2fd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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