Skip to content

Commit

Permalink
0.15.0 (#14)
Browse files Browse the repository at this point in the history
- elify is enabled by default
- Fixed some API errors 
- Added meta docs generator for VS Code lua extension
- Changed API:
   ver.compare_version -> ver.compare
   ver.parse_semver -> ver.parse
  • Loading branch information
cryi authored Apr 18, 2021
1 parent f21c3c4 commit d8c00bc
Show file tree
Hide file tree
Showing 32 changed files with 2,108 additions and 836 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ build
tools/luasrcdiet
.CACHE
lib/tests/tmp/*
!lib/tests/tmp/.gitkeep
!lib/tests/tmp/.gitkeep
.meta
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Build requirements:
Steps:
1. `git clone https://github.com/cryon-io/eli && cd eli`
2. `docker build -t elibuild .`
3. `docker run -v $(pwd):"/root/luabuild" -v "$(pwd)/toolchains:/opt/cross" -e TOOLCHAINS='x86_64-linux-musl-cross;i686-linux-musl-cross' elibuild`
3. `docker run -v $(pwd):"/root/luabuild" -v "$(pwd)/toolchains:/opt/cross" -e TOOLCHAINS='x86_64-linux-musl-cross;i686-linux-musl-cross;aarch64-linux-musl-cross' elibuild`
4. Built binaries `eli` and `elic` will be created in build directory and per `<toolchain>` subdirectories

*Note: You can choose build toolchain you like from https://musl.cc/ and set its name in TOOLCHAINS*
Expand Down
9 changes: 8 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Additional Extra docs & External docs (non essential)
[ ] extra.proc
[ ] extra.stream
[ ] extra.pipe
[ ] extra.fs - filetype
[ ] lzip - ZipArchive

# Eli
* [x] logs
* [x] support for init scripts
Expand All @@ -10,7 +17,7 @@
# Build
* [x] toolchain configurable
* [x] replace curl with libfetch (requires testing)
* [ ] mount and use toolchain dir during build (toolchain caching)
* [x] mount and use toolchain dir during build (toolchain caching)
* [ ] optional use of cache during build

## CMakeLists
Expand Down
43 changes: 41 additions & 2 deletions build_n_test.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
podman run -v $(pwd):"/root/luabuild" -v "$(pwd)/opt_cross:/opt/cross" -e TOOLCHAINS='x86_64-linux-musl-cross' elibuild
./run_tests.sh $(pwd)/build/eli proc.lua
#!/bin/sh
podman run -v "$(pwd):/root/luabuild" -v "$(pwd)/toolchains:/opt/cross" -e TOOLCHAINS='x86_64-linux-musl-cross;i686-linux-musl-cross;aarch64-linux-musl-cross' elibuild

PLATFORM=$(uname -m)
ROOT=$(pwd)
rm -rf release
rm -rf .meta
mkdir release

test_build() {
cd lib/tests && \
"$ROOT/build/$1-linux-musl-cross/eli" all.lua && \
echo cp "$ROOT/build/$1-linux-musl-cross/eli" "release/eli-unix-$1" && \
cp "$ROOT/build/$1-linux-musl-cross/eli" "$ROOT/release/eli-unix-$1"
if [ -f "$ROOT/release/eli-unix-$1" ]; then
cd "$ROOT" && \
"$ROOT/release/eli-unix-$1" "$ROOT/tools/meta-generator.lua"
cd "$ROOT/.meta" && \
zip "$ROOT/release/meta.zip" -r *
fi
cd "$ROOT"
}

test_qemu_build() {
cd lib/tests && \
"$2" "$ROOT/build/$1-linux-musl-cross/eli" all.lua && \
cp "$ROOT/build/$1-linux-musl-cross/eli" "$ROOT/release/eli-unix-$1"
cd "$ROOT"
}

test_platform() {
if [ "$PLATFORM" = "$1" ]; then
test_build "$1"
elif which qemu-x86_64; then
test_qemu_build "$1" "qemu-${2:-$1}"
fi
}

test_platform "x86_64"
test_platform "i686" "i386"
test_platform "aarch64"
64 changes: 58 additions & 6 deletions config.hjson
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
version: 0.14.1
version: 0.15.0
global_modules: false//disables global modules loading (only looks up for modules in cwd)
minify: true
inject_CA: true
Expand Down Expand Up @@ -38,7 +38,59 @@
path: lib
ignore: [ "init.lua", ".*test.*" ]
}
]
],
inject_docs: [
{
source: lua-modules/hjson
files: [
{
lib: hjson
name: hjson.lua
isGlobal: false
destination: "hjson/hjson.lua"
}
]
},
{
source: modules/lua_is_tty
files: [
{
lib: is_tty
name: src/is_tty.c
isGlobal: false
destination: "is_tty/is_tty.lua"
}
]
},
{
source: modules/eli-env-extra
files: [
{
lib: eli.env
name: src/lenv.c
isGlobal: true,
destination: "env.extra.lua"
}
]
},
{
source: modules/eli-os-extra
files: [
{
lib: eli.os
name: src/los.c
isGlobal: true,
destination: "os.extra.lua"
},
{
lib: eli.os
name: src/lcwd.c
isGlobal: true,
destination: "os.extra-cwd.lua"
}
]
}
],
init: [
lib/init.lua
]
Expand All @@ -54,7 +106,7 @@
{
id: is_tty
repository: cryon-io/lua_is_tty
version: 0.1.1
version: 0.1.2
destination: modules/lua_is_tty
omitRoot: true
},
Expand Down Expand Up @@ -103,14 +155,14 @@
{
id: eli_os_extra
repository: cryon-io/eli-os-extra
version: 0.0.2
version: 0.0.3
destination: modules/eli-os-extra
omitRoot: true
},
{
id: eli_env_extra
repository: cryon-io/eli-env-extra
version: 0.1.0
version: 0.1.1
destination: modules/eli-env-extra
omitRoot: true
},
Expand Down Expand Up @@ -182,7 +234,7 @@
{
id: hjson
repository: cryi/hjson-lua
version: 0.1.3
version: 0.1.3-1
destination: lua-modules/hjson
omitRoot: true
},
Expand Down
6 changes: 4 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ LATEST=$(curl -sL https://api.github.com/repos/cryon-io/eli/releases/latest | gr

TMP_NAME="/tmp/$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"

wget "https://github.com/cryon-io/eli/releases/download/$LATEST/eli-unix-$(uname -m)" -O "$TMP_NAME" &&

PLATFORM=$(uname -m)
wget "https://github.com/cryon-io/eli/releases/download/$LATEST/eli-unix-$PLATFORM" -O "$TMP_NAME" &&
mv "$TMP_NAME" /usr/sbin/eli &&
chmod +x /usr/sbin/eli &&
echo "eli $LATEST for $(uname -m) successfuly installed."
echo "eli $LATEST for $PLATFORM successfuly installed."
89 changes: 81 additions & 8 deletions lib/eli/Logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,34 @@ local _exTable = require"eli.extensions.table"

local RESET_COLOR = string.char(27) .. "[0m"

---@alias LogLevel '"trace"'|'"debug"'|'"info"'|'"success"'|'"warn"'|'"error"'
---@alias LogLevelInt '-2'|'-1'|'0'|'0'|'1'|'2'

---@class LogMessage
---@field level LogLevel
---@field msg string
---@field module nil|string


---@class EliLoggerOptions
---@field format '"auto"'|'"standard"'|'"json"'
---@field colorful boolean
---@field level LogLevel
---@field includeFields boolean
---@field noTime boolean

---#DES 'Logger'
---@class Logger
---@field options EliLoggerOptions
---@field __type '"ELI_LOGGER"'
local Logger = {}
Logger.__index = Logger

---#DES 'Logger:new'
---
---@param self Logger
---@param options EliLoggerOptions
---@return Logger
function Logger:new(options)
local logger = {}
if options == nil then
Expand Down Expand Up @@ -46,10 +71,16 @@ function Logger:new(options)
return logger
end

function Logger:__tostring()
---#DES 'Logger.__tostring'
---
---@return string
function Logger.__tostring()
return "ELI_LOGGER"
end

---returns color based on log level
---@param level LogLevel
---@return string
local function get_log_color(level)
if level == "success" then
return string.char(27) .. "[32m"
Expand Down Expand Up @@ -77,13 +108,23 @@ local _levelValueMap = {
["trace"] = -2,
}

local function _level_value(lvl)
if type(lvl) ~= 'string' then return 0 end
local _lvl = _levelValueMap[lvl]
---returns integer equivalent of log level
---@param level LogLevel
---@return LogLevelInt
local function _level_value(level)
if type(level) ~= 'string' then return 0 end
local _lvl = _levelValueMap[level]
if (type(_lvl) == nil) then return 0 end
return _lvl
end

---prints log
---comment
---@param data LogMessage
---@param colorful boolean
---@param color string
---@param noTime boolean
---@param includeFields boolean
local function log_txt(data, colorful, color, noTime, includeFields)
local module = ""
if data.module ~= nil and data.module ~= "" then
Expand Down Expand Up @@ -121,6 +162,8 @@ local function log_txt(data, colorful, color, noTime, includeFields)
end
end

---prints log in json format
---@param data table
local function log_json(data)
data.timestamp = os.time(os.date("!*t"))
print(encode_to_json(data, {indent = false, skipkeys = true}))
Expand All @@ -133,12 +176,18 @@ local function wrap_msg(msg)
return msg
end

function Logger:log(msg, lvl)
---#DES 'Logger:log'
---
---Logs message with specified level
---@param self Logger
---@param msg LogMessage
---@param level LogLevel
function Logger:log(msg, level)
msg = wrap_msg(msg)
if lvl ~= nil then
msg.level = lvl
if level ~= nil then
msg.level = level
end
if _level_value(self.options.level) > _level_value(lvl) then
if _level_value(self.options.level) > _level_value(level) then
return
end

Expand All @@ -150,26 +199,50 @@ function Logger:log(msg, lvl)
end
end

---#DES 'Logger:success'
---
---@param self Logger
---@param msg LogMessage
function Logger:success(msg)
self:log(msg, "success")
end

---#DES 'Logger:debug'
---
---@param self Logger
---@param msg LogMessage
function Logger:debug(msg)
self:log(msg, "debug")
end

---#DES 'Logger:trace'
---
---@param self Logger
---@param msg LogMessage
function Logger:trace(msg)
self:log(msg, "trace")
end

---#DES 'Logger:info'
---
---@param self Logger
---@param msg LogMessage
function Logger:info(msg)
self:log(msg, "info")
end

---#DES 'Logger:warn'
---
---@param self Logger
---@param msg LogMessage
function Logger:warn(msg)
self:log(msg, "warn")
end

---#DES 'Logger:error'
---
---@param self Logger
---@param msg LogMessage
function Logger:error(msg)
self:log(msg, "error")
end
Expand Down
17 changes: 17 additions & 0 deletions lib/eli/cli.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
local _util = require("eli.util")

---@class CliArg
---#DES 'CliArg.type'
---@field type "option"|"parameter"
---#DES 'CliArg.value'
---@field value string|boolean
---#DES 'CliArg.id'
---@field id string
---#DES 'CliArg.arg'
---
---the cli argument this CliArg was created from
---@field arg string

---#DES cli.parse_args
---
---Parses array of arguments
---@param args string[]
---@return CliArg[]
local function _parse_args(args)
if not _util.is_array(args) then
args = arg
Expand Down
2 changes: 1 addition & 1 deletion lib/eli/elify.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--[[ // TODO consider implications of mergin proc with os and fs with io ]]
--[[ // TODO consider implications of merging proc with os and fs with io ]]
local _elified = false
local _overridenValues = {}

Expand Down
Loading

0 comments on commit d8c00bc

Please sign in to comment.