Skip to content
Snippets Groups Projects
Commit dd5c5033 authored by David Bauer's avatar David Bauer
Browse files

image-customization: load image-customization.lua once


Load the site image-customization.lua file only on init. Previously, the
file was loaded on every device invocation.

Signed-off-by: default avatarDavid Bauer <mail@david-bauer.net>
parent 83406bc5
No related branches found
No related tags found
No related merge requests found
local M = {} local M = {
customization_file = nil,
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 function evaluate_device(env, dev) local function evaluate_device(env, dev)
local selections = { local selections = {
...@@ -91,12 +80,8 @@ local function evaluate_device(env, dev) ...@@ -91,12 +80,8 @@ local function evaluate_device(env, dev)
end end
-- Evaluate the feature definition files -- Evaluate the feature definition files
local f, err = loadfile(get_customization_file_name(env)) setfenv(M.customization_file, funcs)
if not f then M.customization_file()
error('Failed to parse feature definition: ' .. err)
end
setfenv(f, funcs)
f()
return { return {
selections = selections, selections = selections,
...@@ -110,7 +95,8 @@ function M.get_selections(dev) ...@@ -110,7 +95,8 @@ function M.get_selections(dev)
packages = {}, 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 return return_object
end end
...@@ -119,7 +105,8 @@ function M.get_selections(dev) ...@@ -119,7 +105,8 @@ function M.get_selections(dev)
end end
function M.device_overrides(dev) 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 {} return {}
end end
...@@ -128,7 +115,17 @@ function M.device_overrides(dev) ...@@ -128,7 +115,17 @@ function M.device_overrides(dev)
end end
function M.init(env) function M.init(env)
local filename = env.GLUON_SITEDIR .. '/image-customization.lua'
M.env = env 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 end
return M return M
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