Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • firmware/gluon
  • 0x4A6F/gluon
  • patrick/gluon
3 results
Select Git revision
Show changes
Showing
with 831 additions and 350 deletions
#!/usr/bin/env bash
set -e
[ "$GLUON_IMAGEDIR" -a "$GLUON_RELEASE" -a "$GLUON_SITEDIR" ] || exit 1
default_sysupgrade_ext='.bin'
output=
aliases=
manifest_aliases=
sysupgrade_ext=
SITE_CODE="$(scripts/site.sh site_code)"
get_filename() {
local name="$1"
echo -n "gluon-${SITE_CODE}-${GLUON_RELEASE}-${name}-sysupgrade${sysupgrade_ext}"
}
get_filepath() {
local filename="$1"
echo -n "${GLUON_IMAGEDIR}/sysupgrade/${filename}"
}
generate_line() {
local model="$1"
local filename="$2"
local filesize="$3"
local filepath="$(get_filepath "$filename")"
[ -e "$filepath" ] || return 0
local file256sum="$(scripts/sha256sum.sh "$filepath")"
local file512sum="$(scripts/sha512sum.sh "$filepath")"
echo "$model $GLUON_RELEASE $file256sum $filesize $filename"
echo "$model $GLUON_RELEASE $file256sum $filename"
echo "$model $GLUON_RELEASE $file512sum $filename"
}
generate() {
[ "${output}" ] || return 0
[ "$sysupgrade_ext" ] || return 0
local filename="$(get_filename "$output")"
local filepath="$(get_filepath "$filename")"
[ -e "$filepath" ] || return 0
local filesize="$(scripts/filesize.sh "$filepath")"
generate_line "$output" "$filename" "$filesize"
for alias in $aliases; do
generate_line "$alias" "$(get_filename "$alias")" "$filesize"
done
for alias in $manifest_aliases; do
generate_line "$alias" "$filename" "$filesize"
done
}
. scripts/common.inc.sh
device() {
generate
output="$1"
aliases=
manifest_aliases=
sysupgrade_ext="$default_sysupgrade_ext"
}
sysupgrade_image() {
generate
output="$1"
aliases=
manifest_aliases=
if [ "$3" ]; then
sysupgrade_ext="$3"
else
sysupgrade_ext="$2"
fi
}
alias() {
aliases="$aliases $1"
}
manifest_alias() {
manifest_aliases="$manifest_aliases $1"
}
sysupgrade() {
if [ "$2" ]; then
sysupgrade_ext="$2"
else
sysupgrade_ext="$1"
fi
if [ -z "$output" ]; then
default_sysupgrade_ext="$sysupgrade_ext"
fi
}
. targets/"$1"; generate
#!/bin/sh
if [ $# -ne 1 ]; then
echo >&2 "Usage: getversion.sh <directory>"
exit 1
fi
cd "$1" || exit 1
cat .scmversion 2>/dev/null && exit 0
git --git-dir=.git describe --tags --always --abbrev=7 --dirty=+ 2>/dev/null && exit 0
echo unknown
local M = {
customization_file = nil,
}
local function evaluate_device(env, dev)
local selections = {
features = {},
packages = {},
}
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
table.insert(selections[element_type], element)
end
end
local function add_override(ovr_key, ovr_value)
device_overrides[ovr_key] = ovr_value
end
function funcs.features(features)
add_elements('features', features)
end
function funcs.packages(packages)
add_elements('packages', packages)
end
function funcs.broken(broken)
assert(
type(broken) == 'boolean',
'Incorrect use of broken(): has to be a boolean value')
add_override('broken', broken)
end
function funcs.disable()
add_override('disabled', true)
end
function funcs.disable_factory()
add_override('disable_factory', true)
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
setfenv(M.customization_file, funcs)
M.customization_file()
return {
selections = selections,
device_overrides = device_overrides,
}
end
function M.get_selections(dev)
local eval_result = evaluate_device(M.env, dev)
return eval_result.selections
end
function M.device_overrides(dev)
local eval_result = evaluate_device(M.env, dev)
return eval_result.device_overrides
end
function M.init(env)
local filename = env.GLUON_SITEDIR .. '/image-customization.lua'
M.env = env
M.customization_file = assert(loadfile(filename))
end
return M
#!/bin/sh
set -e
editorconfig-checker .github contrib docs package scripts targets tests ./*.* .luacheckrc .editorconfig
#!/bin/sh
set -e
luacheck package scripts targets
#!/bin/sh
set -e
is_scriptfile() {
echo "$1" | grep -q '\.sh$' || head -n1 "$1" | grep -qE '^#!(.*\<bash|/bin/sh)$'
}
is_initscript() {
head -n1 "$1" | grep -qxF '#!/bin/sh /etc/rc.common'
}
find contrib -type f | while read -r file; do
is_scriptfile "$file" || continue
echo "Checking $file"
shellcheck -f gcc "$file"
done
find package -type f | while read -r file; do
if is_scriptfile "$file"; then
echo "Checking $file"
shellcheck -f gcc -x -s sh -e SC2039,SC3043,SC3037,SC3057 "$file"
elif is_initscript "$file"; then
echo "Checking $file (initscript)"
shellcheck -f gcc -x -s sh -e SC2034,SC2039,SC3043,SC3037,SC3057 "$file"
fi
done
find scripts -type f | while read -r file; do
is_scriptfile "$file" || continue
echo "Checking $file"
shellcheck -f gcc -x "$file"
done
#!/usr/bin/env bash
set -e
. scripts/modules.sh
GLUONDIR="$(pwd)"
if [ ! -d "$GLUONDIR/openwrt" ]; then
echo "You don't seem to have obtained the external repositories needed by Gluon; please call \`make update\` first!"
exit 1
fi
need_sync=false
for module in $GLUON_MODULES; do
echo "Checking module '$module'"
var=${module//\//_}
_remote_commit=${var^^}_COMMIT
commit_expected=${!_remote_commit}
prefix=invalid
cd "$GLUONDIR/$module" 2>/dev/null && prefix="$(git rev-parse --show-prefix 2>/dev/null)"
if [ "$prefix" ]; then
echo "*** No Git repository found at '$module'."
need_sync=true
continue
fi
commit_actual="$(git rev-parse heads/base 2>/dev/null)"
if [ -z "$commit_actual" ]; then
echo "*** No base branch found at '$module'."
need_sync=true
continue
fi
if [ "$commit_expected" != "$commit_actual" ]; then
echo "*** base branch at '$module' did not match module file (expected: ${commit_expected}, actual: ${commit_actual})"
need_sync=true
continue
fi
# Use git status instead of git diff -q, as the latter doesn't
# check for untracked files
if [ "$(git status --porcelain 2>/dev/null | wc -l)" -ne 0 ]; then
echo "*** Module '$module' has uncommitted changes:"
git status --short
fi
done
if $need_sync; then
echo
# shellcheck disable=SC2016
echo 'Run `make update` to sync dependencies.'
echo
fi
#!/bin/sh
# shellcheck source=./modules
. ./modules . ./modules
[ ! -f "$GLUON_SITEDIR"/modules ] || . "$GLUON_SITEDIR"/modules [ ! -f "$GLUON_SITEDIR"/modules ] || . "$GLUON_SITEDIR"/modules
FEEDS="$(echo $GLUON_FEEDS $GLUON_SITE_FEEDS | tr ' ' '\n')" # shellcheck disable=SC2086
FEEDS="$(echo $GLUON_SITE_FEEDS $GLUON_FEEDS | tr ' ' '\n')"
GLUON_MODULES=openwrt GLUON_MODULES=openwrt
......
#!/bin/bash #!/usr/bin/env bash
# shellcheck enable=check-unassigned-uppercase
set -e set -e
shopt -s nullglob shopt -s nullglob
[ "$GLUON_TMPDIR" ] && [ "$GLUON_PATCHESDIR" ] || exit 1
. scripts/modules.sh . scripts/modules.sh
...@@ -19,7 +22,7 @@ for module in $GLUON_MODULES; do ...@@ -19,7 +22,7 @@ for module in $GLUON_MODULES; do
git clone -s -b base --single-branch "$GLUONDIR/$module" "$PATCHDIR" 2>/dev/null git clone -s -b base --single-branch "$GLUONDIR/$module" "$PATCHDIR" 2>/dev/null
cd "$PATCHDIR" cd "$PATCHDIR"
for patch in "$GLUONDIR/patches/$module"/*.patch; do for patch in "${GLUON_PATCHESDIR}/$module"/*.patch; do
git -c user.name='Gluon Patch Manager' -c user.email='gluon@void.example.com' -c commit.gpgsign=false am --whitespace=nowarn --committer-date-is-author-date "$patch" git -c user.name='Gluon Patch Manager' -c user.email='gluon@void.example.com' -c commit.gpgsign=false am --whitespace=nowarn --committer-date-is-author-date "$patch"
done done
......
#!/bin/sh #!/bin/sh
check_command() { check_command() {
which "$1" >/dev/null 2>&1 command -v "$1" >/dev/null 2>&1
} }
if check_command sha256sum; then if check_command sha256sum; then
...@@ -15,6 +15,7 @@ else ...@@ -15,6 +15,7 @@ else
exit 1 exit 1
fi fi
# shellcheck disable=SC2181
[ "$?" -eq 0 ] || exit 1 [ "$?" -eq 0 ] || exit 1
echo "$ret" | awk '{ print $1 }' echo "$ret" | awk '{ print $1 }'
#!/bin/sh
check_command() {
which "$1" >/dev/null 2>&1
}
if check_command sha512sum; then
ret="$(sha512sum "$@")"
elif check_command shasum; then
ret="$(shasum -a 512 "$@")"
elif check_command cksum; then
ret="$(cksum -q -a sha512 "$@")"
else
echo "$0: no suitable sha512sum implementation was found" >&2
exit 1
fi
[ "$?" -eq 0 ] || exit 1
echo "$ret" | awk '{ print $1 }'
#!/bin/sh
export GLUON_SITE_CONFIG=site.conf
exec openwrt/staging_dir/hostpkg/bin/lua -e "print(assert(dofile('scripts/site_config.lua').$1))" 2>/dev/null
local site = os.getenv('GLUON_SITEDIR') .. '/' local site = os.getenv('GLUON_SITEDIR') .. '/'
local config = os.getenv('GLUON_SITE_CONFIG')
return function(config)
local function loader() local function loader()
coroutine.yield('return ') coroutine.yield('return ')
coroutine.yield(io.open(site..config):read('*a')) coroutine.yield(io.open(site..config):read('*a'))
...@@ -8,3 +8,4 @@ end ...@@ -8,3 +8,4 @@ end
-- setfenv doesn't work with Lua 5.2 anymore, but we're using 5.1 -- setfenv doesn't work with Lua 5.2 anymore, but we're using 5.1
return setfenv(assert(load(coroutine.wrap(loader), config)), {})() return setfenv(assert(load(coroutine.wrap(loader), config)), {})()
end
site_packages() {
MAKEFLAGS= make print PROFILE="$1" --no-print-directory -s -f - <<'END_MAKE'
include $(GLUON_SITEDIR)/site.mk
print:
echo '$(GLUON_$(PROFILE)_SITE_PACKAGES)'
END_MAKE
}
. scripts/common.inc.sh
no_opkg() {
config '# CONFIG_SIGNED_PACKAGES is not set'
config 'CONFIG_CLEAN_IPKG=y'
packages '-opkg'
}
local lib = dofile('scripts/target_config_lib.lua')
for _, config in pairs(lib.configs) do
io.stdout:write(config:format(), '\n')
end
#!/usr/bin/env bash
set -e
[ "$OPENWRT_TARGET" ] || exit 1
target="$1"
packages=$2
output=
profile=
default_packages=
profile_packages=
OPENWRT_CONFIG_TARGET="${OPENWRT_TARGET//-/_}"
emit() {
[ "${output}" ] || return 0
want_device "${output}" || return 0
profile_packages="${profile_packages} $(site_packages "$output")"
for package in $profile_packages; do
[ "${package:0:1}" = '-' ] || echo "CONFIG_PACKAGE_${package}=m"
done
echo "CONFIG_TARGET_DEVICE_${OPENWRT_CONFIG_TARGET}_DEVICE_${profile}=y"
echo "CONFIG_TARGET_DEVICE_PACKAGES_${OPENWRT_CONFIG_TARGET}_DEVICE_${profile}=\"${profile_packages}\""
}
. scripts/target_config.inc.sh
config() {
echo "$1"
}
try_config() {
echo "$1"
}
device() {
emit
output="$1"
profile="$3"
if [ -z "$profile" ]; then
profile="$2"
fi
profile_packages="${default_packages}"
}
packages() {
if [ "${output}" ]; then
profile_packages="${profile_packages} $@"
else
default_packages="${default_packages} $@"
for package in "$@"; do
if [ "${package:0:1}" = '-' ]; then
echo "# CONFIG_PACKAGE_${package:1} is not set"
else
echo "CONFIG_PACKAGE_${package}=y"
fi
done
fi
}
# The sort will not only remove duplicate entries,
# but also magically make =y entries override =m ones
(
. targets/generic
packages $packages
. targets/"$target"
emit
) | sort -u
local errors = false
local function fail(msg)
if not errors then
errors = true
io.stderr:write('Configuration failed:', '\n')
end
io.stderr:write(' * ', msg, '\n')
end
local function match_config(expected, actual)
if expected == actual then
return true
end
if expected:gsub('=m$', '=y') == actual then
return true
end
return false
end
local function check_config(config)
for line in io.lines('openwrt/.config') do
if match_config(config, line) then
return true
end
end
return false
end
local lib = dofile('scripts/target_config_lib.lua')
for _, config in pairs(lib.configs) do
if config.required then
if not check_config(config:format()) then
fail(config.required)
end
end
end
if errors then
os.exit(1)
end
#!/usr/bin/env bash
set -e
[ "$OPENWRT_TARGET" ] || exit 1
target="$1"
packages=$2
output=
ret=0
OPENWRT_CONFIG_TARGET="${OPENWRT_TARGET//-/_}"
fail() {
local message="$1"
if [ $ret -eq 0 ]; then
ret=1
echo "Configuration failed:" >&2
fi
echo " * $message" >&2
}
check_config() {
grep -q "$1" openwrt/.config
}
check_package() {
local package="$1"
local value="$2"
if ! check_config "^CONFIG_PACKAGE_${package}=${value}"; then
fail "unable to enable package '${package}'"
fi
}
. scripts/target_config.inc.sh
config() {
local config="$1"
if ! check_config "^${config}\$"; then
fail "unable to set '${config}'"
fi
}
device() {
output="$1"
want_device "${output}" || return 0
local profile="$3"
if [ -z "$profile" ]; then
profile="$2"
fi
if ! check_config "CONFIG_TARGET_DEVICE_${OPENWRT_CONFIG_TARGET}_DEVICE_${profile}=y"; then
fail "unable to enable device '${profile}'"
fi
for package in $(site_packages "$output"); do
[ "${package:0:1}" = '-' ] || check_package "$package"
done
}
factory_image() {
output="$1"
want_device "${output}" || return 0
}
sysupgrade_image() {
output="$1"
want_device "${output}" || return 0
}
packages() {
if [ "${output}" ]; then
want_device "${output}" || return 0
for package in "$@"; do
[ "${package:0:1}" = '-' ] || check_package "$package"
done
else
for package in "$@"; do
[ "${package:0:1}" = '-' ] || check_package "$package" 'y'
done
fi
}
. targets/generic
packages $packages
. targets/"$target"
check_devices
exit $ret
local lib = dofile('scripts/target_lib.lua')
local feature_lib = dofile('scripts/feature_lib.lua')
local image_customization_lib = dofile('scripts/image_customization_lib.lua')
local env = lib.env
local target = env.GLUON_TARGET
assert(target)
assert(env.BOARD)
assert(env.SUBTARGET)
local openwrt_config_target
if env.SUBTARGET ~= '' then
openwrt_config_target = env.BOARD .. '_' .. env.SUBTARGET
else
openwrt_config_target = env.BOARD
end
-- Initialize image-customization
image_customization_lib.init(env)
-- Split a string into words
local function split(s)
local ret = {}
for w in string.gmatch(s, '%S+') do
table.insert(ret, w)
end
return ret
end
local feeds = split(lib.exec_capture_raw('. scripts/modules.sh; echo "$FEEDS"'))
-- Strip leading '-' character
local function strip_neg(s)
if string.sub(s, 1, 1) == '-' then
return string.sub(s, 2)
else
return s
end
end
-- Add an element to a list, removing duplicate entries and handling negative
-- elements prefixed with a '-'
local function append_to_list(list, item, keep_neg)
local match = strip_neg(item)
local ret = {}
for _, el in ipairs(list) do
if strip_neg(el) ~= match then
table.insert(ret, el)
end
end
if keep_neg ~= false or string.sub(item, 1, 1) ~= '-' then
table.insert(ret, item)
end
return ret
end
local function concat_list(a, b, keep_neg)
local ret = a
for _, el in ipairs(b) do
ret = append_to_list(ret, el, keep_neg)
end
return ret
end
local function compact_list(list, keep_neg)
return concat_list({}, list, keep_neg)
end
local function file_exists(file)
local f = io.open(file)
if not f then
return false
end
f:close()
return true
end
local function feature_packages(features)
local files = {'package/features'}
for _, feed in ipairs(feeds) do
local path = string.format('packages/%s/features', feed)
if file_exists(path) then
table.insert(files, path)
end
end
return feature_lib.get_packages(files, features)
end
local function site_specific_packages(dev_info)
local site_selections
local site_packages
local feature_inherited_pkgs
local site_features
-- Get all enabled selections from image-customization.lua
site_selections = image_customization_lib.get_selections(dev_info)
-- First read enabled features from site
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 = site_selections['packages']
-- Concat feature-packages with site-packages
local pkgs = concat_list(feature_inherited_pkgs, site_packages)
-- Negations for the resulting package-list are dealt with in the calling function
return pkgs
end
local enabled_packages = {}
-- Arguments: package name and config value (true: y, nil: m, false: unset)
-- Ensures precedence of y > m > unset
local function config_package(pkg, v)
-- HACK: Handle virtual default packages
local subst = {
nftables = 'nftables-nojson'
}
if subst[pkg] then
pkg = subst[pkg]
end
if v == false then
if not enabled_packages[pkg] then
lib.try_config('PACKAGE_' .. pkg, false)
end
return
end
if v == true or not enabled_packages[pkg] then
lib.config('PACKAGE_' .. pkg, v, string.format("unable to enable package '%s'", pkg))
enabled_packages[pkg] = true
end
end
local function handle_target_pkgs(pkgs)
for _, pkg in ipairs(pkgs) do
if string.sub(pkg, 1, 1) == '-' then
config_package(string.sub(pkg, 2), false)
else
config_package(pkg, true)
end
end
end
local function get_default_pkgs()
local targetinfo_target = string.gsub(openwrt_config_target, '_', '/', 1)
local target_matches = false
for line in io.lines('openwrt/tmp/.targetinfo') do
local target_match = string.match(line, '^Target: (.+)$')
if target_match then
target_matches = (target_match == targetinfo_target)
end
local default_packages_match = string.match(line, '^Default%-Packages: (.+)$')
if target_matches and default_packages_match then
return split(default_packages_match)
end
end
io.stderr:write('Error: unable to get default packages for OpenWrt target ', targetinfo_target, '\n')
os.exit(1)
end
lib.include('generic')
lib.include(target)
lib.check_devices()
handle_target_pkgs(concat_list(get_default_pkgs(), lib.target_packages))
for _, dev in ipairs(lib.devices) do
local device_pkgs = {}
local function handle_pkgs(pkgs)
for _, pkg in ipairs(pkgs) do
if string.sub(pkg, 1, 1) ~= '-' then
config_package(pkg, nil)
end
device_pkgs = append_to_list(device_pkgs, pkg)
end
end
handle_pkgs(lib.target_packages)
handle_pkgs(dev.options.packages or {})
handle_pkgs(site_specific_packages(dev))
local profile_config = string.format('%s_DEVICE_%s', openwrt_config_target, dev.name)
lib.config(
'TARGET_DEVICE_' .. profile_config, true,
string.format("unable to enable device '%s'", dev.name)
)
lib.config(
'TARGET_DEVICE_PACKAGES_' .. profile_config,
table.concat(device_pkgs, ' ')
)
end
return lib
local image_customization_lib = dofile('scripts/image_customization_lib.lua')
-- Functions for use in targets/*
local F = {}
-- To be accessed by scripts using target_lib
local M = setmetatable({}, { __index = F })
local funcs = setmetatable({}, {
__index = function(_, k)
return F[k] or _G[k]
end,
})
local env = setmetatable({}, {
__index = function(_, k) return os.getenv(k) end
})
F.env = env
assert(env.GLUON_SITEDIR)
assert(env.GLUON_TARGETSDIR)
assert(env.GLUON_RELEASE)
assert(env.GLUON_DEPRECATED)
M.site_code = assert(
dofile('scripts/site_config.lua')('site.conf').site_code, 'site_code missing in site.conf'
)
M.target_packages = {}
M.configs = {}
M.devices = {}
M.images = {}
-- Initialize image-customization
image_customization_lib.init(env)
local default_options = {
factory = '-squashfs-factory',
factory_ext = '.bin',
sysupgrade = '-squashfs-sysupgrade',
sysupgrade_ext = '.bin',
extra_images = {},
aliases = {},
manifest_aliases = {},
packages = {},
class = 'standard',
deprecated = false,
broken = false,
}
local gluon_devices, unknown_devices = {}, {}
for dev in string.gmatch(env.GLUON_DEVICES or '', '%S+') do
gluon_devices[dev] = true
unknown_devices[dev] = true
end
function F.istrue(v)
return (tonumber(v) or 0) > 0
end
local function device_broken(device_info, overrides)
if F.istrue(env.BROKEN) then
return false
end
if overrides['broken'] ~= nil then
return overrides['broken'] == true
elseif device_info.options.broken then
return true
end
return false
end
local function want_device(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
return false
end
if device_broken(device_info, overrides) then
return false
end
if device_info.options.deprecated and env.GLUON_DEPRECATED == '0' then
return false
end
if (env.GLUON_DEVICES or '') == '' then
return true
end
unknown_devices[device_info.image] = nil
return gluon_devices[device_info.image]
end
local function merge(a, b)
local ret = {}
for k, v in pairs(a) do
ret[k] = v
end
for k, v in pairs(b or {}) do
assert(ret[k] ~= nil, string.format("unknown option '%s'", k))
ret[k] = v
end
return ret
end
-- Escapes a single argument to be used in a shell command
-- The argument is surrounded by single quotes, single quotes inside the
-- argument are replaced by '\''.
-- To allow using shell wildcards, zero bytes in the arguments are replaced
-- by unquoted asterisks.
function F.escape(s)
s = string.gsub(s, "'", "'\\''")
s = string.gsub(s, "%z", "'*'")
return "'" .. s .. "'"
end
local function escape_command(command, raw)
local ret = ''
if not raw then
ret = 'exec'
end
for _, arg in ipairs(command) do
ret = ret .. ' ' .. F.escape(arg)
end
if raw then
ret = ret .. ' ' .. raw
end
return ret
end
function F.exec_raw(command, may_fail)
local ret = os.execute(command)
assert((ret == 0) or may_fail)
return ret
end
function F.exec(command, may_fail, raw)
return F.exec_raw(escape_command(command, raw), may_fail)
end
function F.exec_capture_raw(command)
local f = io.popen(command)
assert(f)
local data = f:read('*a')
f:close()
return data
end
function F.exec_capture(command, raw)
return F.exec_capture_raw(escape_command(command, raw))
end
local image_mt = {
__index = {
dest_name = function(image, name, site, release)
return env.GLUON_IMAGEDIR..'/'..image.subdir,
'gluon-'..(site or M.site_code)..'-'..(release or env.GLUON_RELEASE)..'-'..name..image.out_suffix..image.extension
end,
},
}
local function add_image(image)
local device = image.image
M.images[device] = M.images[device] or {}
table.insert(M.images[device], setmetatable(image, image_mt))
end
local function format_config(k, v)
local format
if type(v) == 'string' then
format = '%s=%q'
elseif v == true then
format = '%s=y'
elseif v == nil then
format = '%s=m'
elseif v == false then
format = '# %s is not set'
else
format = '%s=%d'
end
return string.format(format, 'CONFIG_' .. k, v)
end
local config_mt = {
__index = {
format = function(config)
return format_config(config.key, config.value)
end,
}
}
local function do_config(k, v, required)
M.configs[k] = setmetatable({
key = k,
value = v,
required = required,
}, config_mt)
end
function F.try_config(k, v)
do_config(k, v)
end
function F.config(k, v, message)
if not message then
message = string.format("unable to set '%s'", format_config(k, v))
end
do_config(k, v, message)
end
function F.packages(pkgs)
for _, pkg in ipairs(pkgs) do
table.insert(M.target_packages, pkg)
end
end
M.packages = F.packages
local function as_table(v)
if type(v) == 'table' then
return v
else
return {v}
end
end
local function disable_factory_image(device_info)
if device_info.options.deprecated and env.GLUON_DEPRECATED ~= 'full' then
return true
end
local overrides = image_customization_lib.device_overrides(device_info)
if overrides["disable_factory"] then
return true
end
return false
end
function F.device(image, name, options)
options = merge(default_options, options)
local device_info = {
image = image,
name = name,
options = options,
}
if not want_device(device_info) then
return
end
table.insert(M.devices, device_info)
if options.sysupgrade then
add_image {
image = image,
name = name,
subdir = 'sysupgrade',
in_suffix = options.sysupgrade,
out_suffix = '-sysupgrade',
extension = options.sysupgrade_ext,
aliases = options.aliases,
manifest_aliases = options.manifest_aliases,
}
end
if disable_factory_image(device_info) then
return
end
if options.factory then
for _, ext in ipairs(as_table(options.factory_ext)) do
add_image {
image = image,
name = name,
subdir = 'factory',
in_suffix = options.factory,
out_suffix = '',
extension = ext,
aliases = options.aliases,
}
end
end
for _, extra_image in ipairs(options.extra_images) do
add_image {
image = image,
name = name,
subdir = 'other',
in_suffix = extra_image[1],
out_suffix = extra_image[2],
extension = extra_image[3],
aliases = options.aliases,
}
end
end
function F.defaults(options)
default_options = merge(default_options, options)
end
function F.include(name)
local f = assert(loadfile(env.GLUON_TARGETSDIR .. '/' .. name))
setfenv(f, funcs)
return f()
end
function M.check_devices()
local device_list = {}
for device in pairs(unknown_devices) do
table.insert(device_list, device)
end
if #device_list ~= 0 then
table.sort(device_list)
io.stderr:write('Error: unknown devices given: ', table.concat(device_list, ' '), '\n')
os.exit(1)
end
end
return M