Convert site.conf to JSON during build
This will allow us to use its content from other languages than Lua as well.
This commit is contained in:
parent
97471a1bb7
commit
f23e024787
2
Makefile
2
Makefile
@ -338,7 +338,7 @@ prepare-image: FORCE
|
||||
+$(SUBMAKE) -C $(TOPDIR)/target/linux/$(BOARD)/image image_prepare KDIR="$(BOARD_KDIR)"
|
||||
|
||||
prepare: FORCE
|
||||
@$(STAGING_DIR_HOST)/bin/lua $(GLUONDIR)/package/gluon-core/files/usr/lib/lua/gluon/site_config.lua \
|
||||
@$(STAGING_DIR_HOST)/bin/lua $(GLUONDIR)/scripts/site_config.lua \
|
||||
|| (echo 'Your site configuration did not pass validation.'; false)
|
||||
|
||||
mkdir -p $(GLUON_IMAGEDIR) $(BOARD_BUILDDIR)
|
||||
|
@ -12,7 +12,7 @@ define Package/gluon-core
|
||||
SECTION:=gluon
|
||||
CATEGORY:=Gluon
|
||||
TITLE:=Base files of Gluon
|
||||
DEPENDS:=+gluon-site +lua-platform-info +luci-base +odhcp6c +firewall
|
||||
DEPENDS:=+gluon-site +lua-platform-info +luci-base +luci-lib-jsonc +odhcp6c +firewall
|
||||
endef
|
||||
|
||||
|
||||
|
@ -1,20 +1,26 @@
|
||||
local config = os.getenv('GLUON_SITE_CONFIG') or '/lib/gluon/site.conf'
|
||||
local function get_site_config()
|
||||
local config = '/lib/gluon/site.json'
|
||||
|
||||
local function loader()
|
||||
coroutine.yield('return ')
|
||||
coroutine.yield(io.open(config):read('*a'))
|
||||
local json = require 'luci.jsonc'
|
||||
local ltn12 = require 'luci.ltn12'
|
||||
|
||||
local file = assert(io.open(config))
|
||||
|
||||
local decoder = json.new()
|
||||
ltn12.pump.all(ltn12.source.file(io.open(config)), decoder:sink())
|
||||
|
||||
file:close()
|
||||
|
||||
return assert(decoder:get())
|
||||
end
|
||||
|
||||
-- setfenv doesn't work with Lua 5.2 anymore, but we're using 5.1
|
||||
local site_config = setfenv(assert(load(coroutine.wrap(loader), 'site.conf')), {})()
|
||||
|
||||
local setmetatable = setmetatable
|
||||
|
||||
module 'gluon.site_config'
|
||||
|
||||
setmetatable(_M,
|
||||
{
|
||||
__index = site_config,
|
||||
__index = get_site_config(),
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -5,7 +5,7 @@ PKG_VERSION:=$(if $(GLUON_SITE_CODE),$(GLUON_SITE_CODE),1)
|
||||
PKG_RELEASE:=$(GLUON_RELEASE)
|
||||
|
||||
PKG_FILE_DEPENDS := $(GLUON_SITEDIR)/site.conf $(GLUON_SITEDIR)/i18n/
|
||||
PKG_BUILD_DEPENDS := luci-base/host
|
||||
PKG_BUILD_DEPENDS := luci-base/host lua-cjson/host
|
||||
|
||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
||||
|
||||
@ -33,7 +33,7 @@ endef
|
||||
|
||||
define Package/gluon-site/install
|
||||
$(INSTALL_DIR) $(1)/lib/gluon
|
||||
$(CP) $(GLUON_SITEDIR)/site.conf $(1)/lib/gluon/site.conf
|
||||
lua -e 'print(require("cjson").encode(assert(dofile("$(GLUONDIR)/scripts/site_config.lua"))))' > $(1)/lib/gluon/site.json
|
||||
echo "$(GLUON_RELEASE)" > $(1)/lib/gluon/release
|
||||
|
||||
$(call GluonInstallI18N,gluon-site,$(1))
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
SITE_CONFIG_LUA=package/gluon-core/files/usr/lib/lua/gluon/site_config.lua
|
||||
SITE_CONFIG_LUA=scripts/site_config.lua
|
||||
CHECK_SITE_LIB=scripts/check_site_lib.lua
|
||||
|
||||
"$GLUONDIR"/openwrt/staging_dir/host/bin/lua -e "site = dofile(os.getenv('GLUONDIR') .. '/${SITE_CONFIG_LUA}'); dofile(os.getenv('GLUONDIR') .. '/${CHECK_SITE_LIB}'); dofile()"
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
SITE_CONFIG_LUA=package/gluon-core/files/usr/lib/lua/gluon/site_config.lua
|
||||
SITE_CONFIG_LUA=scripts/site_config.lua
|
||||
|
||||
"$GLUONDIR"/openwrt/staging_dir/host/bin/lua -e "print(assert(dofile(os.getenv('GLUONDIR') .. '/${SITE_CONFIG_LUA}').$1))" 2>/dev/null
|
||||
|
9
scripts/site_config.lua
Normal file
9
scripts/site_config.lua
Normal file
@ -0,0 +1,9 @@
|
||||
local config = os.getenv('GLUON_SITE_CONFIG')
|
||||
|
||||
local function loader()
|
||||
coroutine.yield('return ')
|
||||
coroutine.yield(io.open(config):read('*a'))
|
||||
end
|
||||
|
||||
-- setfenv doesn't work with Lua 5.2 anymore, but we're using 5.1
|
||||
return setfenv(assert(load(coroutine.wrap(loader), 'site.conf')), {})()
|
Loading…
Reference in New Issue
Block a user