Skip to content
Snippets Groups Projects
Select Git revision
  • ee5ec5afe5eac7c1347c4c12172a58855aaac67e
  • experimental
  • master
  • v2021.1.2-ffs
  • v2021.1.1-ffs
  • nrb/gluon-master-cpe510
  • v2021.1-ffs
  • v2020.2.3-ffs
  • nrbffs/fastd-remove-delay
  • v2020.2.2-ffs
  • v2020.2.1-ffs
  • v2020.2-ffs
  • v2020.2.x
  • v2020.1.3-ffs
  • v2020.1.1-ffs
  • v2020.1-ffs
  • v2019.1.2-ffs
  • v2019.1.1-ffs
  • nrb/test-radv-filter
  • v2019.1-ffs
  • nrbffs/netgear-ex6120
  • v2021.1.2-ffs0.2
  • v2021.1.2-ffs0.1
  • v2021.1.1-ffs0.4
  • v2021.1.1-ffs0.3
  • v2021.1.1-ffs0.2
  • v2021.1.1-ffs0.1
  • v2021.1-ffs0.1
  • v2020.2.3-ffs0.3
  • v2020.2.3-ffs0.2
  • v2020.2.3-ffs0.1
  • v2020.2.2-ffs0.1
  • v2020.2.1-ffs0.1
  • v2020.2-ffs0.1
  • v2020.2
  • v2020.2.x-ffs0.1
  • v2020.1.3-ffs0.1
  • v2020.1.1-ffs0.1
  • v2020.1-ffs0.1
  • v2019.1.2-ffs0.1
  • v2019.1.1-ffs0.1
41 results

feature_lib.lua

Blame
  • Forked from firmware / FFS Gluon
    Source project has a limited visibility.
    • Matthias Schiffer's avatar
      ee5ec5af
      build: rewrite features.sh in Lua · ee5ec5af
      Matthias Schiffer authored
      The `features` file is converted to a Lua-based DSL.
      
      A helper function `_` is used in the DSL; this will return the original
      string for enabled features, and nil for disabled features. This allows
      to use boolean operations on features without making the code too
      verbose.
      
      Besides having more readable and robust code, this also fixes the bug
      that all files `packages/*/features` were evaluated instead of only
      using the feature definitions of currently active feeds.
      ee5ec5af
      History
      build: rewrite features.sh in Lua
      Matthias Schiffer authored
      The `features` file is converted to a Lua-based DSL.
      
      A helper function `_` is used in the DSL; this will return the original
      string for enabled features, and nil for disabled features. This allows
      to use boolean operations on features without making the code too
      verbose.
      
      Besides having more readable and robust code, this also fixes the bug
      that all files `packages/*/features` were evaluated instead of only
      using the feature definitions of currently active feeds.
    feature_lib.lua 989 B
    local M = {}
    
    local function to_keys(t)
    	local ret = {}
    	for _, v in ipairs(t) do
    		ret[v] = true
    	end
    	return ret
    end
    
    local function collect_keys(t)
    	local ret = {}
    	for v in pairs(t) do
    		table.insert(ret, v)
    	end
    	return ret
    end
    
    function M.get_packages(file, features)
    	local feature_table = to_keys(features)
    
    	local funcs = {}
    
    	function funcs._(feature)
    		if feature_table[feature] then
    			return feature
    		end
    	end
    
    	local nodefault = {}
    	local packages = {}
    	function funcs.feature(match, options)
    		if not match then
    			return
    		end
    
    		if options.nodefault then
    			nodefault[match] = true
    		end
    		for _, package in ipairs(options.packages or {}) do
    			packages[package] = true
    		end
    	end
    
    	-- Evaluate the feature definition file
    	local f = loadfile(file)
    	setfenv(f, funcs)
    	f()
    
    	-- Handle default packages
    	for _, feature in ipairs(features) do
    		if not nodefault[feature] then
    			packages['gluon-' .. feature] = true
    		end
    	end
    
    	return collect_keys(packages)
    end
    
    return M