Skip to content

Commit 3d214bf

Browse files
committed
[cleanup] simplify code
1 parent 701237a commit 3d214bf

1 file changed

Lines changed: 11 additions & 20 deletions

File tree

ninja.lua

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,7 @@ end
140140
-- so we need to propely escape them
141141
function ninja.shesc(value)
142142
if type(value) == 'table' then
143-
local result = {}
144-
local n = #value
145-
for i = 1, n do
146-
table.insert(result, ninja.shesc(value[i]))
147-
end
148-
return result
143+
return table.translate(value, ninja.shesc)
149144
end
150145

151146
if value:find(' ') or value:find('"') or value:find('(', 1, true) or value:find(')') or value:find('|') or value:find('&') then
@@ -546,17 +541,15 @@ local function compile_file_build(cfg, filecfg, toolset, pch_dependency, regular
546541
objfiles[#objfiles + 1] = objfilename
547542
local vars = {}
548543
if has_custom_settings then
549-
cflags = 'CFLAGS = $CFLAGS ' .. getcflags(toolset, cfg, filecfg)
550-
vars = { cflags }
544+
vars = { 'CFLAGS = $CFLAGS ' .. getcflags(toolset, cfg, filecfg) }
551545
end
552546
ninja.add_build(cfg, objfilename, {}, iif(use_clangtidy, 'clangtidy_cc', 'cc'), { filepath }, pch_dependency, regular_file_dependencies, vars)
553547
elseif shouldcompileascpp(filecfg) then
554548
local objfilename = obj_dir .. '/' .. obj_file
555549
objfiles[#objfiles + 1] = objfilename
556550
local vars = {}
557551
if has_custom_settings then
558-
cxxflags = 'CXXFLAGS = $CXXFLAGS ' .. getcxxflags(toolset, cfg, filecfg)
559-
vars = { cxxflags }
552+
vars = { 'CXXFLAGS = $CXXFLAGS ' .. getcxxflags(toolset, cfg, filecfg) }
560553
end
561554
ninja.add_build(cfg, objfilename, {}, iif(use_clangtidy, 'clangtidy_cxx', 'cxx'), { filepath }, pch_dependency, regular_file_dependencies, vars)
562555
elseif path.isresourcefile(filecfg.abspath) then
@@ -649,16 +642,14 @@ function ninja.generateProjectCfg(cfg)
649642

650643
---------------------------------------------------- figure out settings
651644
local pch = nil
652-
if is_c_or_cpp then
653-
if toolset ~= p.tools.msc then
654-
pch = p.tools.gcc.getpch(cfg)
655-
if pch then
656-
pch = {
657-
input = pch,
658-
placeholder = project.getrelative(cfg.workspace, path.join(cfg.objdir, path.getname(pch))),
659-
gch = project.getrelative(cfg.workspace, path.join(cfg.objdir, path.getname(pch) .. '.gch')),
660-
}
661-
end
645+
if is_c_or_cpp and toolset ~= p.tools.msc then
646+
pch = p.tools.gcc.getpch(cfg)
647+
if pch then
648+
pch = {
649+
input = pch,
650+
placeholder = project.getrelative(cfg.workspace, path.join(cfg.objdir, path.getname(pch))),
651+
gch = project.getrelative(cfg.workspace, path.join(cfg.objdir, path.getname(pch) .. '.gch')),
652+
}
662653
end
663654
end
664655

0 commit comments

Comments
 (0)