Skip to content

Commit

Permalink
image-customization: load image-customization.lua once
Browse files Browse the repository at this point in the history
Load the site image-customization.lua file only on init. Previously, the
file was loaded on every device invocation.

Signed-off-by: David Bauer <mail@david-bauer.net>
  • Loading branch information
blocktrron committed Dec 20, 2023
1 parent 83406bc commit dd5c503
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions scripts/image_customization_lib.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
local M = {}

local function file_exists(file)
local f = io.open(file)
if not f then
return false
end
f:close()
return true
end

local function get_customization_file_name(env)
return env.GLUON_SITEDIR .. '/image-customization.lua'
end
local M = {
customization_file = nil,
}

local function evaluate_device(env, dev)
local selections = {
Expand Down Expand Up @@ -91,12 +80,8 @@ local function evaluate_device(env, dev)
end

-- Evaluate the feature definition files
local f, err = loadfile(get_customization_file_name(env))
if not f then
error('Failed to parse feature definition: ' .. err)
end
setfenv(f, funcs)
f()
setfenv(M.customization_file, funcs)
M.customization_file()

return {
selections = selections,
Expand All @@ -110,7 +95,8 @@ function M.get_selections(dev)
packages = {},
}

if not file_exists(get_customization_file_name(M.env)) then
if M.customization_file == nil then
-- No customization file found
return return_object
end

Expand All @@ -119,7 +105,8 @@ function M.get_selections(dev)
end

function M.device_overrides(dev)
if not file_exists(get_customization_file_name(M.env)) then
if M.customization_file == nil then
-- No customization file found
return {}
end

Expand All @@ -128,7 +115,17 @@ function M.device_overrides(dev)
end

function M.init(env)
local filename = env.GLUON_SITEDIR .. '/image-customization.lua'

M.env = env

local f, _ = loadfile(filename)
if not f then
-- No customization file found, nothing to do
return
end

M.customization_file = f
end

return M

0 comments on commit dd5c503

Please sign in to comment.