Skip to content
Snippets Groups Projects
Unverified Commit d3107790 authored by Matthias Schiffer's avatar Matthias Schiffer Committed by GitHub
Browse files

Merge pull request #2037 from freifunk-gluon/config-gen

Config generation fixes
parents 6b3b5e70 7279c401
No related branches found
No related tags found
No related merge requests found
local funcs = {} local lib = dofile('scripts/target_config_lib.lua')
function funcs.config_message(config, _, ...) for _, config in pairs(lib.configs) do
config(...) io.stdout:write(config:format(), '\n')
end
function funcs.config_package(config, pkg, value)
config('CONFIG_PACKAGE_%s=%s', pkg, value)
end
local lib = dofile('scripts/target_config_lib.lua')(funcs)
local output = {}
for config in pairs(lib.configs) do
table.insert(output, config)
end
-- The sort will make =y entries override =m ones
table.sort(output)
for _, line in ipairs(output) do
io.stdout:write(line, '\n')
end end
local errors = {} local errors = false
local function fail(msg)
local function fail(...) if not errors then
if not next(errors) then errors = true
io.stderr:write('Configuration failed:', '\n') io.stderr:write('Configuration failed:', '\n')
end end
local msg = string.format(...) io.stderr:write(' * ', msg, '\n')
if not errors[msg] then
errors[msg] = true
io.stderr:write(' * ', msg, '\n')
end
end end
local function match_config(f) local function match_config(f)
...@@ -23,49 +19,21 @@ local function match_config(f) ...@@ -23,49 +19,21 @@ local function match_config(f)
return false return false
end end
local function check_config(pattern) local function check_config(config)
return match_config(function(line) return line == pattern end) return match_config(function(line) return line == config end)
end
local function check_config_prefix(pattern)
return match_config(function(line) return string.sub(line, 1, -2) == pattern end)
end
local funcs = {}
function funcs.config_message(_, message, ...)
local pattern = string.format(...)
if not check_config(pattern) then
fail('%s', message)
end
end end
function funcs.config_package(_, pkg, value)
local pattern = string.format('CONFIG_PACKAGE_%s=%s', pkg, value)
local res
if value == 'y' then
res = check_config(pattern)
else
res = check_config_prefix(string.sub(pattern, 1, -2))
end
if not res then
fail("unable to enable package '%s'", pkg)
end
end
local lib = dofile('scripts/target_config_lib.lua')(funcs) local lib = dofile('scripts/target_config_lib.lua')
for config, v in pairs(lib.configs) do for _, config in pairs(lib.configs) do
if v == 2 then if config.required then
if not check_config(config) then if not check_config(config:format()) then
fail("unable to set '%s'", config) fail(config.required)
end end
end end
end end
if next(errors) then if errors then
os.exit(1) os.exit(1)
end end
local lib = dofile('scripts/target_lib.lua')
local env = lib.env
local target = env.GLUON_TARGET
assert(target)
assert(env.BOARD)
assert(env.SUBTARGET)
local openwrt_config_target
if env.SUBTARGET ~= '' then
openwrt_config_target = env.BOARD .. '_' .. env.SUBTARGET
else
openwrt_config_target = env.BOARD
end
-- Split a string into words -- Split a string into words
local function split(s) local function split(s)
local ret = {} local ret = {}
...@@ -40,133 +57,138 @@ local function compact_list(list, keep_neg) ...@@ -40,133 +57,138 @@ local function compact_list(list, keep_neg)
return ret return ret
end end
return function(funcs)
local lib = dofile('scripts/target_lib.lua')
local env = lib.env
local target = env.GLUON_TARGET
assert(target)
assert(env.BOARD)
assert(env.SUBTARGET)
local openwrt_config_target
if env.SUBTARGET ~= '' then
openwrt_config_target = env.BOARD .. '_' .. env.SUBTARGET
else
openwrt_config_target = env.BOARD
end
local function site_vars(var)
local function site_vars(var) return lib.exec_capture_raw(string.format(
return lib.exec_capture_raw(string.format([[ [[
MAKEFLAGS= make print _GLUON_SITE_VARS_=%s --no-print-directory -s -f - <<'END_MAKE' MAKEFLAGS= make print _GLUON_SITE_VARS_=%s --no-print-directory -s -f - <<'END_MAKE'
include $(GLUON_SITEDIR)/site.mk include $(GLUON_SITEDIR)/site.mk
print: print:
echo -n '$(_GLUON_SITE_VARS_)' echo -n '$(_GLUON_SITE_VARS_)'
END_MAKE END_MAKE
]], lib.escape(var))) ]],
end lib.escape(var)))
end
local function site_packages(image) local function site_packages(image)
return split(site_vars(string.format('$(GLUON_%s_SITE_PACKAGES)', image))) return split(site_vars(string.format('$(GLUON_%s_SITE_PACKAGES)', image)))
end end
-- TODO: Rewrite features.sh in Lua -- TODO: Rewrite features.sh in Lua
local function feature_packages(features) local function feature_packages(features)
-- Ugly hack: Lua doesn't give us the return code of a popened -- Ugly hack: Lua doesn't give us the return code of a popened
-- command, so we match on a special __ERROR__ marker -- command, so we match on a special __ERROR__ marker
local pkgs = lib.exec_capture({'scripts/features.sh', features}, '|| echo __ERROR__') local pkgs = lib.exec_capture({'scripts/features.sh', features}, '|| echo __ERROR__')
assert(string.find(pkgs, '__ERROR__') == nil, 'Error while evaluating features') assert(string.find(pkgs, '__ERROR__') == nil, 'Error while evaluating features')
return pkgs return pkgs
end end
-- This involves running lots of processes to evaluate site.mk, so we -- This involves running lots of processes to evaluate site.mk, so we
-- add a simple cache -- add a simple cache
local class_cache = {} local class_cache = {}
local function class_packages(class) local function class_packages(class)
if class_cache[class] then if class_cache[class] then
return class_cache[class] return class_cache[class]
end end
local features = site_vars(string.format('$(GLUON_FEATURES) $(GLUON_FEATURES_%s)', class)) local features = site_vars(string.format('$(GLUON_FEATURES) $(GLUON_FEATURES_%s)', class))
features = table.concat(compact_list(split(features), false), ' ') features = table.concat(compact_list(split(features), false), ' ')
local pkgs = feature_packages(features) local pkgs = feature_packages(features)
pkgs = pkgs .. ' ' .. site_vars(string.format('$(GLUON_SITE_PACKAGES) $(GLUON_SITE_PACKAGES_%s)', class)) pkgs = pkgs .. ' ' .. site_vars(string.format('$(GLUON_SITE_PACKAGES) $(GLUON_SITE_PACKAGES_%s)', class))
pkgs = compact_list(split(pkgs)) pkgs = compact_list(split(pkgs))
class_cache[class] = pkgs class_cache[class] = pkgs
return pkgs return pkgs
end end
local function handle_target_pkgs(pkgs) local enabled_packages = {}
for _, pkg in ipairs(pkgs) do -- Arguments: package name and config value (true: y, nil: m, false: unset)
if string.sub(pkg, 1, 1) == '-' then -- Ensures precedence of y > m > unset
lib.try_config('# CONFIG_PACKAGE_%s is not set', string.sub(pkg, 2)) local function config_package(pkg, v)
else if v == false then
funcs.config_package(lib.config, pkg, 'y') if not enabled_packages[pkg] then
end lib.try_config('PACKAGE_' .. pkg, false)
end end
return
end end
lib.include('generic') if v == true or not enabled_packages[pkg] then
lib.include(target) lib.config('PACKAGE_' .. pkg, v, string.format("unable to enable package '%s'", pkg))
enabled_packages[pkg] = true
lib.check_devices() end
end
if not lib.opkg then local function handle_target_pkgs(pkgs)
lib.config '# CONFIG_SIGNED_PACKAGES is not set' for _, pkg in ipairs(pkgs) do
lib.config 'CONFIG_CLEAN_IPKG=y' if string.sub(pkg, 1, 1) == '-' then
lib.packages {'-opkg'} config_package(string.sub(pkg, 2), false)
else
config_package(pkg, true)
end
end end
end
if #lib.devices > 0 then lib.include('generic')
handle_target_pkgs(lib.target_packages) lib.include(target)
for _, dev in ipairs(lib.devices) do lib.check_devices()
local profile = dev.options.profile or dev.name
local device_pkgs = {} if not lib.opkg then
local function handle_pkgs(pkgs) lib.config('SIGNED_PACKAGES', false)
for _, pkg in ipairs(pkgs) do lib.config('CLEAN_IPKG', true)
if string.sub(pkg, 1, 1) ~= '-' then lib.packages {'-opkg'}
funcs.config_package(lib.config, pkg, 'm') end
end
device_pkgs = append_to_list(device_pkgs, pkg)
end
end
handle_pkgs(lib.target_packages) if #lib.devices > 0 then
handle_pkgs(class_packages(dev.options.class)) handle_target_pkgs(lib.target_packages)
handle_pkgs(dev.options.packages or {})
handle_pkgs(site_packages(dev.image))
funcs.config_message(lib.config, string.format("unable to enable device '%s'", profile), for _, dev in ipairs(lib.devices) do
'CONFIG_TARGET_DEVICE_%s_DEVICE_%s=y', openwrt_config_target, profile) local profile = dev.options.profile or dev.name
lib.config('CONFIG_TARGET_DEVICE_PACKAGES_%s_DEVICE_%s="%s"',
openwrt_config_target, profile, local device_pkgs = {}
table.concat(device_pkgs, ' '))
end
else
-- x86 fallback: no devices
local target_pkgs = {}
local function handle_pkgs(pkgs) local function handle_pkgs(pkgs)
for _, pkg in ipairs(pkgs) do for _, pkg in ipairs(pkgs) do
target_pkgs = append_to_list(target_pkgs, pkg) if string.sub(pkg, 1, 1) ~= '-' then
config_package(pkg, nil)
end
device_pkgs = append_to_list(device_pkgs, pkg)
end end
end end
-- Just hardcode the class for device-less targets to 'standard'
-- - this is x86 only at the moment, and it will have devices
-- in OpenWrt 19.07 + 1 as well
handle_pkgs(lib.target_packages) handle_pkgs(lib.target_packages)
handle_pkgs(class_packages('standard')) handle_pkgs(class_packages(dev.options.class))
handle_pkgs(dev.options.packages or {})
handle_target_pkgs(target_pkgs) handle_pkgs(site_packages(dev.image))
local profile_config = string.format('%s_DEVICE_%s', openwrt_config_target, profile)
lib.config(
'TARGET_DEVICE_' .. profile_config, true,
string.format("unable to enable device '%s'", profile)
)
lib.config(
'TARGET_DEVICE_PACKAGES_' .. profile_config,
table.concat(device_pkgs, ' ')
)
end
else
-- x86 fallback: no devices
local target_pkgs = {}
local function handle_pkgs(pkgs)
for _, pkg in ipairs(pkgs) do
target_pkgs = append_to_list(target_pkgs, pkg)
end
end end
return lib -- Just hardcode the class for device-less targets to 'standard'
-- - this is x86 only at the moment, and it will have devices
-- in OpenWrt 19.07 + 1 as well
handle_pkgs(lib.target_packages)
handle_pkgs(class_packages('standard'))
handle_target_pkgs(target_pkgs)
end end
return lib
...@@ -150,14 +150,51 @@ local function add_image(image) ...@@ -150,14 +150,51 @@ local function add_image(image)
table.insert(M.images[device], setmetatable(image, image_mt)) table.insert(M.images[device], setmetatable(image, image_mt))
end end
function F.try_config(...)
M.configs[string.format(...)] = 1 local function format_config(k, v)
local format
if type(v) == 'string' then
format = '%s=%q'
elseif v == true then
format = '%s=y'
elseif v == nil then
format = '%s=m'
elseif v == false then
format = '# %s is not set'
else
format = '%s=%d'
end
return string.format(format, 'CONFIG_' .. k, v)
end
local config_mt = {
__index = {
format = function(config)
return format_config(config.key, config.value)
end,
}
}
local function do_config(k, v, required)
M.configs[k] = setmetatable({
key = k,
value = v,
required = required,
}, config_mt)
end end
function F.config(...) function F.try_config(k, v)
M.configs[string.format(...)] = 2 do_config(k, v)
end
function F.config(k, v, message)
if not message then
message = string.format("unable to set '%s'", format_config(k, v))
end
do_config(k, v, message)
end end
function F.packages(pkgs) function F.packages(pkgs)
for _, pkg in ipairs(pkgs) do for _, pkg in ipairs(pkgs) do
table.insert(M.target_packages, pkg) table.insert(M.target_packages, pkg)
...@@ -165,6 +202,14 @@ function F.packages(pkgs) ...@@ -165,6 +202,14 @@ function F.packages(pkgs)
end end
M.packages = F.packages M.packages = F.packages
local function as_table(v)
if type(v) == 'table' then
return v
else
return {v}
end
end
function F.device(image, name, options) function F.device(image, name, options)
options = merge(default_options, options) options = merge(default_options, options)
...@@ -196,16 +241,17 @@ function F.device(image, name, options) ...@@ -196,16 +241,17 @@ function F.device(image, name, options)
end end
if options.factory then if options.factory then
add_image { for _, ext in ipairs(as_table(options.factory_ext)) do
image = image, add_image {
name = name, image = image,
subdir = 'factory', name = name,
in_suffix = options.factory, subdir = 'factory',
out_suffix = '', in_suffix = options.factory,
extension = options.factory_ext, out_suffix = '',
aliases = options.aliases, extension = ext,
manifest_aliases = options.manifest_aliases, aliases = options.aliases,
} }
end
end end
for _, extra_image in ipairs(options.extra_images) do for _, extra_image in ipairs(options.extra_images) do
add_image { add_image {
...@@ -216,7 +262,6 @@ function F.device(image, name, options) ...@@ -216,7 +262,6 @@ function F.device(image, name, options)
out_suffix = extra_image[2], out_suffix = extra_image[2],
extension = extra_image[3], extension = extra_image[3],
aliases = options.aliases, aliases = options.aliases,
manifest_aliases = options.manifest_aliases,
} }
end end
end end
...@@ -240,7 +285,6 @@ function F.factory_image(image, name, ext, options) ...@@ -240,7 +285,6 @@ function F.factory_image(image, name, ext, options)
out_suffix = '', out_suffix = '',
extension = ext, extension = ext,
aliases = options.aliases, aliases = options.aliases,
manifest_aliases = options.manifest_aliases,
} }
end end
......
config 'CONFIG_GLUON_SPECIALIZE_KERNEL=y' config('GLUON_SPECIALIZE_KERNEL', true)
config 'CONFIG_TARGET_SQUASHFS_BLOCK_SIZE=64' config('TARGET_SQUASHFS_BLOCK_SIZE', 64)
local ATH10K_PACKAGES = { local ATH10K_PACKAGES = {
'kmod-ath10k', 'kmod-ath10k',
......
config 'CONFIG_GLUON_SPECIALIZE_KERNEL=y' config('GLUON_SPECIALIZE_KERNEL', true)
defaults { defaults {
factory = false, factory = false,
......
config 'CONFIG_GLUON_SPECIALIZE_KERNEL=y' config('GLUON_SPECIALIZE_KERNEL', true)
local ATH10K_PACKAGES = {'kmod-ath10k', '-kmod-ath10k-ct', 'ath10k-firmware-qca988x', '-ath10k-firmware-qca988x-ct'} local ATH10K_PACKAGES = {'kmod-ath10k', '-kmod-ath10k-ct', 'ath10k-firmware-qca988x', '-ath10k-firmware-qca988x-ct'}
......
config 'CONFIG_GLUON_SPECIALIZE_KERNEL=y' config('GLUON_SPECIALIZE_KERNEL', true)
no_opkg() no_opkg()
......
assert(env.GLUON_LANGS) assert(env.GLUON_LANGS)
config('CONFIG_GLUON_SITEDIR="%s"', env.GLUON_SITEDIR) config('GLUON_SITEDIR', env.GLUON_SITEDIR)
config('CONFIG_GLUON_RELEASE="%s"', env.GLUON_RELEASE) config('GLUON_RELEASE', env.GLUON_RELEASE)
try_config('CONFIG_GLUON_BRANCH="%s"', env.GLUON_BRANCH or '') try_config('GLUON_BRANCH', env.GLUON_BRANCH or '')
for lang in string.gmatch(env.GLUON_LANGS, '%S+') do for lang in string.gmatch(env.GLUON_LANGS, '%S+') do
try_config('CONFIG_GLUON_WEB_LANG_%s=y', lang) try_config('GLUON_WEB_LANG_' .. lang, true)
end end
config('CONFIG_TARGET_%s=y', env.BOARD) config('TARGET_' .. env.BOARD, true)
if env.SUBTARGET ~= '' then if env.SUBTARGET ~= '' then
config('CONFIG_TARGET_%s_%s=y', env.BOARD, env.SUBTARGET) config(string.format('TARGET_%s_%s', env.BOARD, env.SUBTARGET), true)
end end
-- Disable non-default feeds in distfeeds.conf -- Disable non-default feeds in distfeeds.conf
config('# CONFIG_FEED_gluon_base is not set') config('FEED_gluon_base', false)
local default_feeds = {} local default_feeds = {}
for feed in string.gmatch(exec_capture_raw('. scripts/default_feeds.sh && echo "$DEFAULT_FEEDS"'), '%S+') do for feed in string.gmatch(exec_capture_raw('. scripts/default_feeds.sh && echo "$DEFAULT_FEEDS"'), '%S+') do
...@@ -24,52 +24,46 @@ end ...@@ -24,52 +24,46 @@ end
for feed in string.gmatch(exec_capture_raw('. scripts/modules.sh && echo -n "$FEEDS"'), '%S+') do for feed in string.gmatch(exec_capture_raw('. scripts/modules.sh && echo -n "$FEEDS"'), '%S+') do
if not default_feeds[feed] then if not default_feeds[feed] then
config('# CONFIG_FEED_%s is not set', feed) config('FEED_' .. feed, false)
end end
end end
config '# CONFIG_TARGET_ROOTFS_INITRAMFS is not set' config('TARGET_ROOTFS_INITRAMFS', false)
config 'CONFIG_DEVEL=y' config('DEVEL', true)
config 'CONFIG_ALL_NONSHARED=y' config('ALL_NONSHARED', true)
config '# CONFIG_PACKAGE_usbip is not set' -- fails to build config('PACKAGE_usbip', false) -- fails to build
config '# CONFIG_PACKAGE_kmod-jool is not set' -- fails to build config('PACKAGE_kmod-jool', false) -- fails to build
config 'CONFIG_BUSYBOX_CUSTOM=y' config('BUSYBOX_CUSTOM', true)
config '# CONFIG_BUSYBOX_CONFIG_FEATURE_PREFER_IPV4_ADDRESS is not set' config('BUSYBOX_CONFIG_FEATURE_PREFER_IPV4_ADDRESS', false)
config 'CONFIG_PACKAGE_ATH_DEBUG=y' config('PACKAGE_ATH_DEBUG', true)
try_config 'CONFIG_TARGET_SQUASHFS_BLOCK_SIZE=256' try_config('TARGET_SQUASHFS_BLOCK_SIZE', 256)
config '# CONFIG_KERNEL_IP_MROUTE is not set' config('KERNEL_IP_MROUTE', false)
config '# CONFIG_KERNEL_IPV6_MROUTE is not set' config('KERNEL_IPV6_MROUTE', false)
try_config 'CONFIG_TARGET_MULTI_PROFILE=y' try_config('TARGET_MULTI_PROFILE', true)
try_config 'CONFIG_TARGET_PER_DEVICE_ROOTFS=y' try_config('TARGET_PER_DEVICE_ROOTFS', true)
if istrue(env.GLUON_MULTIDOMAIN) then config('GLUON_MULTIDOMAIN', istrue(env.GLUON_MULTIDOMAIN))
config 'CONFIG_GLUON_MULTIDOMAIN=y'
end
if istrue(env.GLUON_AUTOREMOVE) then config('AUTOREMOVE', istrue(env.GLUON_AUTOREMOVE))
config 'CONFIG_AUTOREMOVE=y'
end
if istrue(env.GLUON_DEBUG) then if istrue(env.GLUON_DEBUG) then
config 'CONFIG_DEBUG=y' config('DEBUG', true)
config 'CONFIG_NO_STRIP=y' config('NO_STRIP', true)
config '# CONFIG_USE_STRIP is not set' config('USE_STRIP', false)
config '# CONFIG_USE_SSTRIP is not set' config('USE_SSTRIP', false)
try_config 'CONFIG_TARGET_ROOTFS_PARTSIZE=500' try_config('TARGET_ROOTFS_PARTSIZE', 500)
end end
if not istrue(env.GLUON_MINIFY) then config('GLUON_MINIFY', istrue(env.GLUON_MINIFY))
config '# CONFIG_GLUON_MINIFY is not set'
end
packages { packages {
'-kmod-ipt-offload', '-kmod-ipt-offload',
......
config '# CONFIG_KERNEL_KALLSYMS is not set' config('KERNEL_KALLSYMS', false)
config 'CONFIG_GLUON_SPECIALIZE_KERNEL=y' config('GLUON_SPECIALIZE_KERNEL', true)
no_opkg() no_opkg()
......
config 'CONFIG_VDI_IMAGES=y' config('VDI_IMAGES', true)
config 'CONFIG_VMDK_IMAGES=y' config('VMDK_IMAGES', true)
packages { packages {
'kmod-3c59x', 'kmod-3c59x',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment