Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image customization: add include() function #3148

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/user/site.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 15 additions & 3 deletions scripts/image_customization_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down