features: handle all feature files in a single pass of feature_lib.get_packages()

All defined features need to be known at the same time, otherwise handling
a feed-provided feature definition file would add gluon-web-advanced etc.
to the package list when the corresponding feature flags appear in
GLUON_FEATURES.

Fixes: ee5ec5afe5 ("build: rewrite features.sh in Lua")
This commit is contained in:
Matthias Schiffer 2020-08-28 22:20:13 +02:00
parent 13b743d51e
commit a9c2db939a
2 changed files with 12 additions and 16 deletions

View File

@ -16,7 +16,7 @@ local function collect_keys(t)
return ret return ret
end end
function M.get_packages(file, features) function M.get_packages(files, features)
local enabled_features = to_keys(features) local enabled_features = to_keys(features)
local handled_features = {} local handled_features = {}
local packages = {} local packages = {}
@ -55,13 +55,15 @@ function M.get_packages(file, features)
end end
end end
-- Evaluate the feature definition file -- Evaluate the feature definition files
local f, err = loadfile(file) for _, file in ipairs(files) do
if not f then local f, err = loadfile(file)
error('Failed to parse feature definition: ' .. err) if not f then
error('Failed to parse feature definition: ' .. err)
end
setfenv(f, funcs)
f()
end end
setfenv(f, funcs)
f()
-- Handle default packages -- Handle default packages
for _, feature in ipairs(features) do for _, feature in ipairs(features) do

View File

@ -91,21 +91,15 @@ local function site_packages(image)
end end
local function feature_packages(features) local function feature_packages(features)
local pkgs = {} local files = {'package/features'}
local function handle_feature_file(file)
pkgs = concat_list(pkgs, feature_lib.get_packages(file, features))
end
handle_feature_file('package/features')
for _, feed in ipairs(feeds) do for _, feed in ipairs(feeds) do
local path = string.format('packages/%s/features', feed) local path = string.format('packages/%s/features', feed)
if file_exists(path) then if file_exists(path) then
handle_feature_file(path) table.insert(files, path)
end end
end end
return pkgs return feature_lib.get_packages(files, features)
end end
-- This involves running a few processes to evaluate site.mk, so we add a simple cache -- This involves running a few processes to evaluate site.mk, so we add a simple cache