From 0d3dfaf9d256800a53329fbeb6be7156b71f3421 Mon Sep 17 00:00:00 2001 From: LostbBlizzard <106630000+LostbBlizzard@users.noreply.github.com> Date: Tue, 8 Oct 2024 20:44:49 -0400 Subject: [PATCH 01/10] added prefering defualtplatform when set --- ninja.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ninja.lua b/ninja.lua index a0f70c4..dd38a09 100644 --- a/ninja.lua +++ b/ninja.lua @@ -160,14 +160,23 @@ function ninja.generateWorkspace(wks) table.insert(cfgs[cfg.buildcfg], key) -- set first configuration name - if (cfg_first == nil) and (cfg.kind == p.CONSOLEAPP or cfg.kind == p.WINDOWEDAPP) then - cfg_first = key + if wks.defaultplatform == "" then + if (cfg_first == nil) and (cfg.kind == p.CONSOLEAPP or cfg.kind == p.WINDOWEDAPP) then + cfg_first = key + end end if (cfg_first_lib == nil) and (cfg.kind == p.STATICLIB or cfg.kind == p.SHAREDLIB) then cfg_first_lib = key end - if prj.name == wks.startproject then + + if wks.defaultplatform == "" then cfg_first = key + elseif prj.name == wks.startproject then + if cfg.platform == wks.defaultplatform then + if cfg_first == nil then + cfg_first = key + end + end end -- include other ninja file From 290686c05cd789a47aaced1e933a42c0d167a0da Mon Sep 17 00:00:00 2001 From: LostbBlizzard <106630000+LostbBlizzard@users.noreply.github.com> Date: Tue, 8 Oct 2024 20:47:15 -0400 Subject: [PATCH 02/10] added missing postfix for file dependencies --- ninja.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ninja.lua b/ninja.lua index dd38a09..0192883 100644 --- a/ninja.lua +++ b/ninja.lua @@ -250,7 +250,7 @@ local function getFileDependencies(cfg) dependencies = {"prebuild_" .. get_key(cfg)} end for i = 1, #cfg.dependson do - table.insert(dependencies, cfg.dependson[i] .. "_" .. cfg.buildcfg) + table.insert(dependencies, cfg.dependson[i] .. "_" .. cfg.buildcfg .. "_" .. cfg.platform) end return dependencies end From 9294b7726270b42e8b0f8f5e474263159510b5b7 Mon Sep 17 00:00:00 2001 From: LostbBlizzard <106630000+LostbBlizzard@users.noreply.github.com> Date: Tue, 8 Oct 2024 21:28:39 -0400 Subject: [PATCH 03/10] fixed breaking old code --- ninja.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ninja.lua b/ninja.lua index 0192883..b61966e 100644 --- a/ninja.lua +++ b/ninja.lua @@ -250,7 +250,11 @@ local function getFileDependencies(cfg) dependencies = {"prebuild_" .. get_key(cfg)} end for i = 1, #cfg.dependson do - table.insert(dependencies, cfg.dependson[i] .. "_" .. cfg.buildcfg .. "_" .. cfg.platform) + local dependposfix = cfg.buildcfg + if cfg.platform then + dependposfix = dependposfix .. "_" .. cfg.platform + end + table.insert(dependencies, cfg.dependson[i] .. "_" .. dependposfix) end return dependencies end From b3275c9c34882327efa9a3078149a7dd3b82584b Mon Sep 17 00:00:00 2001 From: LostbBlizzard <106630000+LostbBlizzard@users.noreply.github.com> Date: Tue, 8 Oct 2024 22:38:55 -0400 Subject: [PATCH 04/10] fixed include not be relative to main ninja --- ninja.lua | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/ninja.lua b/ninja.lua index b61966e..c000296 100644 --- a/ninja.lua +++ b/ninja.lua @@ -259,12 +259,29 @@ local function getFileDependencies(cfg) return dependencies end + +local function fixincludedir(cfg,includedirs) + local fixincludedirs = {} + for _,value in ipairs(includedirs) do + if value == cfg.project.location then -- the '.' this would make would not work as the working directory would not change. + value = path.getrelative(cfg.workspace.location,cfg.project.location) + end + + local newvalue = path.getrelative(cfg.workspace.location, value) + + table.insert(fixincludedirs,newvalue) + end + return fixincludedirs +end local function getcflags(toolset, cfg, filecfg) local buildopt = ninja.list(filecfg.buildoptions) local cppflags = ninja.list(toolset.getcppflags(filecfg)) local cflags = ninja.list(toolset.getcflags(filecfg)) local defines = ninja.list(table.join(toolset.getdefines(filecfg.defines), toolset.getundefines(filecfg.undefines))) - local includes = ninja.list(toolset.getincludedirs(cfg, filecfg.includedirs, filecfg.externalincludedirs, filecfg.frameworkdirs, filecfg.includedirsafter)) + + local fixincludedirs = fixincludedir(cfg,filecfg.includedirs) + + local includes = ninja.list(toolset.getincludedirs(cfg, fixincludedirs, filecfg.externalincludedirs, filecfg.frameworkdirs, filecfg.includedirsafter)) local forceincludes = ninja.list(toolset.getforceincludes(cfg)) return buildopt .. cppflags .. cflags .. defines .. includes .. forceincludes @@ -275,7 +292,10 @@ local function getcxxflags(toolset, cfg, filecfg) local cppflags = ninja.list(toolset.getcppflags(filecfg)) local cxxflags = ninja.list(toolset.getcxxflags(filecfg)) local defines = ninja.list(table.join(toolset.getdefines(filecfg.defines), toolset.getundefines(filecfg.undefines))) - local includes = ninja.list(toolset.getincludedirs(cfg, filecfg.includedirs, filecfg.externalincludedirs, filecfg.frameworkdirs, filecfg.includedirsafter)) + + local fixincludedirs = fixincludedir(cfg,filecfg.includedirs) + + local includes = ninja.list(toolset.getincludedirs(cfg, fixincludedirs, filecfg.externalincludedirs, filecfg.frameworkdirs, filecfg.includedirsafter)) local forceincludes = ninja.list(toolset.getforceincludes(cfg)) return buildopt .. cppflags .. cxxflags .. defines .. includes .. forceincludes end From fe2a1c18e6d6f77cd278928574d0e3de6d45291b Mon Sep 17 00:00:00 2001 From: LostbBlizzard <106630000+LostbBlizzard@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:20:14 -0400 Subject: [PATCH 05/10] fixed unnned if check --- ninja.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ninja.lua b/ninja.lua index c000296..31798f7 100644 --- a/ninja.lua +++ b/ninja.lua @@ -263,10 +263,6 @@ end local function fixincludedir(cfg,includedirs) local fixincludedirs = {} for _,value in ipairs(includedirs) do - if value == cfg.project.location then -- the '.' this would make would not work as the working directory would not change. - value = path.getrelative(cfg.workspace.location,cfg.project.location) - end - local newvalue = path.getrelative(cfg.workspace.location, value) table.insert(fixincludedirs,newvalue) From 3348f86ec17738399fe390fcb4caf479c85819e2 Mon Sep 17 00:00:00 2001 From: LostbBlizzard <106630000+LostbBlizzard@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:37:53 -0400 Subject: [PATCH 06/10] fixed project command paths not being relative to ninja file --- ninja.lua | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/ninja.lua b/ninja.lua index 31798f7..84bcaf2 100644 --- a/ninja.lua +++ b/ninja.lua @@ -314,13 +314,50 @@ local function getresflags(toolset, cfg, filecfg) return defines .. includes .. options end +local function fixupbuildcommands(cfg,commands) + + local function splitstring(inputstr, sep) + if sep == nil then + sep = "%s" + end + local t = {} + for str in string.gmatch(inputstr, "([^"..sep.."]+)") do + table.insert(t, str) + end + return t + end + + local newcommands = {} + for _,Item in ipairs(cfg.prebuildcommands) do + + local splits = splitstring(Item," ") + local newvalue = "" + + + for _,item in ipairs(splits) do + local ispath = string.find(item,"/") or string.find(item,"\\") + + if ispath then + local relative = path.getrelative(cfg.workspace.location,cfg.project.location) + newvalue = newvalue .. relative .. "/" .. item + else + newvalue = newvalue .. item + end + end + + table.insert(newcommands,newinput) + 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 @@ -333,13 +370,14 @@ local function prebuild_rule(cfg) end end + local function prelink_rule(cfg) if #cfg.prelinkcommands > 0 or cfg.prelinkmessage then local commands = {} 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 @@ -358,7 +396,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 From 2958dc24c0c70bf119e6a72780ca9cfa16b0a7ba Mon Sep 17 00:00:00 2001 From: LostbBlizzard <106630000+LostbBlizzard@users.noreply.github.com> Date: Wed, 9 Oct 2024 09:35:00 -0400 Subject: [PATCH 07/10] fixed typos --- ninja.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ninja.lua b/ninja.lua index 84bcaf2..8ede8f0 100644 --- a/ninja.lua +++ b/ninja.lua @@ -328,7 +328,7 @@ local function fixupbuildcommands(cfg,commands) end local newcommands = {} - for _,Item in ipairs(cfg.prebuildcommands) do + for _,Item in ipairs(commands) do local splits = splitstring(Item," ") local newvalue = "" @@ -345,7 +345,7 @@ local function fixupbuildcommands(cfg,commands) end end - table.insert(newcommands,newinput) + table.insert(newcommands,newvalue) end From c4b332a9441888b34ade6b1a56ce180457367d54 Mon Sep 17 00:00:00 2001 From: LostbBlizzard <106630000+LostbBlizzard@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:03:41 -0400 Subject: [PATCH 08/10] fix missing space for commands --- ninja.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ninja.lua b/ninja.lua index 8ede8f0..062c107 100644 --- a/ninja.lua +++ b/ninja.lua @@ -334,7 +334,7 @@ local function fixupbuildcommands(cfg,commands) local newvalue = "" - for _,item in ipairs(splits) do + for ind,item in ipairs(splits) do local ispath = string.find(item,"/") or string.find(item,"\\") if ispath then @@ -343,6 +343,11 @@ local function fixupbuildcommands(cfg,commands) else newvalue = newvalue .. item end + + if ind ~= #splits then + newvalue = newvalue .. " " + end + end table.insert(newcommands,newvalue) From edbca641e74feb0bcbd53bedd378bf33e91d2049 Mon Sep 17 00:00:00 2001 From: LostbBlizzard <106630000+LostbBlizzard@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:04:59 -0400 Subject: [PATCH 09/10] fixed missing dependencies for prebuild_ commands --- ninja.lua | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ninja.lua b/ninja.lua index 062c107..5ce4c77 100644 --- a/ninja.lua +++ b/ninja.lua @@ -244,11 +244,7 @@ local function shouldcompileascpp(filecfg) return path.iscppfile(filecfg.abspath) end -local function getFileDependencies(cfg) - local dependencies = {} - if #cfg.prebuildcommands > 0 or cfg.prebuildmessage then - dependencies = {"prebuild_" .. get_key(cfg)} - end +local function addcfgDependencies(dependencies,cfg) for i = 1, #cfg.dependson do local dependposfix = cfg.buildcfg if cfg.platform then @@ -256,6 +252,19 @@ local function getFileDependencies(cfg) end table.insert(dependencies, cfg.dependson[i] .. "_" .. dependposfix) end +end + +local function getcfgDependencies(cfg) + local dependencies = {} + addcfgDependencies(dependencies,cfg) + return dependencies +end +local function getFileDependencies(cfg) + local dependencies = {} + if #cfg.prebuildcommands > 0 or cfg.prebuildmessage then + dependencies = {"prebuild_" .. get_key(cfg)} + end + addcfgDependencies(dependencies,cfg) return dependencies end @@ -758,7 +767,7 @@ function ninja.generateProjectCfg(cfg) ---------------------------------------------------- build final target if #cfg.prebuildcommands > 0 or cfg.prebuildmessage then p.outln("# prebuild") - add_build(cfg, "prebuild_" .. get_key(cfg), {}, "run_prebuild", {}, {}, {}, {}) + add_build(cfg, "prebuild_" .. get_key(cfg), {}, "run_prebuild", {}, {}, getcfgDependencies(cfg), {}) end local prelink_dependency = {} if #cfg.prelinkcommands > 0 or cfg.prelinkmessage then From 61316ad8af221f2905e9fbd9cd08657d5e611847 Mon Sep 17 00:00:00 2001 From: LostbBlizzard <106630000+LostbBlizzard@users.noreply.github.com> Date: Sat, 12 Oct 2024 15:46:26 -0400 Subject: [PATCH 10/10] clean up fixupbuildcommands --- ninja.lua | 45 ++++++++------------------------------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/ninja.lua b/ninja.lua index 5ce4c77..823586e 100644 --- a/ninja.lua +++ b/ninja.lua @@ -323,46 +323,17 @@ local function getresflags(toolset, cfg, filecfg) return defines .. includes .. options end -local function fixupbuildcommands(cfg,commands) - - local function splitstring(inputstr, sep) - if sep == nil then - sep = "%s" - end - local t = {} - for str in string.gmatch(inputstr, "([^"..sep.."]+)") do - table.insert(t, str) - end - return t +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 } - local newcommands = {} - for _,Item in ipairs(commands) do - - local splits = splitstring(Item," ") - local newvalue = "" - - - for ind,item in ipairs(splits) do - local ispath = string.find(item,"/") or string.find(item,"\\") - - if ispath then - local relative = path.getrelative(cfg.workspace.location,cfg.project.location) - newvalue = newvalue .. relative .. "/" .. item - else - newvalue = newvalue .. item - end - - if ind ~= #splits then - newvalue = newvalue .. " " - end - - end - - table.insert(newcommands,newvalue) + for _, Item in ipairs(commands) do + table.insert(newcommands, Item) end - - return newcommands end local function prebuild_rule(cfg)