From a01818f6d23dc05a1eb55ca07c17d5f3ea9f21fa Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 23 Aug 2022 21:41:03 +0200 Subject: [PATCH 1/3] scripts: target_config_lib: remove handling for targets without devices Another leftover from legacy OpenWrt targets, which we don't support anymore. --- scripts/target_config_lib.lua | 58 +++++++++++++---------------------- 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/scripts/target_config_lib.lua b/scripts/target_config_lib.lua index ccda8e42..863915ec 100644 --- a/scripts/target_config_lib.lua +++ b/scripts/target_config_lib.lua @@ -151,49 +151,33 @@ lib.include(target) lib.check_devices() -if #lib.devices > 0 then - handle_target_pkgs(lib.target_packages) +handle_target_pkgs(lib.target_packages) - for _, dev in ipairs(lib.devices) do - local device_pkgs = {} - local function handle_pkgs(pkgs) - for _, pkg in ipairs(pkgs) do - if string.sub(pkg, 1, 1) ~= '-' then - config_package(pkg, nil) - end - device_pkgs = append_to_list(device_pkgs, pkg) - end - end - - handle_pkgs(lib.target_packages) - handle_pkgs(class_packages(dev.options.class)) - handle_pkgs(dev.options.packages or {}) - handle_pkgs(site_packages(dev.image)) - - local profile_config = string.format('%s_DEVICE_%s', openwrt_config_target, dev.name) - lib.config( - 'TARGET_DEVICE_' .. profile_config, true, - string.format("unable to enable device '%s'", dev.name) - ) - lib.config( - 'TARGET_DEVICE_PACKAGES_' .. profile_config, - table.concat(device_pkgs, ' ') - ) - end -else - -- x86 fallback: no devices - local target_pkgs = {} +for _, dev in ipairs(lib.devices) do + local device_pkgs = {} local function handle_pkgs(pkgs) - target_pkgs = concat_list(target_pkgs, pkgs) + for _, pkg in ipairs(pkgs) do + if string.sub(pkg, 1, 1) ~= '-' then + config_package(pkg, nil) + end + device_pkgs = append_to_list(device_pkgs, pkg) + 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(class_packages('standard')) + handle_pkgs(class_packages(dev.options.class)) + handle_pkgs(dev.options.packages or {}) + handle_pkgs(site_packages(dev.image)) - handle_target_pkgs(target_pkgs) + local profile_config = string.format('%s_DEVICE_%s', openwrt_config_target, dev.name) + lib.config( + 'TARGET_DEVICE_' .. profile_config, true, + string.format("unable to enable device '%s'", dev.name) + ) + lib.config( + 'TARGET_DEVICE_PACKAGES_' .. profile_config, + table.concat(device_pkgs, ' ') + ) end return lib From ca219527378ad765797dfb713f002e57a34289bb Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 23 Aug 2022 22:53:45 +0200 Subject: [PATCH 2/3] scripts: target_config_lib: add aliases for virtual default packages OpenWrt's default package list contains the package "nftables", which is a virtual package provided by "nftables-json" and "nftables-nojson". Explicitly handle this case, otherwise our config check will fail when we extend our default package list with the one from OpenWrt. --- scripts/target_config_lib.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/target_config_lib.lua b/scripts/target_config_lib.lua index 863915ec..7e41f883 100644 --- a/scripts/target_config_lib.lua +++ b/scripts/target_config_lib.lua @@ -123,6 +123,14 @@ local enabled_packages = {} -- Arguments: package name and config value (true: y, nil: m, false: unset) -- Ensures precedence of y > m > unset local function config_package(pkg, v) + -- HACK: Handle virtual default packages + local subst = { + nftables = 'nftables-nojson' + } + if subst[pkg] then + pkg = subst[pkg] + end + if v == false then if not enabled_packages[pkg] then lib.try_config('PACKAGE_' .. pkg, false) From d20f8d41a05a735c86dd9ab07227e423ae49fcb3 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 23 Aug 2022 22:59:55 +0200 Subject: [PATCH 3/3] scripts: target_config_lib: prepend target default package list from openwrt/tmp/.targetinfo Device-specific package additions could generate `CONFIG_PACKAGE_...=m` lines, which would override `CONFIG_PACKAGE_...=y` lines inserted by OpenWrt for default packages (as Gluon did not know about these default packages). This resulted in the unintended removal of such packages from other devices that did not contain the same package in their device package lists. Avoid this issue by explicitly adding OpenWrt's target default package list to the front of Gluon's target package list. --- Makefile | 1 + scripts/target_config_lib.lua | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e3aa596f..565a32a0 100644 --- a/Makefile +++ b/Makefile @@ -181,6 +181,7 @@ config: $(LUA) FORCE $(call CheckSite,$(conf)); \ ) + $(OPENWRTMAKE) prepare-tmpinfo $(GLUON_ENV) $(LUA) scripts/target_config.lua > openwrt/.config $(OPENWRTMAKE) defconfig $(GLUON_ENV) $(LUA) scripts/target_config_check.lua diff --git a/scripts/target_config_lib.lua b/scripts/target_config_lib.lua index 7e41f883..ef487f06 100644 --- a/scripts/target_config_lib.lua +++ b/scripts/target_config_lib.lua @@ -154,12 +154,31 @@ local function handle_target_pkgs(pkgs) end end +local function get_default_pkgs() + local targetinfo_target = string.gsub(openwrt_config_target, '_', '/') + local target_matches = false + for line in io.lines('openwrt/tmp/.targetinfo') do + local target_match = string.match(line, '^Target: (.+)$') + if target_match then + target_matches = (target_match == targetinfo_target) + end + + local default_packages_match = string.match(line, '^Default%-Packages: (.+)$') + if target_matches and default_packages_match then + return split(default_packages_match) + end + end + + io.stderr:write('Error: unable to get default packages for OpenWrt target ', targetinfo_target, '\n') + os.exit(1) +end + lib.include('generic') lib.include(target) lib.check_devices() -handle_target_pkgs(lib.target_packages) +handle_target_pkgs(concat_list(get_default_pkgs(), lib.target_packages)) for _, dev in ipairs(lib.devices) do local device_pkgs = {}