Merge pull request #607 from freifunk-gluon/site.json
Convert site.conf to JSON during build
This commit is contained in:
commit
7b6f3fed70
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))
|
||||
|
@ -0,0 +1,16 @@
|
||||
From: Matthias Schiffer <mschiffer@universe-factory.net>
|
||||
Date: Tue, 29 Dec 2015 22:48:52 +0100
|
||||
Subject: lua: fix installation of headers for host build
|
||||
|
||||
diff --git a/package/utils/lua/Makefile b/package/utils/lua/Makefile
|
||||
index 72d5631..c37d99b 100644
|
||||
--- a/package/utils/lua/Makefile
|
||||
+++ b/package/utils/lua/Makefile
|
||||
@@ -140,6 +140,7 @@ define Host/Install
|
||||
$(MAKE) -C $(HOST_BUILD_DIR) \
|
||||
INSTALL_TOP="$(STAGING_DIR_HOST)" \
|
||||
install
|
||||
+ $(CP) $(HOST_BUILD_DIR)/src/lnum_config.h $(STAGING_DIR_HOST)/include/
|
||||
endef
|
||||
|
||||
define Build/InstallDev
|
@ -0,0 +1,32 @@
|
||||
From: Matthias Schiffer <mschiffer@universe-factory.net>
|
||||
Date: Wed, 30 Dec 2015 01:00:49 +0100
|
||||
Subject: lua-cjson: add host build support
|
||||
|
||||
diff --git a/lang/lua-cjson/Makefile b/lang/lua-cjson/Makefile
|
||||
index fd489f2..90c8f98 100644
|
||||
--- a/lang/lua-cjson/Makefile
|
||||
+++ b/lang/lua-cjson/Makefile
|
||||
@@ -20,6 +20,7 @@ PKG_MD5SUM:=24f270663e9f6ca8ba2a02cef19f7963
|
||||
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
|
||||
|
||||
+include $(INCLUDE_DIR)/host-build.mk
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include $(INCLUDE_DIR)/cmake.mk
|
||||
|
||||
@@ -39,6 +40,9 @@ endef
|
||||
CMAKE_OPTIONS += \
|
||||
-DUSE_LUA=ON
|
||||
|
||||
+CMAKE_HOST_OPTIONS += \
|
||||
+ -DLUA_MATH_LIBRARY=m
|
||||
+
|
||||
define Package/lua-cjson/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/cjson.so $(1)/usr/lib/lua/
|
||||
@@ -47,4 +51,5 @@ define Package/lua-cjson/install
|
||||
$(INSTALL_DATA) $(PKG_BUILD_DIR)/lua/cjson/util.lua $(1)/usr/lib/lua/cjson
|
||||
endef
|
||||
|
||||
+$(eval $(call HostBuild))
|
||||
$(eval $(call BuildPackage,lua-cjson))
|
@ -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