Skip to content

Commit

Permalink
image-customization: load customization-file only once
Browse files Browse the repository at this point in the history
Load the customization-file per-target and not per-device.

Signed-off-by: David Bauer <[email protected]>
  • Loading branch information
blocktrron committed Dec 19, 2023
1 parent 0f04410 commit 7ceeab7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
30 changes: 19 additions & 11 deletions scripts/image_customization_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ local function file_exists(file)
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 selections = {
features = {},
Expand Down Expand Up @@ -91,11 +87,7 @@ 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)
setfenv(M.customization_file, funcs)
f()

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

if not file_exists(get_customization_file_name(env)) then
if not M.customization_file then
return return_object
end

Expand All @@ -119,12 +111,28 @@ function M.get_selections(env, dev)
end

function M.device_overrides(env, dev)
if not file_exists(get_customization_file_name(env)) then
if not M.customization_file then
return {}
end

local eval_result = evaluate_device(env, dev)
return eval_result.device_overrides
end

function M.set_env(env)
local file_path = env.GLUON_SITEDIR .. '/image-customization.lua'

-- Store OS environment
M.env = env

-- Check if the customization-file exists
if not file_exists(file_path) then
return
end

-- Load the customization-file
local file_content, err = loadfile(file_path)
M.customization_file = file_content
end

return M
1 change: 1 addition & 0 deletions scripts/target_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ assert(env.GLUON_TARGETSDIR)
assert(env.GLUON_RELEASE)
assert(env.GLUON_DEPRECATED)

image_customization_lib.set_env(env)

M.site_code = assert(
dofile('scripts/site_config.lua')('site.conf').site_code, 'site_code missing in site.conf'
Expand Down

0 comments on commit 7ceeab7

Please sign in to comment.