From 94a82666846d62cdff7d78f78d428df35412e50d Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Mon, 22 Jun 2020 03:14:43 +0000 Subject: [PATCH] flua: add ucl library libucl comes with a Lua library binding. Build it into flua. This lets us parse/generate config files in the various formats supported by libucl with flua. For example, the following script will detect the format of an object written to stdin as one of UCL config, JSON, or YAML and write it to stdout as pretty-printed JSON: local ucl = require('ucl') local parser = ucl.parser() parser:parse_string(io.read('*a')) local obj = parser:get_object() print(ucl.to_format(obj, 'json')) Reviewed by: kevans, pstef Approved by: mmacy (mentor) Relnotes: yes Differential Revision: https://reviews.freebsd.org/D25009 --- Makefile.inc1 | 4 ++-- libexec/flua/Makefile | 6 ++++++ libexec/flua/linit_flua.c | 2 ++ tools/build/Makefile | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile.inc1 b/Makefile.inc1 index 5197a53f24d9..7a1c24585b8e 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -2112,8 +2112,8 @@ ${_bt}-lib/libdwarf: ${_bt_m4_depend} # 13.0-CURRENT cycle, thus needs to be built on -older releases and stable # branches. .if ${BOOTSTRAPPING} < 1300059 -${_bt}-libexec/flua: ${_bt}-lib/liblua -_flua= lib/liblua libexec/flua +${_bt}-libexec/flua: ${_bt}-lib/liblua ${_bt}-lib/libucl +_flua= lib/liblua lib/libucl libexec/flua .endif # r245440 mtree -N support added diff --git a/libexec/flua/Makefile b/libexec/flua/Makefile index 4b5c4ee55416..a4dc916e7834 100644 --- a/libexec/flua/Makefile +++ b/libexec/flua/Makefile @@ -32,4 +32,10 @@ CFLAGS+= -I${SRCTOP}/lib/libedit -I${SRCTOP}/contrib/libedit LIBADD+= edit .endif +UCLSRC?= ${SRCTOP}/contrib/libucl +.PATH: ${UCLSRC}/lua +SRCS+= lua_ucl.c +CFLAGS+= -I${UCLSRC}/include -I${UCLSRC}/src -I${UCLSRC}/uthash +LIBADD+= ucl + .include diff --git a/libexec/flua/linit_flua.c b/libexec/flua/linit_flua.c index 99818c3b4db7..b62084b66ffa 100644 --- a/libexec/flua/linit_flua.c +++ b/libexec/flua/linit_flua.c @@ -36,6 +36,7 @@ #include "lauxlib.h" #include "lfs.h" #include "lposix.h" +#include "lua_ucl.h" /* ** these libs are loaded by lua.c and are readily available to any Lua @@ -59,6 +60,7 @@ static const luaL_Reg loadedlibs[] = { {"lfs", luaopen_lfs}, {"posix.sys.stat", luaopen_posix_sys_stat}, {"posix.unistd", luaopen_posix_unistd}, + {"ucl", luaopen_ucl}, {NULL, NULL} }; diff --git a/tools/build/Makefile b/tools/build/Makefile index 427171cd11c9..f6c4e4a89247 100644 --- a/tools/build/Makefile +++ b/tools/build/Makefile @@ -149,6 +149,7 @@ INSTALLDIR_LIST= \ lib/casper \ lib/geom \ usr/include/casper \ + usr/include/private/ucl \ usr/include/private/zstd \ usr/lib \ usr/libexec