Skip to content

Commit

Permalink
build image-customization: create init routine
Browse files Browse the repository at this point in the history
Create an init routine which loads the environment only once instead
every evaluation.

Signed-off-by: David Bauer <[email protected]>
  • Loading branch information
blocktrron committed Dec 20, 2023
1 parent 0f04410 commit d9bb9bc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
14 changes: 9 additions & 5 deletions scripts/image_customization_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ local function evaluate_device(env, dev)
end

-- Evaluate the feature definition files
local f, err = loadfile(get_customization_file_name(env))
local f, err = loadfile(get_customization_file_name(M.env))
if not f then
error('Failed to parse feature definition: ' .. err)
end
Expand All @@ -104,27 +104,31 @@ local function evaluate_device(env, dev)
}
end

function M.get_selections(env, dev)
function M.get_selections(dev)
local return_object = {
features = {},
packages = {},
}

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

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

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

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

function M.init(env)
M.env = env
end

return M
4 changes: 3 additions & 1 deletion scripts/target_config_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ else
openwrt_config_target = env.BOARD
end

-- Initialize image-customization
image_customization_lib.init(env)

-- Split a string into words
local function split(s)
Expand Down Expand Up @@ -93,7 +95,7 @@ local function site_specific_packages(dev_info)
local site_features

-- Get all enabled selections from image-customization.lua
site_selections = image_customization_lib.get_selections(env, dev_info)
site_selections = image_customization_lib.get_selections(dev_info)

-- First read enabled features from site
site_features = site_selections['features']
Expand Down
10 changes: 4 additions & 6 deletions scripts/target_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ M.configs = {}
M.devices = {}
M.images = {}

-- Initialize image-customization
image_customization_lib.init(env)

local default_options = {
factory = '-squashfs-factory',
Expand All @@ -57,10 +59,6 @@ function F.istrue(v)
return (tonumber(v) or 0) > 0
end

local function get_device_overrides(device_info)
return image_customization_lib.device_overrides(env, device_info)
end

local function device_broken(device_info, overrides)
if F.istrue(env.BROKEN) then
return false
Expand All @@ -76,7 +74,7 @@ local function device_broken(device_info, overrides)
end

local function want_device(device_info)
local overrides = get_device_overrides(device_info)
local overrides = image_customization_lib.device_overrides(device_info)

-- Check if device is disabled via image-customization.lua in site
if overrides['disabled'] then
Expand Down Expand Up @@ -240,7 +238,7 @@ local function disable_factory_image(device_info)
return true
end

local overrides = get_device_overrides(device_info)
local overrides = image_customization_lib.device_overrides(device_info)
if overrides["disable_factory"] then
return true
end
Expand Down

0 comments on commit d9bb9bc

Please sign in to comment.