Merge pull request #2234 from freifunk-gluon/lua-jsonc-host

treewide: use lua-jsonc instead of lua-cjson for JSON handling during build
This commit is contained in:
Matthias Schiffer 2021-06-13 09:06:32 +02:00 committed by GitHub
commit 867b18deeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 23 deletions

View File

@ -13,4 +13,4 @@ PACKAGES_ROUTING_BRANCH=openwrt-19.07
PACKAGES_ROUTING_COMMIT=101632e153b41238bc19dfd96ba2d23339dbcb76 PACKAGES_ROUTING_COMMIT=101632e153b41238bc19dfd96ba2d23339dbcb76
PACKAGES_GLUON_REPO=https://github.com/freifunk-gluon/packages.git PACKAGES_GLUON_REPO=https://github.com/freifunk-gluon/packages.git
PACKAGES_GLUON_COMMIT=8d53ff54e562ddb2ed8397781dd78edc76f6ff38 PACKAGES_GLUON_COMMIT=b644a2a8d8bf2543d12f782f59a2b2ecdc7bda97

View File

@ -8,7 +8,7 @@ PKG_VERSION:=$(if $(DUMP),x,$(GLUON_SITE_VERSION))
PKG_CONFIG_DEPENDS := CONFIG_GLUON_RELEASE CONFIG_GLUON_SITEDIR CONFIG_GLUON_MULTIDOMAIN PKG_CONFIG_DEPENDS := CONFIG_GLUON_RELEASE CONFIG_GLUON_SITEDIR CONFIG_GLUON_MULTIDOMAIN
PKG_FILE_DEPENDS := $(GLUON_SITEDIR)/site.conf $(GLUON_SITEDIR)/domains/ $(GLUON_SITEDIR)/i18n/ PKG_FILE_DEPENDS := $(GLUON_SITEDIR)/site.conf $(GLUON_SITEDIR)/domains/ $(GLUON_SITEDIR)/i18n/
PKG_BUILD_DEPENDS := lua-cjson/host gluon-web/host PKG_BUILD_DEPENDS := lua-jsonc/host gluon-web/host
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
@ -38,7 +38,7 @@ endef
define GenerateJSON define GenerateJSON
GLUON_SITEDIR='$$(GLUON_SITEDIR)' GLUON_SITE_CONFIG='$(1).conf' \ GLUON_SITEDIR='$$(GLUON_SITEDIR)' GLUON_SITE_CONFIG='$(1).conf' \
lua -e 'print(require("cjson").encode(assert(dofile("../../scripts/site_config.lua")(os.getenv("GLUON_SITE_CONFIG")))))' \ lua -e 'print(require("jsonc").stringify(assert(dofile("../../scripts/site_config.lua")(os.getenv("GLUON_SITE_CONFIG")))))' \
> '$$(PKG_BUILD_DIR)/$(1).json' > '$$(PKG_BUILD_DIR)/$(1).json'
endef endef

View File

@ -1,4 +1,4 @@
local cjson = require 'cjson' local json = require 'jsonc'
local function config_error(src, ...) local function config_error(src, ...)
error(src .. ' error: ' .. string.format(...), 0) error(src .. ' error: ' .. string.format(...), 0)
@ -7,20 +7,12 @@ end
local has_domains = (os.execute('ls -d "$IPKG_INSTROOT"/lib/gluon/domains/ >/dev/null 2>&1') == 0) local has_domains = (os.execute('ls -d "$IPKG_INSTROOT"/lib/gluon/domains/ >/dev/null 2>&1') == 0)
local function load_json(filename)
local f = assert(io.open(filename))
local json = cjson.decode(f:read('*a'))
f:close()
return json
end
local function get_domains() local function get_domains()
local domains = {} local domains = {}
local dirs = io.popen("find \"$IPKG_INSTROOT\"/lib/gluon/domains/ -name '*.json'") local dirs = io.popen("find \"$IPKG_INSTROOT\"/lib/gluon/domains/ -name '*.json'")
for filename in dirs:lines() do for filename in dirs:lines() do
local name = string.match(filename, '([^/]+).json$') local name = string.match(filename, '([^/]+).json$')
domains[name] = load_json(filename) domains[name] = assert(json.load(filename))
end end
dirs:close() dirs:close()
@ -391,7 +383,7 @@ end
local check = setfenv(assert(loadfile()), M) local check = setfenv(assert(loadfile()), M)
site = load_json(os.getenv('IPKG_INSTROOT') .. '/lib/gluon/site.json') site = assert(json.load(os.getenv('IPKG_INSTROOT') .. '/lib/gluon/site.json'))
local ok, err = pcall(function() local ok, err = pcall(function()
if has_domains then if has_domains then

View File

@ -1,13 +1,6 @@
local cjson = require 'cjson' local json = require 'jsonc'
local function load_json(filename) local domain = assert(json.load(arg[1]))
local f = assert(io.open(filename))
local json = cjson.decode(f:read('*a'))
f:close()
return json
end
local domain = load_json(arg[1])
for k, _ in pairs(domain.domain_names) do for k, _ in pairs(domain.domain_names) do
print(k) print(k)
end end