-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: implement flexible site-selection system
Implement a flexible system for handling site-defined features as well as packages. This system is inspired by the existing feature-system and allows for a more flexible approach for selecting specific packages for devices. Features are now defined in a `features` file in the site-root. The same goes for packages. These files are sequentially evaluated and the device-package list is evaluated for each device independently. Signed-off-by: David Bauer <mail@david-bauer.net>
- Loading branch information
1 parent
0e9f9e7
commit 92ac0bb
Showing
5 changed files
with
120 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
default({ | ||
'autoupdater', | ||
'ebtables-filter-multicast', | ||
'ebtables-filter-ra-dhcp', | ||
'ebtables-limit-arp', | ||
'mesh-batman-adv-15', | ||
'mesh-vpn-fastd', | ||
'respondd', | ||
'status-page', | ||
'web-advanced', | ||
'web-wizard' | ||
}) | ||
|
||
when(not device_class('tiny'), { | ||
'wireless-encryption-wpa3' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
default({ | ||
'iwinfo', | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
local M = {} | ||
|
||
local function collect_keys(t) | ||
local ret = {} | ||
for v in pairs(t) do | ||
table.insert(ret, v) | ||
end | ||
return ret | ||
end | ||
|
||
function M.get_selection(files, env, dev) | ||
local selections = {} | ||
|
||
local funcs = {} | ||
|
||
local function add_pkgs(pkgs) | ||
for _, pkg in ipairs(pkgs or {}) do | ||
selections[pkg] = true | ||
end | ||
end | ||
|
||
function funcs.default(pkgs) | ||
assert( | ||
type(pkgs) == 'table', | ||
'Incorrect use of default(): pass a list of packages as argument') | ||
|
||
add_pkgs(pkgs) | ||
end | ||
|
||
function funcs.when(cond, pkgs) | ||
assert( | ||
type(cond) == 'boolean', | ||
'Incorrect use of when(): pass a conditional expression as first argument') | ||
|
||
if cond then | ||
add_pkgs(pkgs) | ||
end | ||
end | ||
|
||
function funcs.device(device_names) | ||
assert( | ||
type(device_names) == 'table', | ||
'Incorrect use of device(): pass a list of device-names as argument') | ||
|
||
for _, device_name in ipairs(device_names) do | ||
if device_name == dev.image then | ||
return true | ||
end | ||
end | ||
|
||
return false | ||
end | ||
|
||
function funcs.target(target, subtarget) | ||
assert( | ||
type(target) == 'string', | ||
'Incorrect use of target(): pass a target-name as first argument') | ||
|
||
if target ~= env.BOARD then | ||
return false | ||
end | ||
|
||
if subtarget and subtarget ~= env.SUBTARGET then | ||
return false | ||
end | ||
|
||
return true | ||
end | ||
|
||
function funcs.device_class(class) | ||
return dev.options.class == class | ||
end | ||
|
||
-- Evaluate the feature definition files | ||
for _, file in ipairs(files) do | ||
local f, err = loadfile(file) | ||
if not f then | ||
error('Failed to parse feature definition: ' .. err) | ||
end | ||
setfenv(f, funcs) | ||
f() | ||
end | ||
|
||
return collect_keys(selections) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters