Skip to content

Commit

Permalink
fixed buildcommand not haveing project working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
LostbBlizzard committed Oct 19, 2024
1 parent 9bb7911 commit 31be402
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions ninja.lua
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,26 @@ local function getresflags(toolset, cfg, filecfg)
return defines .. includes .. options
end

local function fixupbuildcommands(cfg, commands)
if cfg.workspace.location == cfg.project.location then
return commands
end
local relative = path.getrelative(cfg.workspace.location, cfg.project.location)

local newcommands = { "cd " .. relative }

for _, Item in ipairs(commands) do
table.insert(newcommands, Item)
end
return newcommands
end
local function prebuild_rule(cfg)
if #cfg.prebuildcommands > 0 or cfg.prebuildmessage then
local commands = {}
if cfg.prebuildmessage then
commands = {os.translateCommandsAndPaths("{ECHO} " .. cfg.prebuildmessage, cfg.workspace.basedir, cfg.workspace.location)}
end
commands = table.join(commands, os.translateCommandsAndPaths(cfg.prebuildcommands, cfg.workspace.basedir, cfg.workspace.location))
commands = table.join(commands, os.translateCommandsAndPaths(fixupbuildcommands(cfg,cfg.prebuildcommands), cfg.workspace.basedir, cfg.workspace.location))
if (#commands > 1) then
commands = 'sh -c ' .. ninja.quote(table.implode(commands,"","",";"))
else
Expand All @@ -310,7 +323,7 @@ local function prelink_rule(cfg)
if cfg.prelinkmessage then
commands = {os.translateCommandsAndPaths("{ECHO} " .. cfg.prelinkmessage, cfg.workspace.basedir, cfg.workspace.location)}
end
commands = table.join(commands, os.translateCommandsAndPaths(cfg.prelinkcommands, cfg.workspace.basedir, cfg.workspace.location))
commands = table.join(commands, os.translateCommandsAndPaths(fixupbuildcommands(cfg,cfg.prelinkcommands), cfg.workspace.basedir, cfg.workspace.location))
if (#commands > 1) then
commands = 'sh -c ' .. ninja.quote(table.implode(commands,"","",";"))
else
Expand All @@ -329,7 +342,7 @@ local function postbuild_rule(cfg)
if cfg.postbuildmessage then
commands = {os.translateCommandsAndPaths("{ECHO} " .. cfg.postbuildmessage, cfg.workspace.basedir, cfg.workspace.location)}
end
commands = table.join(commands, os.translateCommandsAndPaths(cfg.postbuildcommands, cfg.workspace.basedir, cfg.workspace.location))
commands = table.join(commands, os.translateCommandsAndPaths(fixupbuildcommands(cfg,cfg.postbuildcommands), cfg.workspace.basedir, cfg.workspace.location))
if (#commands > 1) then
commands = 'sh -c ' .. ninja.quote(table.implode(commands,"","",";"))
else
Expand Down

0 comments on commit 31be402

Please sign in to comment.