Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version compat #333

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions commands/update.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

return function ()
local log = require('log').log
local core = require('core')()
Expand All @@ -20,6 +21,13 @@ return function ()
return body
end

local isWindows
if _G.jit then
isWindows = _G.jit.os == "Windows"
else
isWindows = not not package.path:match("\\")
end

-- Returns current version, latest version and latest compat version.
local function checkUpdate()
-- Read the current lit version
Expand Down Expand Up @@ -63,7 +71,7 @@ return function ()
local stdout = exec(target, "-v")
if not stdout:match("^lit version:") then
target = pathJoin(target, "..", "lit")
if jit.os == "Windows" then
if isWindows then
target = target .. ".exe"
end
end
Expand Down Expand Up @@ -107,7 +115,7 @@ return function ()

do
local luvitPath = pathJoin(uv.exepath(), "..", "luvit")
if jit.os == "Windows" then
if isWindows then
luvitPath = luvitPath .. ".exe"
end
if uv.fs_stat(luvitPath) then
Expand All @@ -123,14 +131,14 @@ return function ()

do
local target = pathJoin(uv.exepath(), "..", "luvi")
if jit.os == "Windows" then
if isWindows then
target = target .. ".exe"
end
local new, old
local toupdate = require('luvi').version
if uv.fs_stat(target) then
local stdout = exec(target, "-v")
if jit.os == "Windows" then
if isWindows then
stdout = stdout:gsub("luvi.exe ","luvi ")
end
local version = stdout:match("luvi (v[^ \r\n]+)")
Expand Down
4 changes: 2 additions & 2 deletions deps/coro-channel.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
--[[lit-meta
name = "luvit/coro-channel"
version = "3.0.4"
version = "3.0.5"
homepage = "https://github.com/luvit/lit/blob/master/deps/coro-channel.lua"
description = "An adapter for wrapping uv streams as coro-streams."
tags = {"coro", "adapter"}
license = "MIT"
author = { name = "Tim Caswell" }
]]

-- local p = require('pretty-print').prettyPrint
local unpack = unpack or table.unpack

local function assertResume(thread, ...)
local success, err = coroutine.resume(thread, ...)
Expand Down
3 changes: 2 additions & 1 deletion deps/coro-http.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--[[lit-meta
name = "luvit/coro-http"
version = "3.2.3"
version = "3.2.4"
dependencies = {
"luvit/[email protected]",
"luvit/[email protected]"
Expand All @@ -14,6 +14,7 @@

local httpCodec = require('http-codec')
local net = require('coro-net')
local unpack = unpack or table.unpack

local function createServer(host, port, onConnect)
return net.createServer({
Expand Down
3 changes: 2 additions & 1 deletion deps/coro-split.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--[[lit-meta
name = "luvit/coro-split"
version = "2.0.2"
version = "2.0.3"
homepage = "https://github.com/luvit/lit/blob/master/deps/coro-split.lua"
description = "An coro style helper for running tasks concurrently."
tags = {"coro", "split"}
Expand All @@ -11,6 +11,7 @@
-- Split takes several functions as input and runs them in concurrent coroutines.
-- The split function will itself block and wait for all three to finish.
-- The results of the functions will be returned from split.
local unpack = unpack or table.unpack

local function assertResume(thread, ...)
local success, err = coroutine.resume(thread, ...)
Expand Down
3 changes: 2 additions & 1 deletion deps/http-codec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.

--[[lit-meta
name = "luvit/http-codec"
version = "3.0.7"
version = "3.0.8"
homepage = "https://github.com/luvit/luvit/blob/master/deps/http-codec.lua"
description = "A simple pair of functions for converting between hex and raw strings."
tags = {"codec", "http"}
Expand All @@ -33,6 +33,7 @@ local find = string.find
local format = string.format
local concat = table.concat
local match = string.match
local unpack = unpack or table.unpack

local STATUS_CODES = {
[100] = 'Continue',
Expand Down
3 changes: 2 additions & 1 deletion deps/readline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
--]]
--[[lit-meta
name = "luvit/readline"
version = "2.2.0"
version = "2.2.1"
dependencies = {
"luvit/[email protected]",
}
Expand All @@ -29,6 +29,7 @@ limitations under the License.
]]

-- Heavily inspired by ljlinenoise : <http://fperrad.github.io/ljlinenoise/>
local unpack = unpack or table.unpack

local ustring = require "ustring"
local emptyline = ustring.new()
Expand Down
1 change: 1 addition & 0 deletions deps/weblit-auto-headers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Response automatic values:
]]

local date = require('os').date
local unpack = unpack or table.unpack

local success, parent = pcall(require, '../package')
local serverName = success and (parent.name .. " v" .. parent.version)
Expand Down
1 change: 1 addition & 0 deletions deps/weblit-server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
local uv = require('uv')
local createServer = require('coro-net').createServer
local httpCodec = require('http-codec')
local unpack = unpack or table.unpack

-- Provide a nice case insensitive interface to headers.
local headerMeta = {}
Expand Down
3 changes: 2 additions & 1 deletion deps/websocket-codec.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--[[lit-meta
name = "luvit/websocket-codec"
description = "A codec implementing websocket framing and helpers for handshakeing"
version = "3.0.2"
version = "3.0.3"
dependencies = {
"luvit/[email protected]",
"luvit/[email protected]",
Expand Down Expand Up @@ -30,6 +30,7 @@ local gsub = string.gsub
local concat = table.concat
local floor = math.floor
local random = math.random
local unpack = unpack or table.unpack

local function rand4()
-- Generate 32 bits of pseudo random data
Expand Down
17 changes: 7 additions & 10 deletions libs/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ local ffi = require('ffi')
local fs = require('coro-fs')
local metrics = require('metrics')
local uv = require('uv')
local unpack = unpack or table.unpack

local function hex_to_char(x)
return string.char(tonumber(x, 16))
Expand Down Expand Up @@ -173,19 +174,15 @@ local function collectStats()
return entries
end

local howToDetermineFDs = {
Linux = function() return countFDs("/proc/self/fd") end,
OSX = function() return countFDs("/dev/fd") end,
Other = function() return -1 end
}

local os = ffi.os
if howToDetermineFDs[os] == nil then
os = "Other"
local numFDs = -1
if fs.exists("/proc/self/fd") then
numFDs = countFDs("/proc/self/fd")
elseif fs.exists("/dev/fd") then
numFDs = countFDs("/dev/fd")
end

metrics.set("lua.mem.used", memoryUsed)
metrics.set("lua.fds.used", howToDetermineFDs[os]())
metrics.set("lua.fds.used", numFDs)
return metrics.all()
end

Expand Down
2 changes: 1 addition & 1 deletion libs/autoconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ local fs = require('coro-fs')
local env = require('env')

local prefix
if require('ffi').os == "Windows" then
if package.config:sub(1,1) == '\\' and env.get('APPDATA') then
prefix = env.get("APPDATA") .. "\\"
else
prefix = env.get("HOME") .. "/."
Expand Down
25 changes: 19 additions & 6 deletions libs/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ local exportZip = require('export-zip')
local digest = require('openssl').digest.digest
local request = require('coro-http').request
local makeAutoConfig = require('autoconfig')
local unpack = unpack or table.unpack

local quotepattern = '(['..("%^$().[]*+-?"):gsub("(.)", "%%%1")..'])'
local function escape(str)
Expand All @@ -69,6 +70,13 @@ local function run(...)
end
end

local isWindows
if _G.jit then
isWindows = _G.jit.os == "Windows"
else
isWindows = not not package.path:match("\\")
end

-- Takes a time struct with a date and time in UTC and converts it into
-- seconds since Unix epoch (0:00 1 Jan 1970 UTC).
-- Trickier than you'd think because os.time assumes the struct is in local time.
Expand Down Expand Up @@ -181,11 +189,16 @@ local function makeCore(config)
local version = semver.normalize(meta and meta.version or luvi.version)
local template = meta and meta.url or defaultTemplate
local arch
if jit.os == "Windows" then
if jit.arch == "x64" then
if isWindows then
local info = uv.os_uname()
if info.machine == 'amd64' then
arch = "Windows-amd64.exe"
else
arch = "Windows-ia32.exe"
if semver.gte(version, '2.15.0') then
arch = "Windows-x86.exe" -- the new name scheme
else
arch = "Windows-ia32.exe"
end
end
else
arch = run("uname", "-s") .. "_" .. run("uname", "-m")
Expand All @@ -202,7 +215,7 @@ local function makeCore(config)
if template == defaultTemplate and flavor == "regular" and version == semver.normalize(luvi.version) then
local exe = uv.exepath()
local stdout = exec(exe, "-v")
if jit.os == "Windows" then
if isWindows then
stdout = stdout:gsub('.exe','')
end
local iversion = stdout:match("luvi version: v(%d+%.%d+%.%d+)")
Expand Down Expand Up @@ -367,7 +380,7 @@ local function makeCore(config)
end

local function makeZip(rootHash, target, luvi_source)
if jit.os == "Windows" and (not target:match('%.exe$')) then
if isWindows and (not target:match('%.exe$')) then
target = target..'.exe'
end

Expand Down Expand Up @@ -401,7 +414,7 @@ local function makeCore(config)

local function defaultTarget(meta)
local target = meta.target or meta.name:match("[^/]+$")
if jit.os == "Windows" then
if isWindows then
target = target .. ".exe"
end
return target
Expand Down
1 change: 1 addition & 0 deletions libs/db-fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local git = require('git')
local listToMap = git.listToMap
local modeToType = git.modes.toType
local modes = git.modes
local unpack = unpack or table.unpack

return function (db, root)
local cache = {}
Expand Down
1 change: 1 addition & 0 deletions libs/export-zip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
local miniz = require('miniz')
local modes = require('git').modes
local log = require('log').log
local loadstring = loadstring or load

-- Create a zip from a hash optionally compiling lua files to bytecode.
return function (db, rootHash, compileLua)
Expand Down
1 change: 1 addition & 0 deletions libs/handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ local digest = require('openssl').digest.digest
local githubQuery = require('github-request')
local jsonParse = require('json').parse
local verifySignature = require('verify-signature')
local unpack = unpack or table.unpack

local function split(line)
local args = {}
Expand Down
1 change: 1 addition & 0 deletions libs/import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local pathJoin = require('luvi').path.join
local isAllowed = require('rules').isAllowed
local compileFilter = require('rules').compileFilter
local modes = require('git').modes
local loadstring = loadstring or load

-- Import a fs path into the database
return function (db, fs, rootpath, rules, nativeOnly)
Expand Down
19 changes: 13 additions & 6 deletions libs/pkg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ local semver = require('semver')
local pathJoin = require('luvi').path.join
local listToMap = require('git').listToMap
local jsonParse = require('json').parse
local load = load
if not load then
function load(code, name, mode, env)
local fn, err = loadstring(code, name)
if not fn then return fn, err end
if env then setfenv(fn, env) end
return fn
end
end

local function evalModule(data, name)
-- Match multiline lua comments that start with `lit-meta`
Expand All @@ -40,21 +49,19 @@ local function evalModule(data, name)
local term = "]" .. data:sub(a + 3, b - 9) .."]"
local c = data:find(term, b + 1, true)
if c then
local fn, err = loadstring(data:sub(b + 1, c - 1), name)
assert(not err, err)
local env = {}
setfenv(fn, env)
local fn, err = load(data:sub(b + 1, c - 1), name, "t", env)
assert(not err, err)
assert(pcall(fn))
return env
end
end
local fn, err = loadstring(data, name)
if not fn then return nil, err end
local exports = {}
local module = { exports = exports }
setfenv(fn, {
local fn, err = load(data, name, 't', {
exports = exports,
})
if not fn then return nil, err end
local success, ret = pcall(fn)

local meta = success and type(ret) == "table" and ret or module.exports
Expand Down
12 changes: 10 additions & 2 deletions libs/rules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,29 @@ limitations under the License.

--]]

local ffi = require('ffi')
local log = require('log').log
local pathJoin = require('luvi').path.join
local modes = require('git').modes
local colorize = require('pretty-print').colorize
local unpack = unpack or table.unpack
local loadstring = loadstring or load

local quotepattern = '['..("%^$().[]*+-?"):gsub("(.)", "%%%1")..']'

local native_os, native_arch
do
local info = require('luv').os_uname()
native_os = info.sysname
native_arch = info.machine
end

-- When importing into the db to publish, we want to include binaries for all
-- platforms, but when installing to disk or zip app bundle, we want native only.
local patterns = {
-- Rough translation of (Linux|Windows|OSX|BSD) and (x86|x64|arm)
-- This is more liberal than it needs to be, but works mostly in practice.
all = {"[LWOB][iS][nXD][uxdows]*", "[xa][86r][64m]"},
native = {ffi.os, ffi.arch},
native = {native_os, native_arch},
}

local function compileFilter(rootPath, rules, nativeOnly)
Expand Down
Loading