Skip to content

Commit

Permalink
build: only evaluate list of site-selections once
Browse files Browse the repository at this point in the history
Signed-off-by: David Bauer <[email protected]>
  • Loading branch information
blocktrron committed Dec 13, 2023
1 parent 84202e7 commit 291fc8d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
27 changes: 19 additions & 8 deletions scripts/image_customization_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ local function get_customization_file_name(env)
end

local function evaluate_device(env, dev)
local selections = {}
local selections = {
feature = {},
package = {},
}
local funcs = {}
local device_overrides = {}

local function add_elements(element_type, element_list)
-- We depend on the fact both feature and package
-- are already initialized as empty tables
for _, element in ipairs(element_list) do
if not selections[element_type] then
selections[element_type] = {}
end

selections[element_type][element] = true
end
end
Expand Down Expand Up @@ -111,13 +112,23 @@ local function evaluate_device(env, dev)
}
end

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

if not file_exists(get_customization_file_name(env)) then
return {}
return return_object
end

local eval_result = evaluate_device(env, dev)
return collect_keys(eval_result.selections[selection_type] or {})
return_object = {
features = collect_keys(eval_result.selections['feature']),
packages = collect_keys(eval_result.selections['package']),
}

return return_object
end

function M.device_overrides(env, dev)
Expand Down
7 changes: 5 additions & 2 deletions scripts/target_config_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,18 @@ local function site_specific_packages(dev_info)
local feature_inherited_pkgs
local site_features

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

-- First read enabled features from site
site_features = image_customization_lib.get_selection('feature', env, dev_info)
site_features = site_selections['features']
site_features = compact_list(site_features, false)

-- Create List from packages inherited from features
feature_inherited_pkgs = feature_packages(site_features)

-- Read list of packages from site
site_packages = image_customization_lib.get_selection('package', env, dev_info)
site_packages = site_selections['packages']

-- Concat feature-packages with site-packages
local pkgs = concat_list(feature_inherited_pkgs, site_packages)
Expand Down

0 comments on commit 291fc8d

Please sign in to comment.