gluon/scripts/target_config_check.lua
Matthias Schiffer 9e23534ec3
build: rework config generation
So far, we were using a sort operation on the generated .config to
implement precedence of =y packages over =m, and =m over unset.
Unfortunately, this sort not only used for packages, but for all config
lines. This made it impossible to override settings from targets/generic
in a target config when the new setting was sorted before the generic
setting.

To fix this, track configurations by their keys, so we can properly
override config keys that were set before. Value-based precedence is
only preserved for package configuration.

The config() and try_config() calls always take key and value as
separate arguments now. Strings are quoted automatically; the values
true, nil and false map to y, m and unset for tristate options. config()
can take an optional third argument to override the error message to
display when the setting fails to apply.

All existing target configs generate the same .config with the old and the
new code. The new code is also a bit faster on targets with many devices.
2020-05-31 02:20:58 +02:00

40 lines
657 B
Lua
Executable File

local errors = false
local function fail(msg)
if not errors then
errors = true
io.stderr:write('Configuration failed:', '\n')
end
io.stderr:write(' * ', msg, '\n')
end
local function match_config(f)
for line in io.lines('openwrt/.config') do
if f(line) then
return true
end
end
return false
end
local function check_config(config)
return match_config(function(line) return line == config end)
end
local lib = dofile('scripts/target_config_lib.lua')()
for _, config in pairs(lib.configs) do
if config.required then
if not check_config(config:format()) then
fail(config.required)
end
end
end
if errors then
os.exit(1)
end