From 8a422ac0cb2e028be8ebc5b2248a10cbeb0ed94f Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Wed, 9 Jun 2021 21:11:09 +0200
Subject: [PATCH] treewide: use lua-jsonc instead of lua-cjson for JSON
 handling during build

---
 package/gluon-site/Makefile |  4 ++--
 scripts/check_site.lua      | 14 +++-----------
 scripts/domain_aliases.lua  | 11 ++---------
 3 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/package/gluon-site/Makefile b/package/gluon-site/Makefile
index df299c40c..9b01ec4d1 100644
--- a/package/gluon-site/Makefile
+++ b/package/gluon-site/Makefile
@@ -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_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)
 
@@ -38,7 +38,7 @@ endef
 
 define GenerateJSON
 	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'
 endef
 
diff --git a/scripts/check_site.lua b/scripts/check_site.lua
index dd33bf52e..43765f809 100644
--- a/scripts/check_site.lua
+++ b/scripts/check_site.lua
@@ -1,4 +1,4 @@
-local cjson = require 'cjson'
+local json = require 'jsonc'
 
 local function config_error(src, ...)
 	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 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 domains = {}
 	local dirs = io.popen("find \"$IPKG_INSTROOT\"/lib/gluon/domains/ -name '*.json'")
 	for filename in dirs:lines() do
 		local name = string.match(filename, '([^/]+).json$')
-		domains[name] = load_json(filename)
+		domains[name] = assert(json.load(filename))
 	end
 	dirs:close()
 
@@ -391,7 +383,7 @@ end
 
 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()
 	if has_domains then
diff --git a/scripts/domain_aliases.lua b/scripts/domain_aliases.lua
index ea7fbf3a3..0195d211e 100644
--- a/scripts/domain_aliases.lua
+++ b/scripts/domain_aliases.lua
@@ -1,13 +1,6 @@
-local cjson = require 'cjson'
+local json = require 'jsonc'
 
-local function load_json(filename)
-	local f = assert(io.open(filename))
-	local json = cjson.decode(f:read('*a'))
-	f:close()
-	return json
-end
-
-local domain = load_json(arg[1])
+local domain = assert(json.load(arg[1]))
 for k, _ in pairs(domain.domain_names) do
 	print(k)
 end
-- 
GitLab