From 7d735b599d06e690cbad8dd4566d96b8e71380f6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 5 Jan 2024 12:07:04 +0100 Subject: [PATCH 1/3] Makefile: remove duplicate `.` from error messages $(error ...) already adds a `.` to the end of error messages. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5fa37a4322..21964c16b1 100644 --- a/Makefile +++ b/Makefile @@ -36,11 +36,11 @@ ifneq ($(GLUON_BRANCH),) endif ifneq ($(GLUON_FEATURES)$(GLUON_FEATURES_standard)$(GLUON_FEATURES_tiny),) - $(error *** Warning: GLUON_FEATURES has been obsolete, please use the image-customization.lua file instead.) + $(error *** Warning: GLUON_FEATURES has been obsolete, please use the image-customization.lua file instead) endif ifneq ($(GLUON_SITE_PACKAGES)$(GLUON_SITE_PACKAGES_standard)$(GLUON_SITE_PACKAGES_tiny),) - $(error *** Warning: GLUON_SITE_PACKAGES has been obsolete, please use the image-customization.lua file instead.) + $(error *** Warning: GLUON_SITE_PACKAGES has been obsolete, please use the image-customization.lua file instead) endif GLUON_AUTOUPDATER_ENABLED ?= 0 From 19ea52062139517d9b387305df42238765d400dc Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 5 Jan 2024 12:05:54 +0100 Subject: [PATCH 2/3] scripts: image_customization_lib: make error messages lowercase Error messages generated by Lua usually start with a lowercase letter. Let's make our own messages match. --- scripts/image_customization_lib.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/image_customization_lib.lua b/scripts/image_customization_lib.lua index 3abe9d6943..1303714217 100644 --- a/scripts/image_customization_lib.lua +++ b/scripts/image_customization_lib.lua @@ -33,7 +33,7 @@ local function evaluate_device(env, dev) function funcs.broken(broken) assert( type(broken) == 'boolean', - 'Incorrect use of broken(): has to be a boolean value') + 'incorrect use of broken(): has to be a boolean value') add_override('broken', broken) end @@ -48,7 +48,7 @@ local function evaluate_device(env, dev) function funcs.device(device_names) assert( type(device_names) == 'table', - 'Incorrect use of device(): pass a list of device names as argument') + 'incorrect use of device(): pass a list of device names as argument') for _, device_name in ipairs(device_names) do if device_name == dev.image then @@ -62,7 +62,7 @@ local function evaluate_device(env, dev) function funcs.target(target, subtarget) assert( type(target) == 'string', - 'Incorrect use of target(): pass a target name as first argument') + 'incorrect use of target(): pass a target name as first argument') if target ~= env.BOARD then return false From fa09986e54a6a8730c0003febd7bc6fc87783b96 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 5 Jan 2024 11:40:11 +0100 Subject: [PATCH 3/3] scripts: image_customization_lib: add include() function Add a simple way to include image customization Lua snippets. Can be used to split long files, to include the same options multiple times in different conditional branches, or even to pass values back to the including file using return. Relative paths are interpreted relative to the site root (where image-customization.lua is located). Relative includes would become confusing when subdirectories are involved (as they are still interpreted relative to the site root, and proper tracking of current directory for each include seems fairly complex for a very niche use case), so we simply reject this case for now; this way, we can implement this however we want in the future if deemed necessary, without a breaking change. --- docs/user/site.rst | 4 ++++ scripts/image_customization_lib.lua | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/docs/user/site.rst b/docs/user/site.rst index 7f8f544be6..fcd245e4f3 100644 --- a/docs/user/site.rst +++ b/docs/user/site.rst @@ -728,6 +728,10 @@ disable_factory() Disables factory image generation. Sysupgrade images are still generated and stored in the image output directory. +include(path) + Includes another image customization file. Relative paths are interpreted relative to the site + repository root. Values returned from the included file become the return value of ``include``. + Technically, the image customzation file is evaluated once for each device, allowing to make use of regular Lua *if* statements for device-specific configuration as can be seen in the example. diff --git a/scripts/image_customization_lib.lua b/scripts/image_customization_lib.lua index 1303714217..3a4677aca0 100644 --- a/scripts/image_customization_lib.lua +++ b/scripts/image_customization_lib.lua @@ -79,6 +79,18 @@ local function evaluate_device(env, dev) return dev.options.class == class end + function funcs.include(path) + if string.sub(path, 1, 1) ~= '/' then + assert( + string.find(path, '/') == nil, + 'incorrect use of include(): including files from subdirectories is unsupported') + path = env.GLUON_SITEDIR .. '/' .. path + end + local f = assert(loadfile(path)) + setfenv(f, funcs) + return f() + end + -- Evaluate the feature definition files setfenv(M.customization_file, funcs) M.customization_file()