diff --git a/.travis.yml b/.travis.yml index d199d5076..bcb505b6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ before_install: - - sudo apt-get install ed lua5.2 lua-posix ninja + - sudo apt-get install ed lua5.1 liblua5.1-posix1 ninja language: c script: - make PREFIX=/tmp/acki -j4 diff --git a/Makefile b/Makefile index 0f6938b1e..b3955ca40 100644 --- a/Makefile +++ b/Makefile @@ -91,7 +91,7 @@ endif $(BUILDDIR)/rules.ninja: first/ackbuilder.lua $(BUILD_FILES) @mkdir -p $(BUILDDIR) - @lua5.2 first/ackbuilder.lua first/build.lua build.lua --ninja > $(BUILDDIR)/rules.ninja + @lua5.1 first/ackbuilder.lua first/build.lua build.lua --ninja > $(BUILDDIR)/rules.ninja $(BUILDDIR)/rules.mk: first/ackbuilder.lua $(BUILD_FILES) @mkdir -p $(BUILDDIR) diff --git a/first/ackbuilder.lua b/first/ackbuilder.lua index ea65161f1..2333461ee 100644 --- a/first/ackbuilder.lua +++ b/first/ackbuilder.lua @@ -346,10 +346,11 @@ local function templateexpand(list, vars) o[#o+1] = s:gsub("%%%b{}", function(expr) expr = expr:sub(3, -2) - local chunk, e = load("return ("..expr..")", expr, "text", vars) + local chunk, e = loadstring("return ("..expr..")", expr) if e then error(string.format("error evaluating expression: %s", e)) end + setfenv(chunk, vars) local value = chunk() if (value == nil) then error(string.format("template expression '%s' expands to nil (probably an undefined variable)", expr)) @@ -381,7 +382,10 @@ local function loadbuildfile(filename) local thisglobals = {} thisglobals._G = thisglobals setmetatable(thisglobals, {__index = globals}) - chunk, e = load(data, "@"..filename, "text", thisglobals) + chunk, e = loadstring(data, "@"..filename) + if not e then + setfenv(chunk, thisglobals) + end end end if e then @@ -396,6 +400,22 @@ local function loadbuildfile(filename) loadingstack[#loadingstack] = nil end +local function loadbuildfilefor(filepart, targetpart) + local normalname = concatpath(filepart, "/build.lua") + if posix.access(normalname, "r") then + loadbuildfile(normalname) + return + end + + local extendedname = concatpath(filepart, "/build-"..targetpart..".lua") + if posix.access(extendedname, "r") then + loadbuildfile(extendedname) + return + end + + error(string.format("could not access either '%s' or '%s'", normalname, extendedname)) +end + loadtarget = function(targetname) if targets[targetname] then return targets[targetname] @@ -428,13 +448,7 @@ loadtarget = function(targetname) if (filepart == "") then filepart = cwd end - local filename = concatpath(filepart, "/build.lua") - if posix.access(filename, "r") then - loadbuildfile(filename) - else - filename = concatpath(filepart, "/build-"..targetpart..".lua") - loadbuildfile(filename) - end + loadbuildfilefor(filepart, targetpart) target = targets[targetname] if not target then