From 90764320bb5f30fd30c2bcd20f551aa3faeab001 Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 29 Jun 2016 13:58:38 +0200 Subject: [PATCH] Better cwd handling. --- first/ackbuilder.lua | 10 ++++++++++ first/build.lua | 10 ++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/first/ackbuilder.lua b/first/ackbuilder.lua index 9eef1f7a8..fbe0ee733 100644 --- a/first/ackbuilder.lua +++ b/first/ackbuilder.lua @@ -358,6 +358,7 @@ local function definerule(rulename, types, cb) end types.name = { type="string" } + types.cwd = { type="string", optional=true } for propname, typespec in pairs(types) do if not typeconverters[typespec.type] then @@ -366,6 +367,7 @@ local function definerule(rulename, types, cb) end end + local rulecwd = cwd local rule = function(e) local args = {} for propname, typespec in pairs(types) do @@ -388,8 +390,16 @@ local function definerule(rulename, types, cb) args.environment = environment args.fullname = cwd.."+"..args.name + args.rulecwd = rulecwd + if not args.cwd then + args.cwd = cwd + end + local oldcwd = cwd + cwd = rulecwd local result = cb(args) or {} + cwd = oldcwd + result.is = result.is or {} result.is[rulename] = true result.fullname = args.fullname diff --git a/first/build.lua b/first/build.lua index fc3429c7b..762d279d0 100644 --- a/first/build.lua +++ b/first/build.lua @@ -1,5 +1,5 @@ local function objdir(e) - return concatpath("$(OBJDIR)", cwd(), e.name) + return concatpath("$(OBJDIR)", e.cwd, e.name) end definerule("normalrule", @@ -69,6 +69,7 @@ definerule("cfile", return normalrule { name = e.name, + cwd = e.cwd, ins = {csrcs[1], unpack(hsrcs)}, outleaves = {outleaf}, label = e.label, @@ -102,6 +103,7 @@ definerule("bundle", return normalrule { name = e.name, + cwd = e.cwd, ins = e.srcs, outleaves = outleaves, label = e.label, @@ -137,10 +139,11 @@ definerule("clibrary", local n = basename(csrc):gsub("%.%w*$", "") ins[#ins+1] = cfile { name = e.name.."/"..n, + cwd = e.cwd, srcs = {csrc, unpack(hsrcs)}, deps = e.deps, cflags = { - "-I"..cwd(), + "-I"..e.cwd, unpack(e.cflags) }, } @@ -158,6 +161,7 @@ definerule("clibrary", return normalrule { name = e.name, + cwd = e.cwd, ins = ins, outleaves = { e.name..".a", unpack(basename(hdrs)) }, label = e.label, @@ -188,6 +192,7 @@ definerule("cprogram", { clibrary { name = e.name .. "/main", + cwd = e.cwd, srcs = e.srcs, deps = e.deps, cflags = e.cflags, @@ -201,6 +206,7 @@ definerule("cprogram", return normalrule { name = e.name, + cwd = e.cwd, ins = libs, outleaves = { e.name }, commands = e.commands,