From 97471a1bb76b8f974e5e55ea18075d605382cdbd Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 30 Dec 2015 01:02:59 +0100 Subject: [PATCH 1/2] lua-cjson: add host build support --- ...stallation-of-headers-for-host-build.patch | 16 ++++++++++ ...003-lua-cjson-add-host-build-support.patch | 32 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 patches/openwrt/0046-lua-fix-installation-of-headers-for-host-build.patch create mode 100644 patches/packages/openwrt/0003-lua-cjson-add-host-build-support.patch diff --git a/patches/openwrt/0046-lua-fix-installation-of-headers-for-host-build.patch b/patches/openwrt/0046-lua-fix-installation-of-headers-for-host-build.patch new file mode 100644 index 00000000..ab49ad65 --- /dev/null +++ b/patches/openwrt/0046-lua-fix-installation-of-headers-for-host-build.patch @@ -0,0 +1,16 @@ +From: Matthias Schiffer +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 diff --git a/patches/packages/openwrt/0003-lua-cjson-add-host-build-support.patch b/patches/packages/openwrt/0003-lua-cjson-add-host-build-support.patch new file mode 100644 index 00000000..9c1f7744 --- /dev/null +++ b/patches/packages/openwrt/0003-lua-cjson-add-host-build-support.patch @@ -0,0 +1,32 @@ +From: Matthias Schiffer +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)) From f23e02478718cd2f1b17719fdf83c4b85113149c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 30 Dec 2015 03:35:17 +0100 Subject: [PATCH 2/2] Convert site.conf to JSON during build This will allow us to use its content from other languages than Lua as well. --- Makefile | 2 +- package/gluon-core/Makefile | 2 +- .../files/usr/lib/lua/gluon/site_config.lua | 22 ++++++++++++------- package/gluon-site/Makefile | 4 ++-- scripts/check_site.sh | 2 +- scripts/site.sh | 2 +- scripts/site_config.lua | 9 ++++++++ 7 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 scripts/site_config.lua diff --git a/Makefile b/Makefile index bb61eb92..a1b69459 100644 --- a/Makefile +++ b/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) diff --git a/package/gluon-core/Makefile b/package/gluon-core/Makefile index ddf67dcd..ecd6fbe3 100644 --- a/package/gluon-core/Makefile +++ b/package/gluon-core/Makefile @@ -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 diff --git a/package/gluon-core/files/usr/lib/lua/gluon/site_config.lua b/package/gluon-core/files/usr/lib/lua/gluon/site_config.lua index cf151483..6f01b066 100644 --- a/package/gluon-core/files/usr/lib/lua/gluon/site_config.lua +++ b/package/gluon-core/files/usr/lib/lua/gluon/site_config.lua @@ -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(), } ) diff --git a/package/gluon-site/Makefile b/package/gluon-site/Makefile index abd057c9..a7084ad0 100644 --- a/package/gluon-site/Makefile +++ b/package/gluon-site/Makefile @@ -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)) diff --git a/scripts/check_site.sh b/scripts/check_site.sh index e0aa43e5..0ca30316 100755 --- a/scripts/check_site.sh +++ b/scripts/check_site.sh @@ -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()" diff --git a/scripts/site.sh b/scripts/site.sh index 82016cbe..5038438a 100755 --- a/scripts/site.sh +++ b/scripts/site.sh @@ -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 diff --git a/scripts/site_config.lua b/scripts/site_config.lua new file mode 100644 index 00000000..a50f115b --- /dev/null +++ b/scripts/site_config.lua @@ -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')), {})()